// File: 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 %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x320(%rbp)
cmpq $0x0, 0xa8(%rax)
jne 0xdbb4
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x320(%rbp), %rdi
movq 0xa0(%rdi), %rsi
addq $0x18, %rsi
addq $0x18, %rdi
callq 0x5440
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %eax
cmpl 0x64e5e(%rip), %eax     # 0x7241c
je 0xd849
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %eax
cmpl 0x64e45(%rip), %eax     # 0x7241c
je 0xd849
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rdx
addq $0x70, %rdx
leaq 0x40892(%rip), %rsi     # 0x4de88
leaq -0x88(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x12d60
movq -0x328(%rbp), %rsi
leaq 0x40876(%rip), %rdx     # 0x4de8d
leaq -0x68(%rbp), %rdi
callq 0x12d10
jmp 0xd622
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %esi
leaq -0xb8(%rbp), %rdi
callq 0x13410
jmp 0xd63d
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x13340
jmp 0xd653
leaq 0x405e6(%rip), %rdx     # 0x4dc40
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x12d10
jmp 0xd669
movq -0x320(%rbp), %rdi
addq $0x18, %rdi
leaq -0x28(%rbp), %rsi
callq 0x5440
jmp 0xd67f
leaq -0x28(%rbp), %rdi
callq 0x56c0
leaq -0x48(%rbp), %rdi
callq 0x56c0
leaq -0xb8(%rbp), %rdi
callq 0x56c0
leaq -0x68(%rbp), %rdi
callq 0x56c0
leaq -0x88(%rbp), %rdi
callq 0x56c0
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %esi
leaq -0x118(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x13410
movq -0x330(%rbp), %rdx
leaq 0x40582(%rip), %rsi     # 0x4dc62
leaq -0xf8(%rbp), %rdi
callq 0x14000
jmp 0xd6ee
leaq 0x4054b(%rip), %rdx     # 0x4dc40
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x12d10
jmp 0xd70a
movq -0x320(%rbp), %rdi
addq $0x18, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5440
jmp 0xd723
leaq -0xd8(%rbp), %rdi
callq 0x56c0
leaq -0xf8(%rbp), %rdi
callq 0x56c0
leaq -0x118(%rbp), %rdi
callq 0x56c0
jmp 0xdbaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd7d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd7cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd7c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd7b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x56c0
leaq -0x48(%rbp), %rdi
callq 0x56c0
leaq -0xb8(%rbp), %rdi
callq 0x56c0
leaq -0x68(%rbp), %rdi
callq 0x56c0
leaq -0x88(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd838
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd82c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x56c0
leaq -0xf8(%rbp), %rdi
callq 0x56c0
leaq -0x118(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %eax
cmpl 0x64bc0(%rip), %eax     # 0x7241c
je 0xd9fa
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rdx
addq $0x70, %rdx
leaq 0x4060d(%rip), %rsi     # 0x4de88
leaq -0x198(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x12d60
movq -0x338(%rbp), %rsi
leaq 0x405f1(%rip), %rdx     # 0x4de8d
leaq -0x178(%rbp), %rdi
callq 0x12d10
jmp 0xd8aa
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %esi
leaq -0x1b8(%rbp), %rdi
callq 0x13410
jmp 0xd8c5
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
leaq -0x1b8(%rbp), %rdx
callq 0x13340
jmp 0xd8e1
leaq 0x40358(%rip), %rdx     # 0x4dc40
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x12d10
jmp 0xd8fd
movq -0x320(%rbp), %rdi
addq $0x18, %rdi
leaq -0x138(%rbp), %rsi
callq 0x5440
jmp 0xd916
leaq -0x138(%rbp), %rdi
callq 0x56c0
leaq -0x158(%rbp), %rdi
callq 0x56c0
leaq -0x1b8(%rbp), %rdi
callq 0x56c0
leaq -0x178(%rbp), %rdi
callq 0x56c0
leaq -0x198(%rbp), %rdi
callq 0x56c0
jmp 0xdbad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd9e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd9dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd9d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xd9c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x56c0
leaq -0x158(%rbp), %rdi
callq 0x56c0
leaq -0x1b8(%rbp), %rdi
callq 0x56c0
leaq -0x178(%rbp), %rdi
callq 0x56c0
leaq -0x198(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %eax
cmpl 0x64a0f(%rip), %eax     # 0x7241c
je 0xdbab
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rdx
addq $0x70, %rdx
leaq 0x4045c(%rip), %rsi     # 0x4de88
leaq -0x238(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x12d60
movq -0x340(%rbp), %rsi
leaq 0x4044d(%rip), %rdx     # 0x4de9a
leaq -0x218(%rbp), %rdi
callq 0x12d10
jmp 0xda5b
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %esi
leaq -0x258(%rbp), %rdi
callq 0x13410
jmp 0xda76
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
leaq -0x258(%rbp), %rdx
callq 0x13340
jmp 0xda92
leaq 0x401a7(%rip), %rdx     # 0x4dc40
leaq -0x1d8(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x12d10
jmp 0xdaae
movq -0x320(%rbp), %rdi
addq $0x18, %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x5440
jmp 0xdac7
leaq -0x1d8(%rbp), %rdi
callq 0x56c0
leaq -0x1f8(%rbp), %rdi
callq 0x56c0
leaq -0x258(%rbp), %rdi
callq 0x56c0
leaq -0x218(%rbp), %rdi
callq 0x56c0
leaq -0x238(%rbp), %rdi
callq 0x56c0
jmp 0xdbab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xdb76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x56c0
leaq -0x1f8(%rbp), %rdi
callq 0x56c0
leaq -0x258(%rbp), %rdi
callq 0x56c0
leaq -0x218(%rbp), %rdi
callq 0x56c0
leaq -0x238(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
jmp 0xdbad
jmp 0xdbaf
jmp 0xdf44
movq -0x320(%rbp), %rax
cmpl $0xe, 0x90(%rax)
jne 0xde0d
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rcx
movq %rcx, -0x260(%rbp)
movq 0xa8(%rax), %rcx
movq %rcx, -0x268(%rbp)
movl 0xb0(%rax), %eax
cmpl 0x64825(%rip), %eax     # 0x7241c
je 0xdc15
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %ecx
movq -0x260(%rbp), %rax
movl %ecx, 0xb0(%rax)
jmp 0xdc29
callq 0xcef0
movl %eax, %ecx
movq -0x260(%rbp), %rax
movl %ecx, 0xb0(%rax)
movl 0x647ed(%rip), %ecx     # 0x7241c
movq -0x260(%rbp), %rax
movl %ecx, 0xb4(%rax)
movq -0x260(%rbp), %rdi
callq 0xd540
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %edx
movq -0x268(%rbp), %rcx
movl %edx, 0xb4(%rcx)
movl 0xb0(%rax), %ecx
movq -0x268(%rbp), %rax
movl %ecx, 0xb0(%rax)
movq -0x268(%rbp), %rdi
callq 0xd540
movq -0x260(%rbp), %rsi
addq $0x18, %rsi
movq -0x268(%rbp), %rdx
addq $0x18, %rdx
leaq -0x288(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x12c30
movq -0x320(%rbp), %rdi
movq -0x348(%rbp), %rsi
addq $0x18, %rdi
callq 0x5440
jmp 0xdcc3
leaq -0x288(%rbp), %rdi
callq 0x56c0
movq -0x320(%rbp), %rax
movl 0xb0(%rax), %eax
cmpl 0x6473a(%rip), %eax     # 0x7241c
jne 0xde08
movq -0x260(%rbp), %rax
movl 0xb0(%rax), %esi
leaq -0x2e8(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x13410
movq -0x350(%rbp), %rdx
leaq 0x3ff52(%rip), %rsi     # 0x4dc68
leaq -0x2c8(%rbp), %rdi
callq 0x14000
jmp 0xdd24
leaq 0x3ff34(%rip), %rdx     # 0x4dc5f
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x12d10
jmp 0xdd40
movq -0x320(%rbp), %rdi
addq $0x18, %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x5440
jmp 0xdd59
leaq -0x2a8(%rbp), %rdi
callq 0x56c0
leaq -0x2c8(%rbp), %rdi
callq 0x56c0
leaq -0x2e8(%rbp), %rdi
callq 0x56c0
jmp 0xde08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xddf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xddeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x56c0
leaq -0x2c8(%rbp), %rdi
callq 0x56c0
leaq -0x2e8(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
jmp 0xdf44
movq -0x320(%rbp), %rax
cmpl $0xd, 0x90(%rax)
jne 0xdf1f
movq -0x320(%rbp), %rax
movq 0xa0(%rax), %rcx
movq %rcx, -0x2f0(%rbp)
movq 0xa8(%rax), %rcx
movq %rcx, -0x2f8(%rbp)
movl 0x645d2(%rip), %edx     # 0x7241c
movq -0x2f0(%rbp), %rcx
movl %edx, 0xb0(%rcx)
movl 0xb4(%rax), %ecx
movq -0x2f0(%rbp), %rax
movl %ecx, 0xb4(%rax)
movq -0x2f0(%rbp), %rdi
callq 0xd540
movq -0x320(%rbp), %rax
movl 0xb4(%rax), %edx
movq -0x2f8(%rbp), %rcx
movl %edx, 0xb4(%rcx)
movl 0xb0(%rax), %ecx
movq -0x2f8(%rbp), %rax
movl %ecx, 0xb0(%rax)
movq -0x2f8(%rbp), %rdi
callq 0xd540
movq -0x2f0(%rbp), %rsi
addq $0x18, %rsi
movq -0x2f8(%rbp), %rdx
addq $0x18, %rdx
leaq -0x318(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x12c30
movq -0x320(%rbp), %rdi
movq -0x358(%rbp), %rsi
addq $0x18, %rdi
callq 0x5440
jmp 0xdef1
leaq -0x318(%rbp), %rdi
callq 0x56c0
jmp 0xdf42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x56c0
jmp 0xdf4d
movl $0x4, %edi
callq 0x51a0
movq %rax, %rdi
movl $0xffffffff, (%rdi)     # imm = 0xFFFFFFFF
movq 0x64057(%rip), %rsi     # 0x71f90
xorl %eax, %eax
movl %eax, %edx
callq 0x55d0
jmp 0xdf44
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x5610
nopl (%rax)