
.intel_syntax noprefix

.global ModelDirective
.global SetCPU
.global CpuDirective
.global sym_Interface
.global sym_Cpu
.global ModelToken

.extern pe_create_PE_header
.extern RunLineQueue
.extern AddPredefinedText
.extern sym_ReservedStack
.extern LstWriteSrcLine
.extern ModelAssumeInit
.extern FindToken
.extern SetModelDefaultSegNames
.extern ModelSimSegmInit
.extern SimGetSegName
.extern DefineFlatGroup
.extern SetOfssize
.extern GetLangType
.extern CreateVariable
.extern asmerr
.extern szDgroup
.extern Options
.extern Parse_Pass


.SECTION .text
	.ALIGN	16

$_001:	push	rbp
	mov	rbp, rsp
	sub	rsp, 32
	call	CreateVariable@PLT
	test	rax, rax
	jz	$_002
	or	byte ptr [rax+0x10], 0x08
$_002:	leave
	ret

$_003:
	cmp	qword ptr [r14+0x38], 0
	jnz	$_004
	mov	byte ptr [r14+0x5], cl
$_004:	call	SetOfssize@PLT
	ret

$_005:
	push	rsi
	push	rdi
	push	rbx
	sub	rsp, 32
	cmp	byte ptr [r14+0x15], 7
	jne	$_019
	mov	byte ptr [r14+0x17], 1
	movzx	eax, byte ptr [r14+0x14]
	and	eax, 0x9F
	test	eax, 0x80
	jz	$_006
	mov	eax, 128
	jmp	$_007

$_006:	cmp	eax, 6
	jc	$_007
	mov	eax, 6
$_007:	mov	esi, eax
	mov	eax, 1
	test	esi, 0x80
	jz	$_008
	mov	eax, 2
$_008:	mov	ecx, eax
	call	$_003
	mov	al, byte ptr [r14+0x9]
	mov	cl, byte ptr [r14+0x7]
	test	esi, 0x80
	jz	$_017
	test	al, al
	jnz	$_009
	mov	al, 2
$_009:	cmp	dword ptr [Options+0x90+rip], 0
	jnz	$_010
	mov	dword ptr [Options+0x90+rip], 3
$_010:	cmp	dword ptr [Options+0x8C+rip], 1
	jnz	$_012
	cmp	al, 2
	jnz	$_011
	mov	dword ptr [Options+0x8C+rip], 3
	jmp	$_012

$_011:	mov	dword ptr [Options+0x8C+rip], 2
$_012:	cmp	al, 7
	jz	$_013
	cmp	al, 2
	jz	$_013
	cmp	al, 8
	jnz	$_016
$_013:	cmp	al, 8
	jnz	$_014
	mov	cl, 5
	jmp	$_016

$_014:	cmp	dword ptr [Options+0x8C+rip], 3
	jz	$_015
	mov	cl, 2
	jmp	$_016

$_015:	mov	cl, 3
$_016:	jmp	$_018

$_017:	cmp	al, 8
	jnz	$_018
	mov	cl, 4
$_018:	mov	byte ptr [r14+0x7], cl
	call	DefineFlatGroup@PLT
	jmp	$_020

$_019:	mov	byte ptr [r14+0x17], 0
$_020:	movzx	ecx, byte ptr [r14+0x15]
	call	ModelSimSegmInit@PLT
	call	ModelAssumeInit@PLT
	test	byte ptr [r14], 0x08
	jz	$_021
	call	LstWriteSrcLine@PLT
$_021:	call	RunLineQueue@PLT
	cmp	dword ptr [Parse_Pass+rip], 0
	jne	$_031
	mov	eax, 1
	mov	cl, byte ptr [r14+0x15]
	shl	eax, cl
	and	eax, 0x70
	setne	al
	mov	edx, eax
	lea	rcx, [DS000B+rip]
	call	$_001
	mov	qword ptr [sym_CodeSize+rip], rax
	xor	ecx, ecx
	call	SimGetSegName@PLT
	mov	rdx, rax
	lea	rcx, [DS000C+rip]
	call	AddPredefinedText@PLT
	mov	cl, byte ptr [r14+0x15]
	xor	eax, eax
	jmp	$_024

