
.intel_syntax noprefix

.global AssertDirective

.extern RunLineQueue
.extern AddLineQueueX
.extern AddLineQueue
.extern GetCurrOffset
.extern ExpandCStrings
.extern EvaluateHllExpression
.extern GetLabelStr
.extern LstWrite
.extern CondPrepare
.extern CurrIfState
.extern MemDup
.extern LclAlloc
.extern MemFree
.extern asmerr
.extern SymFindID
.extern tstrcpy
.extern tstrchr


.SECTION .text
	.ALIGN	16

AssertDirective:
	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, 4168
	mov	dword ptr [rbp-0x1014], 0
	mov	rbx, rdx
	lea	rdi, [rbp-0x800]
	imul	eax, dword ptr [rbp+0x28], 32
	mov	eax, dword ptr [rbx+rax+0x4]
	mov	dword ptr [rbp-0x1018], eax
	inc	dword ptr [rbp+0x28]
	mov	rsi, qword ptr [r14+0x2E8]
	test	rsi, rsi
	jnz	$_001
	mov	ecx, 56
	call	LclAlloc@PLT
	mov	rsi, rax
$_001:	mov	rcx, qword ptr [rbp+0x30]
	call	ExpandCStrings@PLT
	xor	eax, eax
	mov	dword ptr [rsi+0x14], eax
	mov	dword ptr [rsi+0x30], eax
	mov	eax, dword ptr [rbp-0x1018]
	jmp	$_034

$_002:	imul	edx, dword ptr [rbp+0x28], 32
	mov	al, byte ptr [rbx+rdx]
	cmp	al, 58
	jne	$_017
	add	dword ptr [rbp+0x28], 2
	lea	rdi, [rbx+rdx+0x20]
	mov	al, byte ptr [rbx+rdx+0x20]
	cmp	al, 8
	jnz	$_003
	mov	rcx, rdi
	call	SymFindID@PLT
	test	rax, rax
	jz	$_003
	mov	rcx, qword ptr [r14+0x178]
	call	MemFree@PLT
	mov	rcx, qword ptr [rdi+0x10]
	call	MemDup@PLT
	mov	qword ptr [r14+0x178], rax
	jmp	$_035

$_003:	mov	eax, dword ptr [rdi+0x8]
	mov	rdi, qword ptr [rdi+0x10]
	cmp	eax, 3552940378
	jnz	$_005
	test	byte ptr [r14+0x2], 0x02
	jnz	$_004
	mov	ecx, 537
	call	CondPrepare@PLT
	mov	dword ptr [CurrIfState+rip], 2
$_004:	jmp	$_035

$_005:	cmp	eax, 4167245695
	jnz	$_006
	jmp	$_035

$_006:	cmp	eax, 1758001241
	jnz	$_008
	movzx	eax, byte ptr [r14+0x2]
	and	eax, 0x02
	shr	eax, 1
	movzx	ecx, byte ptr [r14+0x2]
	and	ecx, 0x04
	shr	ecx, 2
	shl	ecx, 1
	or	eax, ecx
	mov	ecx, dword ptr [assert_stid+rip]
	cmp	ecx, 124
	jnc	$_007
	lea	rdx, [assert_stack+rip]
	mov	byte ptr [rdx+rcx], al
	inc	dword ptr [assert_stid+rip]
$_007:	jmp	$_035

$_008:	cmp	eax, 1081563622
	jnz	$_012
	mov	ecx, dword ptr [assert_stid+rip]
	lea	rdx, [assert_stack+rip]
	mov	al, byte ptr [rdx+rcx]
	test	al, 0x01
	jz	$_009
	or	byte ptr [r14+0x2], 0x02
$_009:	test	al, 0x02
	jz	$_010
	or	byte ptr [r14+0x2], 0x04
$_010:	test	ecx, ecx
	jz	$_011
	dec	dword ptr [assert_stid+rip]
$_011:	jmp	$_035

$_012:	cmp	eax, 1651971902
	jnz	$_013
	or	byte ptr [r14+0x2], 0x02
	jmp	$_035

$_013:	cmp	eax, 930712164
	jnz	$_014
	and	byte ptr [r14+0x2], 0xFD
	jmp	$_035

