// File: /workspace/github_c_makefile_star2_O0/Encryptr[P]O-plus-plus/opp/compiler/compile_stmt.c
// Function: opp_compile_if
static void opp_compile_if(struct Opp_Context* opp, struct Opp_Node* node)
{
	struct Opp_Stmt_If* ifstmt = &node->if_stmt;

	bool has_else = ifstmt->other != NULL;

	if (ifstmt->cond->type == EUNARY && ifstmt->cond->unary_expr.type == TINTEGER) {
		if (ifstmt->cond->unary_expr.val.i64val == 1)
			opp_compile_stmt(opp, ifstmt->then);
		else {
			if (has_else)
				opp_compile_stmt(opp, ifstmt->other);
		}

		return;
	}

	opp->cond_state.cond_type = IFWHILE_COND;
	unsigned int end, body, other;

	end = opp->info.label_loc++;
	body = opp->info.label_loc++;
	if (has_else) 
		other = opp->info.label_loc++;
	else
		other = end;

	opp->cond_state.endloc = end;
	opp->cond_state.locs[0] = body;
	opp->cond_state.locs[1] = other;

	opp_compile_expr(opp, ifstmt->cond);

	OPCODE_START();
		OPCODE_TYPE(OPCODE_LABEL);
		opp->ir.opcodes[opp->ir.instr_idx].constant.val.imm_i32 = body;
	OPCODE_END();

	opp_compile_stmt(opp, ifstmt->then);

	if (has_else) {
		OPCODE_START();
			OPCODE_TYPE(OPCODE_JMP);
			opp->ir.opcodes[opp->ir.instr_idx].jmp.type = PURE_JMP;
			opp->ir.opcodes[opp->ir.instr_idx].jmp.loc = end;
		OPCODE_END();

		OPCODE_START();
			OPCODE_TYPE(OPCODE_LABEL);
			opp->ir.opcodes[opp->ir.instr_idx].constant.val.imm_i32 = other;
		OPCODE_END();
		opp_compile_stmt(opp, ifstmt->other);
	}

	OPCODE_START();
		OPCODE_TYPE(OPCODE_LABEL);
		opp->ir.opcodes[opp->ir.instr_idx].constant.val.imm_i32 = end;
	OPCODE_END();
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x28(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, 0x10(%rax)
setne %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpl $0x5, (%rax)
jne 0x886f
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpl $0x2, 0x10(%rax)
jne 0x886f
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpq $0x1, 0x18(%rax)
jne 0x884e
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x7e90
jmp 0x886a
testb $0x1, 0x1f(%rsp)
je 0x8868
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x7e90
jmp 0x886a
jmp 0x8aa5
movq 0x30(%rsp), %rax
movl $0x1, 0x68(%rax)
movq 0x30(%rsp), %rcx
movl 0x24(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rcx)
movl %eax, 0x18(%rsp)
movq 0x30(%rsp), %rcx
movl 0x24(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rcx)
movl %eax, 0x14(%rsp)
testb $0x1, 0x1f(%rsp)
je 0x88c0
movq 0x30(%rsp), %rcx
movl 0x24(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rcx)
movl %eax, 0x10(%rsp)
jmp 0x88c8
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x78(%rax)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x70(%rax)
movl 0x10(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x74(%rax)
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq (%rax), %rsi
callq 0x5d60
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x5600
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rcx
imulq $0x28, 0x48(%rcx), %rcx
addq %rcx, %rax
movl $0xa, (%rax)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rdx
imulq $0x28, 0x48(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x7e90
testb $0x1, 0x1f(%rsp)
je 0x8a51
movq 0x30(%rsp), %rdi
callq 0x5600
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rcx
imulq $0x28, 0x48(%rcx), %rcx
addq %rcx, %rax
movl $0x8, (%rax)
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rcx
imulq $0x28, 0x48(%rcx), %rcx
addq %rcx, %rax
movl $0x0, 0x8(%rax)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rdx
imulq $0x28, 0x48(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rdi
callq 0x5600
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rcx
imulq $0x28, 0x48(%rcx), %rcx
addq %rcx, %rax
movl $0xa, (%rax)
movl 0x10(%rsp), %ecx
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rdx
imulq $0x28, 0x48(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x7e90
movq 0x30(%rsp), %rdi
callq 0x5600
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rcx
imulq $0x28, 0x48(%rcx), %rcx
addq %rcx, %rax
movl $0xa, (%rax)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x30(%rsp), %rdx
imulq $0x28, 0x48(%rdx), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
addq $0x38, %rsp
retq
nopw (%rax,%rax)