// File: /workspace/github_c_makefile_star2_O0/Yamsman[P]scc/src/gen.c
// Function: gen_stmt_if
void gen_stmt_if(asm_f *f, ast_n *n) {
	//Jump to end if not true
	char *lbl_end = gen_numlabel(f);
	gen_expr(f, n->dat.stmt.expr);
	asmf_add_inst(f, mk_inst(INST_TEST, 2,
		mk_oprd(OPRD_REG, RAX),
		mk_oprd(OPRD_REG, RAX)
	));
	asmf_add_inst(f, mk_inst(INST_JZ, 1, mk_oprd_label(lbl_end)));

	//Generate if body
	if (n->dat.stmt.body != NULL)
		gen_stmt(f, n->dat.stmt.body);

	//Generate else body
	if (n->dat.stmt.else_body != NULL) {
		//The main if will jump to here if the expression was false
		//Otherwise, jump past the else block
		char *lbl_else_end = gen_numlabel(f);
		asmf_add_inst(f, mk_inst(INST_JMP, 1,
			mk_oprd_label(lbl_else_end)
		));
		asmf_add_inst(f, mk_label(lbl_end));
		lbl_end = lbl_else_end;

		gen_stmt(f, n->dat.stmt.else_body);
	}
	asmf_add_inst(f, mk_label(lbl_end));
	
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x43f0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x4920
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x63c0
leaq -0x58(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x63c0
movl $0x3d, %edi
movl $0x2, %esi
leaq -0x38(%rbp), %rcx
leaq -0x58(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movb $0x0, %al
callq 0x6460
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x6420
movl $0x39, %edi
movl $0x1, %esi
leaq -0x78(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x6460
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x588d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x5540
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x5949
movq -0x8(%rbp), %rdi
callq 0x43f0
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x80(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x6420
movl $0x45, %edi
movl $0x1, %esi
leaq -0xa0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x6460
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x65a0
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x80(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x5540
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x65a0
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)