$_022:	mov	eax, 1
	jmp	$_025

$_023:	mov	eax, 2
	jmp	$_025

$_024:	cmp	cl, 3
	jz	$_022
	cmp	cl, 5
	jz	$_022
	cmp	cl, 6
	jz	$_023
$_025:	mov	edx, eax
	lea	rcx, [DS000D+rip]
	call	$_001
	mov	qword ptr [sym_DataSize+rip], rax
	lea	rsi, [szDgroup+rip]
	cmp	byte ptr [r14+0x15], 7
	jnz	$_026
	lea	rsi, [DS0006+rip]
$_026:	mov	rdx, rsi
	lea	rcx, [DS000E+rip]
	call	AddPredefinedText@PLT
	cmp	byte ptr [r14+0x1A], 1
	jnz	$_027
	lea	rsi, [DS0008+0x3+rip]
$_027:	mov	rdx, rsi
	lea	rcx, [DS000F+rip]
	call	AddPredefinedText@PLT
	movzx	edx, byte ptr [r14+0x15]
	lea	rcx, [DS0010+rip]
	call	$_001
	mov	qword ptr [sym_Model+rip], rax
	movzx	edx, byte ptr [r14+0x9]
	lea	rcx, [DS0011+rip]
	call	$_001
	mov	qword ptr [sym_Interface+rip], rax
	cmp	byte ptr [r14+0x5], 2
	jnz	$_029
	cmp	byte ptr [r14+0x7], 2
	jz	$_028
	cmp	byte ptr [r14+0x7], 5
	jz	$_028
	cmp	byte ptr [r14+0x7], 3
	jnz	$_029
$_028:	xor	edx, edx
	lea	rcx, [DS0012+rip]
	call	$_001
	mov	qword ptr [sym_ReservedStack+rip], rax
$_029:	cmp	byte ptr [r14+0xB], 2
	jz	$_030
	cmp	byte ptr [r14+0xB], 3
	jnz	$_031
	cmp	dword ptr [Options+0x8C+rip], 0
	jnz	$_031
$_030:	call	pe_create_PE_header@PLT
$_031:	add	rsp, 32
	pop	rbx
	pop	rdi
	pop	rsi
	ret

ModelDirective:
	mov	qword ptr [rsp+0x8], rcx
	mov	qword ptr [rsp+0x10], rdx
	push	rsi
	push	rdi
	push	rbx
	push	rbp
	mov	rbp, rsp
	sub	rsp, 40
	cmp	dword ptr [Parse_Pass+rip], 0
	jz	$_032
	cmp	byte ptr [r14+0x15], 0
	jz	$_032
	call	$_005
	xor	eax, eax
	jmp	$_055

$_032:	inc	dword ptr [rbp+0x28]
	imul	ebx, dword ptr [rbp+0x28], 32
	add	rbx, qword ptr [rbp+0x30]
	cmp	byte ptr [rbx], 0
	jnz	$_033
	mov	ecx, 2013
	call	asmerr@PLT
	jmp	$_055

$_033:	mov	edi, dword ptr [rbp+0x28]
	xor	esi, esi
	mov	r8d, 7
	lea	rdx, [ModelToken+rip]
	mov	rcx, qword ptr [rbx+0x10]
	call	FindToken@PLT
	cmp	eax, 0
	jl	$_035
	lea	esi, [rax+0x1]
	add	rbx, 32
	inc	edi
	cmp	byte ptr [r14+0x15], 0
	jz	$_034
	mov	ecx, 4011
	call	asmerr@PLT
$_034:	jmp	$_036

$_035:	mov	rdx, qword ptr [rbx+0x10]
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_055

