
.intel_syntax noprefix

.global AddLinnumDataRef
.global QueueDeleteLinnum
.global LinnumFini
.global LinnumInit

.extern procidx
.extern omf_check_flush
.extern AddPublicData
.extern CreateProc
.extern CurrProc
.extern TypeFromClassName
.extern GetCurrOffset
.extern SetSymSegOfs
.extern GetLineNumber
.extern LclAlloc
.extern tsprintf
.extern asmerr
.extern write_to_file
.extern Options
.extern Parse_Pass
.extern SymFind


.SECTION .text
	.ALIGN	16

$_001:	mov	qword ptr [rsp+0x8], rcx
	push	rsi
	push	rdi
	push	rbx
	push	rbp
	mov	rbp, rsp
	sub	rsp, 40
	mov	rbx, qword ptr [r14+0x38]
	mov	rdi, qword ptr [rbx+0x78]
	cmp	dword ptr [Options+0x8C+rip], 2
	jz	$_002
	cmp	dword ptr [Options+0x8C+rip], 3
	jnz	$_004
$_002:	mov	rsi, qword ptr [rdi+0x38]
	test	rsi, rsi
	jnz	$_003
	mov	ecx, 16
	call	LclAlloc@PLT
	mov	rsi, rax
	mov	qword ptr [rdi+0x38], rsi
	mov	qword ptr [rsi], 0
$_003:	jmp	$_005

$_004:	lea	rsi, [r14+0x258]
$_005:	mov	rdi, qword ptr [rbp+0x28]
	mov	qword ptr [rdi], 0
	cmp	qword ptr [rsi], 0
	jnz	$_006
	mov	qword ptr [rsi], rdi
	mov	qword ptr [rsi+0x8], rdi
	jmp	$_007

$_006:	mov	rcx, qword ptr [rsi+0x8]
	mov	qword ptr [rcx], rdi
	mov	qword ptr [rsi+0x8], rdi
$_007:	leave
	pop	rbx
	pop	rdi
	pop	rsi
	ret

AddLinnumDataRef:
	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, 56
	mov	rbx, qword ptr [CurrProc+rip]
	mov	rsi, qword ptr [dmyproc+rip]
	test	rsi, rsi
	jz	$_008
	mov	rdi, qword ptr [rsi+0x68]
$_008:	cmp	dword ptr [Options+0x8C+rip], 2
	jne	$_013
	cmp	byte ptr [Options+0xAA+rip], 4
	je	$_013
	test	rbx, rbx
	jne	$_013
	test	rsi, rsi
	jz	$_009
	mov	eax, dword ptr [rbp+0x28]
	cmp	word ptr [rdi+0xE], ax
	jnz	$_009
	mov	rax, qword ptr [r14+0x38]
	cmp	qword ptr [rsi+0x40], rax
	je	$_013
$_009:	test	rsi, rsi
	jz	$_010
	mov	rcx, qword ptr [rsi+0x40]
	mov	rcx, qword ptr [rcx+0x78]
	mov	eax, dword ptr [rcx+0xC]
	sub	eax, dword ptr [rsi+0x30]
	mov	dword ptr [rsi+0x60], eax
$_010:	mov	r8d, dword ptr [procidx+rip]
	lea	rdx, [DS0000+rip]
	lea	rcx, [rbp-0xC]
	call	tsprintf@PLT
	lea	rcx, [rbp-0xC]
	call	SymFind@PLT
	mov	qword ptr [dmyproc+rip], rax
	mov	rsi, rax
	test	rsi, rsi
	jnz	$_011
	mov	r8d, 1
	lea	rdx, [rbp-0xC]
	xor	ecx, ecx
	call	CreateProc@PLT
	mov	qword ptr [dmyproc+rip], rax
	mov	rsi, rax
	or	byte ptr [rsi+0x10], 0x02
	or	byte ptr [rsi+0x11], 0x08
	mov	rcx, rsi
	call	AddPublicData@PLT
	jmp	$_012

$_011:	inc	dword ptr [procidx+rip]
$_012:	test	byte ptr [rsi+0x10], 0x02
	jz	$_013
	mov	rcx, rsi
	call	SetSymSegOfs@PLT
	mov	al, byte ptr [r14+0x4]
	mov	byte ptr [rsi+0x48], al
	mov	al, byte ptr [r14+0x9]
	mov	byte ptr [rsi+0x1F], al
	cmp	dword ptr [write_to_file+rip], 1
	jnz	$_013
	mov	ecx, 24
	call	LclAlloc@PLT
	mov	rdi, rax
	mov	qword ptr [rdi+0x10], rsi
	call	GetLineNumber@PLT
	mov	dword ptr [rdi+0xC], eax
	mov	eax, dword ptr [rbp+0x28]
	shl	eax, 20
	or	dword ptr [rdi+0xC], eax
	mov	dword ptr [rdi+0x8], 0
	mov	rcx, rdi
	call	$_001
