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

	if (loop->cond->type == EUNARY && loop->cond->unary_expr.type == TINTEGER) {
		if (loop->cond->unary_expr.val.i64val == 0)
			return;
		else {
			opp_compile_inifite(opp, node);
			return;
		}
	}

	unsigned int start, body, end;

	opp->cond_state.cond_type = IFWHILE_COND;

	start = opp->info.label_loc++;
	body  = opp->info.label_loc++;
	end   = opp->info.label_loc++;

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

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

	opp_compile_expr(opp, loop->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, loop->then);

	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 = start;
	OPCODE_END();

	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
movq (%rax), %rax
cmpl $0x5, (%rax)
jne 0x8b0f
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpl $0x2, 0x10(%rax)
jne 0x8b0f
movq 0x20(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x8afb
jmp 0x8d16
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x8fe0
jmp 0x8d16
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, 0x1c(%rsp)
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)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x78(%rax)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x70(%rax)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x74(%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 0x1c(%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 (%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 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)
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%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 $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 0x1c(%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 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)
addq $0x38, %rsp
retq
nopl (%rax,%rax)