$_036:	mov	byte ptr [rbp-0x4], 0
	jmp	$_044

$_037:	cmp	edi, dword ptr [r14+0x64]
	jge	$_045
	inc	edi
	add	rbx, 32
	cmp	byte ptr [rbx], 44
	je	$_044
	mov	dword ptr [rbp+0x28], 0
	lea	r8, [rbp-0x2]
	mov	rdx, rbx
	lea	rcx, [rbp+0x28]
	call	GetLangType@PLT
	test	eax, eax
	jnz	$_038
	inc	edi
	add	rbx, 32
	mov	cl, 1
	jmp	$_042

$_038:	mov	r8d, 7
	lea	rdx, [ModelAttr+rip]
	mov	rcx, qword ptr [rbx+0x10]
	call	FindToken@PLT
	cmp	eax, 0
	jl	$_045
	lea	rdx, [ModelAttrValue+rip]
	mov	cl, byte ptr [rdx+rax*2+0x1]
	mov	al, byte ptr [rdx+rax*2]
	cmp	cl, 2
	jnz	$_040
	cmp	esi, 7
	jnz	$_039
	mov	ecx, 2178
	call	asmerr@PLT
	jmp	$_055

$_039:	mov	byte ptr [rbp-0x1], al
	jmp	$_041

$_040:	cmp	cl, 4
	jnz	$_041
	mov	byte ptr [rbp-0x3], al
$_041:	inc	edi
	add	rbx, 32
$_042:	test	byte ptr [rbp-0x4], cl
	jz	$_043
	dec	edi
	sub	rbx, 32
	jmp	$_045

$_043:	or	byte ptr [rbp-0x4], cl
$_044:	cmp	byte ptr [rbx], 44
	je	$_037
$_045:	cmp	byte ptr [rbx], 0
	jz	$_046
	mov	rdx, qword ptr [rbx+0x18]
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_055

$_046:	cmp	esi, 7
	jnz	$_051
	movzx	eax, byte ptr [r14+0x14]
	and	eax, 0x9F
	test	eax, 0x80
	jz	$_047
	mov	eax, 128
	jmp	$_048

$_047:	cmp	eax, 6
	jc	$_048
	mov	eax, 6
$_048:	cmp	eax, 3
	jnc	$_049
	mov	ecx, 2085
	call	asmerr@PLT
	jmp	$_055

$_049:	test	byte ptr [r14+0x14], 0x80
	jz	$_051
	cmp	dword ptr [Options+0x8C+rip], 2
	jnz	$_050
	lea	rax, [coff64_fmtopt+rip]
	mov	qword ptr [r14+0x1B8], rax
	jmp	$_051

$_050:	cmp	dword ptr [Options+0x8C+rip], 3
	jnz	$_051
	lea	rax, [elf64_fmtopt+rip]
	mov	qword ptr [r14+0x1B8], rax
$_051:	mov	eax, esi
	mov	byte ptr [r14+0x15], al
	mov	cl, byte ptr [rbp-0x4]
	test	cl, 0x01
	jz	$_052
	mov	al, byte ptr [rbp-0x2]
	mov	byte ptr [r14+0x9], al
$_052:	test	cl, 0x02
	jz	$_053
	mov	al, byte ptr [rbp-0x1]
	mov	byte ptr [r14+0x1A], al
$_053:	test	cl, 0x04
	jz	$_054
	mov	al, byte ptr [rbp-0x3]
	mov	byte ptr [r14+0x1C], al
$_054:	call	SetModelDefaultSegNames@PLT
	call	$_005
	xor	eax, eax
$_055:	leave
	pop	rbx
	pop	rdi
	pop	rsi
	ret

SetCPU:
	push	rbp
	mov	rbp, rsp
	sub	rsp, 32
	movzx	eax, cl
	and	eax, 0x1F
	cmp	eax, 6
	ja	$_056
	xor	eax, eax
