// File: /workspace/github_cpp_makefile_star2_O2/lhydave[P]SysYCompilerLab/front/node.cpp
// Function: sysY_AST::cond_exp_node::traverse()
void cond_exp_node::traverse()
{
	if (right == nullptr) // leaf node
	{
		left->reduce();
		left->new_temp();
		code += left->code;
		if (true_label != fall_label && false_label != fall_label) // if-else
		{
			code += "\tif " + left->eeyore_name + " == 1 goto l" +
				to_string(true_label) + "\n";
			code += "\tgoto l" + to_string(false_label) + "\n";
		}
		else if (true_label != fall_label) // if false_label
			code += "\tif " + left->eeyore_name + " == 1 goto l" +
				to_string(true_label) + "\n";
		else if (false_label != fall_label)
			code += "\tif " + left->eeyore_name + " == 0 goto l" +
				to_string(false_label) + "\n";
		return;
	}
	// inner node
	if (op == OR)
	{
		auto c_left = static_cast<cond_exp_node *>(left);
		auto c_right = static_cast<cond_exp_node *>(right);

		if (true_label != fall_label)
			c_left->true_label = true_label;
		else
			c_left->true_label = stmt_node::new_label();
		c_left->false_label = fall_label;
		c_left->traverse();

		c_right->false_label = false_label;
		c_right->true_label = true_label;
		c_right->traverse();

		code += c_left->code + c_right->code;
		if (true_label == fall_label)
			code += "l" + to_string(c_left->true_label) + ":\n";
	}
	else if (op == AND)
	{
		auto c_left = static_cast<cond_exp_node *>(left);
		auto c_right = static_cast<cond_exp_node *>(right);
		c_left->true_label = fall_label;
		c_left->false_label = false_label;
		c_left->traverse();

		c_right->false_label = false_label;
		c_right->true_label = true_label;
		c_right->traverse();
		code += c_left->code + c_right->code;
		// code += "l" + to_string(c_right->true_label) + ":\n";
	}
	else
	{
		dbg_printf("should not have other operator!\n");
		throw -1;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %r14
movq 0xa8(%rdi), %rbx
testq %rbx, %rbx
je 0x9749
movl 0x90(%r14), %eax
cmpl $0xd, %eax
je 0x9821
cmpl $0xe, %eax
jne 0x9a7b
movq 0xa0(%r14), %r15
movl 0xb0(%r14), %ecx
movl 0x24cee(%rip), %eax     # 0x2e364
cmpl %eax, %ecx
jne 0x9689
movl 0x24ce0(%rip), %ecx     # 0x2e360
leal 0x1(%rcx), %edx
movl %edx, 0x24cd7(%rip)     # 0x2e360
movl %ecx, 0xb0(%r15)
movl %eax, 0xb4(%r15)
movq %r15, %rdi
callq 0x9628
movq 0xb0(%r14), %rax
movq %rax, 0xb0(%rbx)
movq %rbx, %rdi
callq 0x9628
leaq 0x18(%r15), %rsi
addq $0x18, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rdx
callq 0xc541
leaq 0x18(%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5530
leaq 0x8(%rsp), %rdi
callq 0x5548
movl 0xb0(%r14), %eax
cmpl 0x24c71(%rip), %eax     # 0x2e364
jne 0x9a6c
movl 0xb0(%r15), %esi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xc6d2
leaq 0x152f0(%rip), %rsi     # 0x1ea04
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0xc95f
leaq 0x152d3(%rip), %rdx     # 0x1e9fb
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc579
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5530
jmp 0x9a4e
movq 0xa0(%r14), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq 0xa0(%r14), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq 0xa0(%r14), %rsi
addq $0x18, %rsi
leaq 0x18(%r14), %rbx
movq %rbx, %rdi
callq 0x5530
movl 0xb0(%r14), %ecx
movl 0xb4(%r14), %eax
movl 0x24bd6(%rip), %edx     # 0x2e364
cmpl %edx, %ecx
jne 0x9895
cmpl %ecx, %eax
je 0x9a6c
movq 0xa0(%r14), %rdx
addq $0x70, %rdx
leaq 0x15472(%rip), %rsi     # 0x1ec22
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xc598
leaq 0x1546d(%rip), %rdx     # 0x1ec34
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xc579
movl 0xb4(%r14), %esi
leaq 0x68(%rsp), %rdi
callq 0xc6d2
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0xc66b
leaq 0x151dc(%rip), %rdx     # 0x1e9dc
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc579
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5530
jmp 0x991b
movq 0xa0(%r14), %r15
movl 0x24b36(%rip), %eax     # 0x2e364
movl %eax, 0xb0(%r15)
movl 0xb4(%r14), %eax
movl %eax, 0xb4(%r15)
movq %r15, %rdi
callq 0x9628
movq 0xb0(%r14), %rax
movq %rax, 0xb0(%rbx)
movq %rbx, %rdi
callq 0x9628
addq $0x18, %r15
addq $0x18, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xc541
addq $0x18, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x5530
leaq 0x8(%rsp), %rdi
jmp 0x9a67
cmpl %edx, %eax
jne 0x9950
movq 0xa0(%r14), %rdx
addq $0x70, %rdx
leaq 0x15373(%rip), %rsi     # 0x1ec22
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xc598
leaq 0x15361(%rip), %rdx     # 0x1ec27
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xc579
movl 0xb0(%r14), %esi
leaq 0x68(%rsp), %rdi
callq 0xc6d2
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0xc66b
leaq 0x150dd(%rip), %rdx     # 0x1e9dc
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc579
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5530
leaq 0x8(%rsp), %rdi
callq 0x5548
leaq 0x28(%rsp), %rdi
callq 0x5548
leaq 0x68(%rsp), %rdi
callq 0x5548
leaq 0x48(%rsp), %rdi
callq 0x5548
leaq 0x88(%rsp), %rdi
jmp 0x9a67
movq 0xa0(%r14), %rdx
addq $0x70, %rdx
leaq 0x152c0(%rip), %rsi     # 0x1ec22
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xc598
leaq 0x152ae(%rip), %rdx     # 0x1ec27
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xc579
movl 0xb0(%r14), %esi
leaq 0x68(%rsp), %rdi
callq 0xc6d2
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0xc66b
leaq 0x1502a(%rip), %rdx     # 0x1e9dc
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc579
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5530
leaq 0x8(%rsp), %rdi
callq 0x5548
leaq 0x28(%rsp), %rdi
callq 0x5548
leaq 0x68(%rsp), %rdi
callq 0x5548
leaq 0x48(%rsp), %rdi
callq 0x5548
leaq 0x88(%rsp), %rdi
callq 0x5548
movl 0xb4(%r14), %esi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0xc6d2
leaq 0x14fe0(%rip), %rsi     # 0x1e9fe
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0xc95f
leaq 0x14faa(%rip), %rdx     # 0x1e9dc
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc579
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5530
leaq 0x8(%rsp), %rdi
callq 0x5548
leaq 0x28(%rsp), %rdi
callq 0x5548
leaq 0x48(%rsp), %rdi
callq 0x5548
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
pushq $0x4
popq %rdi
callq 0x5130
orl $-0x1, (%rax)
movq 0x24503(%rip), %rsi     # 0x2df90
movq %rax, %rdi
xorl %edx, %edx
callq 0x5490
jmp 0x9afa
jmp 0x9b09
jmp 0x9b18
jmp 0x9aa1
jmp 0x9aa1
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5548
jmp 0x9ab7
jmp 0x9ab4
jmp 0x9ab4
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5548
jmp 0x9aca
jmp 0x9ac7
jmp 0x9ac7
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5548
jmp 0x9add
jmp 0x9ada
jmp 0x9ada
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5548
jmp 0x9af0
jmp 0x9aed
jmp 0x9aed
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x9b2c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5548
jmp 0x9b0c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5548
jmp 0x9b1b
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x9b2c
jmp 0x9b24
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5548
movq %rbx, %rdi
callq 0x54c0
nop