$_014:	cmp	eax, 1298068605
	jnz	$_015
	or	byte ptr [r14+0x2], 0x04
	jmp	$_035

$_015:	cmp	eax, 1642235252
	jnz	$_016
	and	byte ptr [r14+0x2], 0xFB
	jmp	$_035

$_016:	mov	rdx, rdi
	mov	ecx, 2008
	call	asmerr@PLT
	jmp	$_035

	jmp	$_019

$_017:	test	al, al
	jz	$_018
	test	byte ptr [r14+0x2], 0x02
	jnz	$_019
$_018:	jmp	$_035

$_019:	imul	edx, dword ptr [rbp+0x28], 32
	mov	rdx, qword ptr [rbx+rdx+0x18]
	lea	rcx, [rbp-0x1000]
	call	tstrcpy@PLT
	test	byte ptr [r14+0x2], 0x04
	jz	$_021
	cmp	byte ptr [r14+0x4], 2
	jnz	$_020
	lea	rcx, [DS0000+rip]
	call	AddLineQueue@PLT
	jmp	$_021

$_020:	lea	rcx, [DS0001+rip]
	call	AddLineQueue@PLT
$_021:	mov	dword ptr [rsi+0x28], 0
	mov	dword ptr [rsi+0x18], 0
	inc	dword ptr [r14+0x36C]
	mov	eax, dword ptr [r14+0x36C]
	mov	dword ptr [rsi+0x10], eax
	lea	rcx, [rbp-0x1010]
	inc	dword ptr [r14+0x36C]
	mov	eax, dword ptr [r14+0x36C]
	mov	rdx, rcx
	mov	ecx, eax
	call	GetLabelStr@PLT
	mov	qword ptr [rsp+0x28], rdi
	mov	dword ptr [rsp+0x20], 0
	xor	r9d, r9d
	mov	r8, rbx
	lea	rdx, [rbp+0x28]
	mov	rcx, rsi
	call	EvaluateHllExpression@PLT
	mov	dword ptr [rbp-0x1014], eax
	test	eax, eax
	jne	$_035
	mov	rcx, rdi
	call	AddLineQueue@PLT
	test	byte ptr [r14+0x2], 0x04
	jz	$_023
	cmp	byte ptr [r14+0x4], 2
	jnz	$_022
	lea	rcx, [DS0002+rip]
	call	AddLineQueue@PLT
	jmp	$_023

$_022:	lea	rcx, [DS0003+rip]
	call	AddLineQueue@PLT
$_023:	mov	rdx, rdi
	mov	ecx, dword ptr [rsi+0x10]
	call	GetLabelStr@PLT
	lea	r9, [DS0005+rip]
	mov	r8, rax
	lea	rdx, [rbp-0x1010]
	lea	rcx, [DS0004+rip]
	call	AddLineQueueX@PLT
	test	byte ptr [r14+0x2], 0x04
	jz	$_025
	cmp	byte ptr [r14+0x4], 2
	jnz	$_024
	lea	rcx, [DS0002+rip]
	call	AddLineQueue@PLT
	jmp	$_025

$_024:	lea	rcx, [DS0003+rip]
	call	AddLineQueue@PLT
$_025:	cmp	byte ptr [rdi], 0
	je	$_035
	mov	rax, qword ptr [r14+0x178]
	test	rax, rax
	jnz	$_026
	lea	rax, [DS0006+rip]
	mov	qword ptr [r14+0x178], rax
$_026:	mov	rdx, rax
	lea	rcx, [DS0007+rip]
	call	AddLineQueueX@PLT
	lea	rcx, [DS0008+rip]
	call	AddLineQueue@PLT
	lea	rbx, [rbp-0x1000]
	jmp	$_029

$_027:	mov	byte ptr [rax], 0
	xchg	rbx, rax
	inc	rbx
	cmp	byte ptr [rax], 0
	jz	$_028
	mov	rdx, rax
	lea	rcx, [DS0009+rip]
	call	AddLineQueueX@PLT
	jmp	$_029

$_028:	lea	rcx, [DS000A+rip]
	call	AddLineQueue@PLT