$_056:	mov	edx, eax
	movzx	eax, cl
	and	eax, 0x9F
	test	eax, 0x80
	jz	$_057
	mov	eax, 128
	jmp	$_058

$_057:	cmp	eax, 6
	jc	$_058
	mov	eax, 6
$_058:	test	cl, cl
	jz	$_059
	test	eax, eax
	jz	$_060
	test	edx, edx
	jnz	$_060
$_059:	and	byte ptr [r14+0x14], 0x60
	or	byte ptr [r14+0x14], al
	and	byte ptr [r14+0x14], 0xBF
	mov	al, cl
	and	al, 0x40
	or	byte ptr [r14+0x14], al
	test	byte ptr [Options+0x2+rip], 0x08
	jnz	$_060
	test	cl, 0x20
	jnz	$_060
	or	byte ptr [r14+0x14], 0x20
$_060:	test	cl, 0x80
	jz	$_061
	mov	eax, 157
	and	byte ptr [r14+0x14], 0x60
	or	byte ptr [r14+0x14], al
$_061:	test	edx, edx
	jz	$_062
	movzx	eax, dl
	and	byte ptr [r14+0x14], 0xE0
	or	byte ptr [r14+0x14], al
$_062:	movzx	eax, byte ptr [r14+0x14]
	and	eax, 0x9F
	test	eax, 0x80
	jz	$_063
	mov	eax, 128
	jmp	$_064

$_063:	cmp	eax, 6
	jc	$_064
	mov	eax, 6
$_064:	mov	ecx, eax
	jmp	$_072

$_065:	mov	eax, 3
	jmp	$_073

$_066:	mov	eax, 7
	jmp	$_073

$_067:	mov	eax, 15
	jmp	$_073

$_068:	mov	eax, 31
	jmp	$_073

$_069:	mov	eax, 63
	jmp	$_073

$_070:	mov	eax, 95
	jmp	$_073

$_071:	mov	eax, 1
	jmp	$_073

$_072:	cmp	ecx, 1
	jz	$_065
	cmp	ecx, 2
	jz	$_066
	cmp	ecx, 3
	jz	$_067
	cmp	ecx, 4
	jz	$_068
	cmp	ecx, 5
	jz	$_069
	cmp	ecx, 128
	jz	$_070
	cmp	ecx, 6
	jz	$_070
	jmp	$_071

$_073:
	test	byte ptr [r14+0x14], 0x40
	jz	$_074
	or	eax, 0x80
$_074:	test	byte ptr [r14+0x14], 0x20
	jz	$_080
	mov	edx, ecx
	cmp	edx, 3
	jbe	$_075
	mov	edx, 3
$_075:	jmp	$_079

$_076:	or	eax, 0x100
	jmp	$_080

$_077:	or	eax, 0x500
	jmp	$_080

$_078:	or	eax, 0xD00
	jmp	$_080

$_079:	cmp	edx, 0
	jz	$_076
	cmp	edx, 2
	jz	$_077
	cmp	edx, 3
	jz	$_078
$_080:	mov	dword ptr [r14+0xC], eax
	cmp	byte ptr [r14+0x15], 0
	jnz	$_083
	test	ecx, 0x80
	jz	$_081
	mov	eax, 2
	jmp	$_082

$_081:	mov	eax, 0
	cmp	ecx, 3
	jc	$_082
	mov	eax, 1
$_082:	mov	ecx, eax
	call	$_003
$_083:	mov	edx, dword ptr [r14+0xC]
	lea	rcx, [DS0013+rip]
	call	CreateVariable@PLT
	mov	qword ptr [sym_Cpu+rip], rax
	xor	eax, eax
	leave
	ret

