
.intel_syntax noprefix

.global LabelInit
.global CreateLabel
.global LabelDirective

.extern EvalOperand
.extern LstWrite
.extern GetQualifiedType
.extern SegAssumeTable
.extern CopyPrototype
.extern CreateProc
.extern CurrProc
.extern SetSymSegOfs
.extern sym_ext2int
.extern sym_remove_table
.extern SymTables
.extern BackPatch
.extern tsprintf
.extern asmerr
.extern Options
.extern Parse_Pass
.extern SymLookupLocal
.extern SymLookup


.SECTION .text
	.ALIGN	16

LabelInit:
	mov	dword ptr [r14+0x32C], 0
	ret

CreateLabel:
	mov	qword ptr [rsp+0x10], rdx
	mov	qword ptr [rsp+0x18], r8
	mov	qword ptr [rsp+0x20], r9
	push	rsi
	push	rdi
	push	rbx
	push	rbp
	mov	rbp, rsp
	sub	rsp, 56
	cmp	qword ptr [r14+0x38], 0
	jnz	$_001
	mov	ecx, 2034
	call	asmerr@PLT
	xor	eax, eax
	jmp	$_024

$_001:	mov	rbx, rcx
	mov	rsi, rdx
	mov	al, r8b
	and	al, 0xC0
	cmp	al, 128
	jnz	$_002
	cmp	byte ptr [SegAssumeTable+0x18+rip], 0
	jz	$_002
	mov	ecx, 2108
	call	asmerr@PLT
	xor	eax, eax
	jmp	$_024

$_002:	mov	eax, dword ptr [rsi]
	and	eax, 0xFFFFFF
	cmp	eax, 16448
	jnz	$_003
	lea	rsi, [rbp-0x18]
	inc	dword ptr [r14+0x32C]
	mov	r8d, dword ptr [r14+0x32C]
	lea	rdx, [DS0000+rip]
	mov	rcx, rsi
	call	tsprintf@PLT
	xor	ebx, ebx
$_003:	cmp	dword ptr [rbp+0x48], 0
	jz	$_004
	mov	rdx, rsi
	mov	rcx, rbx
	call	SymLookupLocal@PLT
	jmp	$_005

$_004:	mov	rcx, rsi
	call	SymLookup@PLT
$_005:	mov	rdi, rax
	cmp	dword ptr [Parse_Pass+rip], 0
	jne	$_018
	cmp	byte ptr [rdi+0x1D], 2
	jnz	$_009
	test	byte ptr [rdi+0x4B], 0x02
	jz	$_009
	test	byte ptr [rdi+0x10], 0x02
	jnz	$_006
	cmp	dword ptr [rbp+0x48], 0
	jz	$_007
	cmp	qword ptr [CurrProc+rip], 0
	jz	$_007
$_006:	mov	rdx, qword ptr [rbp+0x30]
	mov	ecx, 2005
	call	asmerr@PLT
	xor	eax, eax
	jmp	$_024

$_007:	cmp	byte ptr [rdi+0x1E], 192
	jz	$_008
	mov	al, byte ptr [rbp+0x38]
	cmp	byte ptr [rdi+0x1E], al
	jz	$_008
	mov	rdx, rsi
	mov	ecx, 2004
	call	asmerr@PLT
$_008:	mov	rcx, rdi
	call	sym_ext2int@PLT
	jmp	$_011

$_009:	cmp	byte ptr [rdi+0x1D], 0
	jnz	$_010
	mov	rdx, rdi
	lea	rcx, [SymTables+rip]
	call	sym_remove_table@PLT
	mov	byte ptr [rdi+0x1D], 1
	jmp	$_011

$_010:	mov	rdx, rsi
	mov	ecx, 2005
	call	asmerr@PLT
	xor	eax, eax
	jmp	$_024

$_011:	mov	rcx, qword ptr [r14+0x38]
	mov	rcx, qword ptr [rcx+0x78]
	mov	rax, qword ptr [rcx+0x20]
	mov	qword ptr [rdi+0x80], rax
	mov	qword ptr [rcx+0x20], rdi
	test	rax, rax
	jz	$_012
	test	byte ptr [rax+0x10], 0x02
	jnz	$_012
	mov	qword ptr [rax+0x38], rdi