$_029:	mov	edx, 34
	mov	rcx, rbx
	call	tstrchr@PLT
	test	rax, rax
	jnz	$_027
	cmp	byte ptr [rbx], 0
	jz	$_030
	mov	rdx, rbx
	lea	rcx, [DS000B+rip]
	call	AddLineQueueX@PLT
$_030:	lea	r8, [DS0005+rip]
	lea	rdx, [rbp-0x1010]
	lea	rcx, [DS000C+rip]
	call	AddLineQueueX@PLT
	jmp	$_035

$_031:	or	byte ptr [rsi+0x32], 0x02
	jmp	$_002

$_032:	or	byte ptr [rsi+0x32], 0x01
	jmp	$_002

$_033:	or	byte ptr [rsi+0x31], 0x80
	jmp	$_002

$_034:	cmp	eax, 488
	je	$_002
	cmp	eax, 491
	jz	$_031
	cmp	eax, 490
	jz	$_032
	cmp	eax, 489
	jz	$_033
$_035:	test	byte ptr [r14], 0x08
	jz	$_036
	call	GetCurrOffset@PLT
	xor	r8d, r8d
	mov	edx, eax
	mov	ecx, 4
	call	LstWrite@PLT
$_036:	cmp	qword ptr [r14+0x2B0], 0
	jz	$_037
	call	RunLineQueue@PLT
$_037:	mov	eax, dword ptr [rbp-0x1014]
	leave
	pop	rbx
	pop	rdi
	pop	rsi
	ret


.SECTION .data
	.ALIGN	16

assert_stack:
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
	.byte  0x00, 0x00, 0x00, 0x00

assert_stid:
	.int   0x00000000

DS0000:
	.byte  0x20, 0x70, 0x75, 0x73, 0x68, 0x66, 0x71, 0x0A
	.byte  0x20, 0x73, 0x75, 0x62, 0x20, 0x72, 0x73, 0x70
	.byte  0x2C, 0x32, 0x38, 0x68, 0x00

DS0001:
	.byte  0x20, 0x70, 0x75, 0x73, 0x68, 0x66, 0x64, 0x00

DS0002:
	.byte  0x20, 0x61, 0x64, 0x64, 0x20, 0x72, 0x73, 0x70
	.byte  0x2C, 0x32, 0x38, 0x68, 0x0A, 0x20, 0x70, 0x6F
	.byte  0x70, 0x66, 0x71, 0x00

DS0003:
	.byte  0x20, 0x70, 0x6F, 0x70, 0x66, 0x64, 0x00

DS0004:
	.byte  0x6A, 0x6D, 0x70, 0x20, 0x25, 0x73, 0x0A, 0x25
	.byte  0x73, 0x25, 0x73, 0x00

DS0005:
	.byte  0x3A, 0x00

DS0006:
	.byte  0x61, 0x73, 0x73, 0x65, 0x72, 0x74, 0x5F, 0x65
	.byte  0x78, 0x69, 0x74, 0x00

DS0007:
	.byte  0x25, 0x73, 0x28, 0x29, 0x00

DS0008:
	.byte  0x64, 0x62, 0x20, 0x40, 0x43, 0x61, 0x74, 0x53
	.byte  0x74, 0x72, 0x28, 0x21, 0x22, 0x2C, 0x25, 0x40
	.byte  0x46, 0x69, 0x6C, 0x65, 0x4E, 0x61, 0x6D, 0x65
	.byte  0x2C, 0x3C, 0x28, 0x3E, 0x2C, 0x25, 0x40, 0x4C
	.byte  0x69, 0x6E, 0x65, 0x2C, 0x3C, 0x29, 0x3A, 0x20
	.byte  0x3E, 0x2C, 0x21, 0x22, 0x29, 0x00

DS0009:
	.byte  0x64, 0x62, 0x20, 0x22, 0x25, 0x73, 0x22, 0x2C
	.byte  0x32, 0x32, 0x68, 0x00

DS000A:
	.byte  0x64, 0x62, 0x20, 0x32, 0x32, 0x68, 0x00

DS000B:
	.byte  0x64, 0x62, 0x20, 0x22, 0x25, 0x73, 0x22, 0x00

DS000C:
	.byte  0x64, 0x62, 0x20, 0x30, 0x0A, 0x25, 0x73, 0x25
	.byte  0x73, 0x00


.att_syntax prefix
