// File: /workspace/github_cpp_makefile_star2_O3/mdpkh[P]retro6k/src/main.cpp
// Function: LogStep
void LogStep()
{
	extern uint32_t clockticks6502;
	extern uint16_t pc;
	extern uint8_t sp, a, x, y, status;
	static dlogentry* laststateentry = nullptr, * lastinstentry = nullptr, * lastboringentry = nullptr;
	bool newsuppresslogging = (bool)(syspflags[pc >> 8] & pageflags::PF_DONTLOG);
	if (newsuppresslogging && !suppresslogging)
	{
		if (laststateentry && lastinstentry)
			lastinstentry->instentry.cycles = clockticks6502 - laststateentry->stateentry.ticks;
		lastboringentry = ExtendLog(dletype::LT_BORING);
		lastboringentry->boringentry.entryclock = clockticks6502;
		lastboringentry->boringentry.complete = false;
		lastinstentry = nullptr;
	}
	else if (!newsuppresslogging && suppresslogging)
	{
		lastboringentry->boringentry.exitclock = clockticks6502;
		lastboringentry->boringentry.complete = true;
	}
	suppresslogging = newsuppresslogging;
	if (suppresslogging)
		return;
	if (partialinst && partialinst->entrytype == dletype::LT_PARTIALINST)
		partialinst->entrytype = dletype::LT_INST;
	dlogentry* newentry = ExtendLog(dletype::LT_STATE);
	newentry->stateentry.ticks = clockticks6502;
	newentry->stateentry.pc = pc;
	newentry->stateentry.sp = sp;
	newentry->stateentry.a = a;
	newentry->stateentry.x = x;
	newentry->stateentry.y = y;
	newentry->stateentry.status = status;
	if (laststateentry && lastinstentry)
		lastinstentry->instentry.cycles = newentry->stateentry.ticks - laststateentry->stateentry.ticks;
	if (laststateentry && laststateentry->stateentry.sp != newentry->stateentry.sp)
		LogStack(sp);
	laststateentry = newentry;
	lastinstentry = partialinst = ExtendLog(dletype::LT_PARTIALINST);
	debuglogexpectargs = -1;
}