$_012:	cmp	byte ptr [rdi+0x1F], 0
	jnz	$_013
	mov	al, byte ptr [r14+0x9]
	mov	byte ptr [rdi+0x1F], al
$_013:	mov	rbx, qword ptr [rbp+0x40]
	cmp	byte ptr [rbp+0x38], 128
	jnz	$_015
	test	byte ptr [rdi+0x10], 0x02
	jnz	$_014
	mov	r8d, 1
	xor	edx, edx
	mov	rcx, rdi
	call	CreateProc@PLT
	mov	rdx, qword ptr [rbx+0x8]
	mov	rcx, rdi
	call	CopyPrototype@PLT
$_014:	mov	rcx, qword ptr [rbx+0x8]
	mov	al, byte ptr [rcx+0x1E]
	mov	byte ptr [rbp+0x38], al
	mov	qword ptr [rbx+0x8], 0
$_015:	mov	al, byte ptr [rbp+0x38]
	mov	byte ptr [rdi+0x1E], al
	test	rbx, rbx
	jz	$_017
	cmp	byte ptr [rbp+0x38], 196
	jnz	$_016
	mov	rax, qword ptr [rbx+0x8]
	mov	qword ptr [rdi+0x28], rax
	jmp	$_017

$_016:	mov	al, byte ptr [rbx+0x13]
	mov	byte ptr [rdi+0x48], al
	mov	al, byte ptr [rbx+0x11]
	mov	byte ptr [rdi+0x49], al
	mov	al, byte ptr [rbx+0x12]
	mov	byte ptr [rdi+0x21], al
	mov	rax, qword ptr [rbx+0x8]
	mov	qword ptr [rdi+0x50], rax
	mov	al, byte ptr [rbx+0x14]
	mov	byte ptr [rdi+0x4A], al
$_017:	jmp	$_019

$_018:	mov	eax, dword ptr [rdi+0x30]
	mov	dword ptr [rbp-0x4], eax
$_019:	or	byte ptr [rdi+0x10], 0x01
	test	byte ptr [rdi+0x12], 0x20
	jnz	$_020
	mov	eax, dword ptr [Parse_Pass+rip]
	mov	byte ptr [rdi+0x4A], al
$_020:	mov	rcx, rdi
	call	SetSymSegOfs@PLT
	mov	eax, dword ptr [rdi+0x30]
	cmp	dword ptr [Parse_Pass+rip], 0
	jnz	$_021
	mov	rcx, rdi
	call	BackPatch@PLT
	jmp	$_023

$_021:	cmp	eax, dword ptr [rbp-0x4]
	jz	$_023
	or	byte ptr [r14+0x370], 0x01
	cmp	byte ptr [rdi+0x4A], 1
	jnz	$_023
	test	byte ptr [r14+0x370], 0x02
	jz	$_023
	sub	eax, dword ptr [rbp-0x4]
	mov	rcx, qword ptr [rdi+0x38]
$_022:	test	rcx, rcx
	jz	$_023
	add	dword ptr [rcx+0x30], eax
	mov	rcx, qword ptr [rcx+0x38]
	jmp	$_022

$_023:	mov	rax, rdi
$_024:	leave
	pop	rbx
	pop	rdi
	pop	rsi
	ret

LabelDirective:
	mov	qword ptr [rsp+0x8], rcx
	mov	qword ptr [rsp+0x10], rdx
	push	rbx
	push	rbp
	mov	rbp, rsp
	sub	rsp, 184
	imul	ebx, dword ptr [rbp+0x18], 32
	add	rbx, qword ptr [rbp+0x20]
	cmp	dword ptr [rbp+0x18], 1
	jz	$_025
	mov	rdx, qword ptr [rbx+0x10]
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_038

$_025:	inc	dword ptr [rbp+0x18]
	mov	dword ptr [rbp-0x18], 0
	mov	byte ptr [rbp-0x7], 0
	mov	byte ptr [rbp-0x6], 0
	mov	byte ptr [rbp-0x8], 192
	mov	byte ptr [rbp-0x4], 192
	mov	qword ptr [rbp-0x10], 0
	mov	al, byte ptr [r14+0x4]
	mov	byte ptr [rbp-0x5], al
	lea	r8, [rbp-0x18]
	mov	rdx, qword ptr [rbp+0x20]
	lea	rcx, [rbp+0x18]
	call	GetQualifiedType@PLT
	cmp	eax, -1
	jnz	$_026
	jmp	$_038