$_013:	cmp	dword ptr [rbp+0x30], 0
	jz	$_015
	cmp	dword ptr [write_to_file+rip], 0
	jz	$_014
	mov	eax, dword ptr [rbp+0x30]
	cmp	dword ptr [lastLineNumber+rip], eax
	jnz	$_015
$_014:	jmp	$_024

$_015:	mov	ecx, 24
	call	LclAlloc@PLT
	mov	rdi, rax
	mov	eax, dword ptr [rbp+0x30]
	mov	dword ptr [rdi+0x8], eax
	cmp	dword ptr [rbp+0x30], 0
	jne	$_020
	mov	rcx, qword ptr [CurrProc+rip]
	cmp	dword ptr [Parse_Pass+rip], 0
	jnz	$_016
	cmp	dword ptr [Options+0x8C+rip], 2
	jnz	$_016
	test	rcx, rcx
	jz	$_016
	test	byte ptr [rcx+0x10], 0x04
	jnz	$_016
	or	byte ptr [rcx+0x11], 0x08
	call	AddPublicData@PLT
$_016:	mov	rax, qword ptr [dmyproc+rip]
	cmp	qword ptr [CurrProc+rip], 0
	jz	$_017
	mov	rax, qword ptr [CurrProc+rip]
$_017:	mov	qword ptr [rdi+0x10], rax
	call	GetLineNumber@PLT
	mov	dword ptr [rdi+0xC], eax
	mov	eax, dword ptr [rbp+0x28]
	shl	eax, 20
	or	dword ptr [rdi+0xC], eax
	mov	rsi, qword ptr [dmyproc+rip]
	test	rsi, rsi
	jz	$_018
	mov	rcx, qword ptr [rsi+0x40]
	mov	rcx, qword ptr [rcx+0x78]
	mov	eax, dword ptr [rcx+0xC]
	sub	eax, dword ptr [rsi+0x30]
	mov	dword ptr [rsi+0x60], eax
	mov	qword ptr [dmyproc+rip], 0
$_018:	mov	rcx, qword ptr [CurrProc+rip]
	mov	rdx, qword ptr [rcx+0x78]
	test	ecx, ecx
	jz	$_019
	cmp	dword ptr [rdx+0x10], 0
	jz	$_019
	mov	rcx, rdi
	call	$_001
	mov	ecx, 24
	call	LclAlloc@PLT
	mov	rdi, rax
	call	GetLineNumber@PLT
	mov	dword ptr [rdi+0x8], eax
	call	GetCurrOffset@PLT
	mov	dword ptr [rdi+0xC], eax
	mov	eax, dword ptr [rbp+0x28]
	mov	dword ptr [rdi+0x10], eax
$_019:	jmp	$_021

$_020:	call	GetCurrOffset@PLT
	mov	dword ptr [rdi+0xC], eax
	mov	eax, dword ptr [rbp+0x28]
	mov	dword ptr [rdi+0x10], eax
$_021:	mov	eax, dword ptr [rbp+0x30]
	mov	dword ptr [lastLineNumber+rip], eax
	cmp	dword ptr [Options+0x8C+rip], 1
	jnz	$_022
	mov	rcx, rdi
	call	omf_check_flush@PLT
$_022:	mov	rbx, qword ptr [r14+0x38]
	mov	rsi, qword ptr [rbx+0x78]
	test	byte ptr [rsi+0x1C], 0x40
	jnz	$_023
	or	byte ptr [rsi+0x1C], 0x40
	mov	rdx, qword ptr [rsi+0x50]
	mov	rcx, rbx
	call	TypeFromClassName@PLT
	cmp	rax, 1
	jz	$_023
	mov	rdx, qword ptr [rbx+0x8]
	mov	ecx, 4012
	call	asmerr@PLT
$_023:	mov	rcx, rdi
	call	$_001
$_024:	leave
	pop	rbx
	pop	rdi
	pop	rsi
	ret

QueueDeleteLinnum:
	test	rcx, rcx
	jz	$_026
	mov	rdx, qword ptr [rcx]
$_025:	test	rdx, rdx
	jz	$_026
	mov	rax, qword ptr [rdx]
	mov	rdx, rax
	jmp	$_025

$_026:
	ret

LinnumFini:
	mov	rax, qword ptr [dmyproc+rip]
	test	rax, rax
	jz	$_027
	mov	rcx, qword ptr [rax+0x40]
	mov	rcx, qword ptr [rcx+0x78]
	mov	edx, dword ptr [rcx+0xC]
	sub	edx, dword ptr [rax+0x30]
	mov	dword ptr [rax+0x60], edx
$_027:	ret

LinnumInit:
	mov	dword ptr [lastLineNumber+rip], 0
	mov	qword ptr [dmyproc+rip], 0
	ret


.SECTION .data
	.ALIGN	16

dmyproc:
	.quad  0x0000000000000000

lastLineNumber:
	.int   0x00000000

DS0000:
	.byte  0x24, 0x24, 0x24, 0x25, 0x30, 0x35, 0x75, 0x00


.att_syntax prefix