// Assembly:
movq 0x10782(%rip), %rax     # 0x1c468
leaq 0x815a91(%rip), %rcx    # 0x82177e
movzwl (%rcx), %edx
movl %edx, %ecx
shrl $0x8, %ecx
movb (%rax,%rcx), %sil
movl %esi, %eax
shrb $0x7, %al
movb 0x109bd(%rip), %cl      # 0x1c6c1
testb %sil, %sil
js 0xbe22
testb %cl, %cl
je 0xbd28
leaq 0x815a5c(%rip), %rcx    # 0x821774
movl (%rcx), %ecx
movq 0x81468f(%rip), %rsi    # 0x8203b0
movl %ecx, 0x8(%rsi)
movb $0x1, 0xc(%rsi)
movb %al, 0x10993(%rip)      # 0x1c6c1
movq 0x810b0b(%rip), %rax    # 0x81c840
testq %rax, %rax
je 0xbd42
cmpb $0x6, (%rax)
jne 0xbd42
movb $0x7, (%rax)
movslq 0x105af(%rip), %rsi     # 0x1c2f8
movl 0x810ae1(%rip), %ecx    # 0x81c830
leal 0x1(%rsi), %eax
andl $0x7ffff, %eax          # imm = 0x7FFFF
cmpl %ecx, %esi
jne 0xbd63
movl %eax, 0x810acf(%rip)    # 0x81c830
movl %eax, %ecx
pushq %r14
pushq %rbx
pushq %rax
movslq %ecx, %rdi
shlq $0x4, %rdi
leaq 0x10abb(%rip), %rbx     # 0x1c830
movb $0x0, (%rdi,%rbx)
shlq $0x4, %rsi
leaq (%rbx,%rsi), %r14
movb $0x5, (%rsi,%rbx)
movl %eax, 0x1056d(%rip)     # 0x1c2f8
leaq 0x8159e2(%rip), %rdi    # 0x821774
movb (%rdi), %dil
movb %dil, 0x4(%rsi,%rbx)
movw %dx, 0x6(%rsi,%rbx)
leaq 0x8159d6(%rip), %rdx    # 0x82177c
movb (%rdx), %dl
movb %dl, 0x8(%rsi,%rbx)
leaq 0x8159cd(%rip), %r8     # 0x821780
movb (%r8), %r8b
movb %r8b, 0x9(%rsi,%rbx)
leaq 0x8159bf(%rip), %r8     # 0x821781
movb (%r8), %r8b
movb %r8b, 0xa(%rsi,%rbx)
leaq 0x8159b1(%rip), %r8     # 0x821782
movb (%r8), %r8b
movb %r8b, 0xb(%rsi,%rbx)
leaq 0x8159a3(%rip), %r8     # 0x821783
movb (%r8), %r8b
movb %r8b, 0xc(%rsi,%rbx)
movq 0x8145b1(%rip), %rsi    # 0x8203a0
testq %rsi, %rsi
setne %r9b
movq 0x8145ab(%rip), %r8     # 0x8203a8
testq %r8, %r8
setne %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0xbed5
subb 0x4(%rsi), %dil
movb %dil, 0x9(%r8)
movb 0x8(%r14), %dil
jmp 0xbedc
testb %cl, %cl
jne 0xbece
movq 0x81456f(%rip), %rcx    # 0x8203a0
testq %rcx, %rcx
setne %sil
movq 0x814569(%rip), %rdx    # 0x8203a8
testq %rdx, %rdx
setne %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0xbe61
leaq 0x81591e(%rip), %rsi    # 0x821774
movb (%rsi), %sil
subb 0x4(%rcx), %sil
movb %sil, 0x9(%rdx)
movslq 0x10490(%rip), %rcx     # 0x1c2f8
movl 0x8109c2(%rip), %esi    # 0x81c830
leal 0x1(%rcx), %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
cmpl %esi, %ecx
jne 0xbe83
movl %edx, 0x8109af(%rip)    # 0x81c830
movl %edx, %esi
movslq %esi, %rsi
shlq $0x4, %rsi
leaq 0x1099f(%rip), %rdi     # 0x1c830
xorl %r8d, %r8d
movb %r8b, (%rsi,%rdi)
shlq $0x4, %rcx
leaq (%rdi,%rcx), %rsi
movb $0xa, (%rcx,%rdi)
movl %edx, 0x1044e(%rip)     # 0x1c2f8
movq %rsi, 0x8144ff(%rip)    # 0x8203b0
leaq 0x8158bc(%rip), %rdx    # 0x821774
movl (%rdx), %edx
movl %edx, 0x4(%rcx,%rdi)
movb %r8b, 0xc(%rcx,%rdi)
movq $0x0, 0x8144da(%rip) # 0x8203a8
movb %al, 0x107ed(%rip)      # 0x1c6c1
retq
movl %edx, %edi
testq %rsi, %rsi
je 0xbef6
cmpb %dil, 0x8(%rsi)
je 0xbef6
movzbl %dl, %edi
callq 0xce37
movl 0x10408(%rip), %eax     # 0x1c2f8
movl 0x81093a(%rip), %ecx    # 0x81c830
movq %r14, 0x8144a3(%rip)    # 0x8203a0
leal 0x1(%rax), %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
cmpl %ecx, %eax
jne 0xbf12
movl %edx, 0x810920(%rip)    # 0x81c830
movl %edx, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
movb $0x0, (%rcx,%rbx)
cltq
shlq $0x4, %rax
leaq (%rbx,%rax), %rcx
movb $0x6, (%rax,%rbx)
movl %edx, 0x103c7(%rip)     # 0x1c2f8
movq %rcx, 0x810908(%rip)    # 0x81c840
movq %rcx, 0x814469(%rip)    # 0x8203a8
movl $0xffffffff, 0x8108eb(%rip) # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
retq