$_026:	imul	ebx, dword ptr [rbp+0x18], 32
	add	rbx, qword ptr [rbp+0x20]
	mov	dword ptr [rbp-0x1C], -1
	mov	al, byte ptr [rbp-0x8]
	and	al, 0xC0
	cmp	al, 128
	jnz	$_028
	cmp	byte ptr [rbp-0x5], 254
	jz	$_027
	mov	al, byte ptr [rbp-0x5]
	cmp	byte ptr [r14+0x4], al
	jz	$_027
	mov	ecx, 2098
	call	asmerr@PLT
	jmp	$_038

$_027:	jmp	$_032

$_028:	cmp	byte ptr [rbx], 58
	jnz	$_032
	cmp	byte ptr [rbx+0x20], 0
	jz	$_032
	test	byte ptr [Options+0x6+rip], 0x10
	jnz	$_032
	inc	dword ptr [rbp+0x18]
	mov	byte ptr [rsp+0x20], 0
	lea	r9, [rbp-0x88]
	mov	r8d, dword ptr [r14+0x64]
	mov	rdx, qword ptr [rbp+0x20]
	lea	rcx, [rbp+0x18]
	call	EvalOperand@PLT
	cmp	eax, -1
	jnz	$_029
	jmp	$_038

$_029:	imul	ebx, dword ptr [rbp+0x18], 32
	add	rbx, qword ptr [rbp+0x20]
	cmp	dword ptr [rbp-0x4C], 0
	jz	$_031
	mov	rcx, qword ptr [rbp-0x38]
	test	rcx, rcx
	jz	$_030
	cmp	byte ptr [rcx+0x1D], 0
	jnz	$_030
	mov	dword ptr [rbp-0x88], 1
	jmp	$_031

$_030:	mov	ecx, 2026
	call	asmerr@PLT
	jmp	$_038

$_031:	mov	eax, dword ptr [rbp-0x88]
	mov	dword ptr [rbp-0x1C], eax
$_032:	cmp	byte ptr [rbx], 0
	jz	$_033
	mov	rdx, qword ptr [rbx+0x18]
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_038

$_033:	test	byte ptr [r14], 0x08
	jz	$_034
	xor	r8d, r8d
	xor	edx, edx
	mov	ecx, 7
	call	LstWrite@PLT
$_034:	mov	rbx, qword ptr [rbp+0x20]
	mov	dword ptr [rsp+0x20], 0
	lea	r9, [rbp-0x18]
	movzx	r8d, byte ptr [rbp-0x8]
	mov	rdx, qword ptr [rbx+0x10]
	mov	rcx, rbx
	call	CreateLabel
	test	rax, rax
	jz	$_037
	mov	rcx, rax
	mov	al, byte ptr [rcx+0x1E]
	and	al, 0xC0
	test	byte ptr [rcx+0x12], 0x20
	jnz	$_036
	cmp	al, 128
	jz	$_036
	cmp	dword ptr [rbp-0x1C], -1
	jz	$_035
	mov	eax, dword ptr [rbp-0x18]
	mul	dword ptr [rbp-0x1C]
	mov	dword ptr [rcx+0x60], eax
	mov	eax, dword ptr [rbp-0x1C]
	mov	dword ptr [rcx+0x68], eax
	or	byte ptr [rcx+0x10], 0x40
	jmp	$_036

$_035:	mov	eax, dword ptr [rbp-0x18]
	mov	dword ptr [rcx+0x60], eax
	mov	dword ptr [rcx+0x68], 1
$_036:	xor	eax, eax
	jmp	$_038

$_037:	mov	rax, -1
$_038:	leave
	pop	rbx
	ret


.SECTION .data
	.ALIGN	16

DS0000:
	.byte  0x4C, 0x26, 0x5F, 0x25, 0x30, 0x34, 0x75, 0x00


.att_syntax prefix