CpuDirective:
	mov	qword ptr [rsp+0x8], rcx
	mov	qword ptr [rsp+0x10], rdx
	push	rbx
	push	rbp
	mov	rbp, rsp
	sub	rsp, 40
	imul	ebx, dword ptr [rbp+0x18], 32
	add	rbx, qword ptr [rbp+0x20]
	mov	eax, dword ptr [rbx+0x4]
	add	eax, eax
	mov	edx, dword ptr [r12+rax*8+0x4]
	add	rbx, 32
	cmp	byte ptr [rbx], 0
	jz	$_084
	mov	rdx, qword ptr [rbx+0x18]
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_085

$_084:	movzx	ecx, dl
	call	SetCPU
$_085:	leave
	pop	rbx
	ret


.SECTION .data
	.ALIGN	16

sym_Interface:
	.quad  0x0000000000000000

sym_Cpu: .quad	0x0000000000000000

coff64_fmtopt:
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x12, 0x0E, 0x50, 0x45, 0x33, 0x32, 0x2B, 0x00

elf64_fmtopt:
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x0F, 0x45, 0x4C, 0x46, 0x36, 0x34, 0x00

ModelToken:
	.quad  DS0000
	.quad  DS0001
	.quad  DS0002
	.quad  DS0003
	.quad  DS0004
	.quad  DS0005
	.quad  DS0006

ModelAttr:
	.quad  DS0007
	.quad  DS0008
	.quad  DS0009
	.quad  DS000A

ModelAttrValue:
	.byte  0x00, 0x02, 0x01, 0x02, 0x00, 0x04, 0x01, 0x04

sym_CodeSize:
	.quad  0x0000000000000000

sym_DataSize:
	.quad  0x0000000000000000

sym_Model:
	.quad  0x0000000000000000

DS000B:
	.byte  0x40, 0x43, 0x6F, 0x64, 0x65, 0x53, 0x69, 0x7A
	.byte  0x65, 0x00

DS000C:
	.byte  0x40, 0x63, 0x6F, 0x64, 0x65, 0x00

DS000D:
	.byte  0x40, 0x44, 0x61, 0x74, 0x61, 0x53, 0x69, 0x7A
	.byte  0x65, 0x00

DS000E:
	.byte  0x40, 0x64, 0x61, 0x74, 0x61, 0x00

DS000F:
	.byte  0x40, 0x73, 0x74, 0x61, 0x63, 0x6B, 0x00

DS0010:
	.byte  0x40, 0x4D, 0x6F, 0x64, 0x65, 0x6C, 0x00

DS0011:
	.byte  0x40, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61
	.byte  0x63, 0x65, 0x00

DS0012:
	.byte  0x40, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65
	.byte  0x64, 0x53, 0x74, 0x61, 0x63, 0x6B, 0x00

DS0013:
	.byte  0x40, 0x43, 0x70, 0x75, 0x00


.SECTION .rodata
	.ALIGN	16

DS0000:
	.byte  0x54, 0x49, 0x4E, 0x59, 0x00

DS0001:
	.byte  0x53, 0x4D, 0x41, 0x4C, 0x4C, 0x00

DS0002:
	.byte  0x43, 0x4F, 0x4D, 0x50, 0x41, 0x43, 0x54, 0x00

DS0003:
	.byte  0x4D, 0x45, 0x44, 0x49, 0x55, 0x4D, 0x00

DS0004:
	.byte  0x4C, 0x41, 0x52, 0x47, 0x45, 0x00

DS0005:
	.byte  0x48, 0x55, 0x47, 0x45, 0x00

DS0006:
	.byte  0x46, 0x4C, 0x41, 0x54, 0x00

DS0007:
	.byte  0x4E, 0x45, 0x41, 0x52, 0x53, 0x54, 0x41, 0x43
	.byte  0x4B, 0x00

DS0008:
	.byte  0x46, 0x41, 0x52, 0x53, 0x54, 0x41, 0x43, 0x4B
	.byte  0x00

DS0009:
	.byte  0x4F, 0x53, 0x5F, 0x44, 0x4F, 0x53, 0x00

DS000A:
	.byte  0x4F, 0x53, 0x5F, 0x4F, 0x53, 0x32, 0x00


.att_syntax prefix
