// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtins_ir_inkey
void subtilis_builtins_ir_inkey(subtilis_ir_section_t *current,
				subtilis_error_t *err)
{
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t cond;
	subtilis_ir_operand_t true_label;
	subtilis_ir_operand_t false_label;
	subtilis_ir_operand_t end_label;

	op0.reg = current->reg_counter++;

	op1.reg = SUBTILIS_IR_REG_TEMP_START;
	op2.integer = 0;
	cond.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_GTEI_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	true_label.reg = subtilis_ir_section_new_label(current);
	false_label.reg = subtilis_ir_section_new_label(current);
	end_label.reg = subtilis_ir_section_new_label(current);

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC, cond,
					  true_label, false_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(current, true_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg2(current, SUBTILIS_OP_INSTR_GET_TO,
					      op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(current, SUBTILIS_OP_INSTR_JMP,
					     end_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(current, false_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = -256;
	cond.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_EQI_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	true_label.reg = subtilis_ir_section_new_label(current);
	false_label.reg = subtilis_ir_section_new_label(current);
	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC, cond,
					  true_label, false_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(current, true_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(
	    current, SUBTILIS_OP_INSTR_OS_BYTE_ID, op0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(current, SUBTILIS_OP_INSTR_JMP,
					     end_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(current, false_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg2(current, SUBTILIS_OP_INSTR_INKEY,
					      op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(current, end_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(current, SUBTILIS_OP_INSTR_RET_I32,
					     op0, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
movq 0x18(%rdi), %r14
leaq 0x1(%r14), %rax
movq %rax, 0x18(%rdi)
pushq $0x41
popq %rsi
pushq $0x4
popq %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x2f151
movq %rax, %r12
movq %r15, %rdi
callq 0x2b774
movq %rax, %rbp
movq %r15, %rdi
callq 0x2b774
movq %rax, %r13
movq %r15, %rdi
callq 0x2b774
movq %rax, (%rsp)
pushq $0x43
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x2f151
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x6d
popq %rsi
pushq $0x4
popq %rcx
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %r8
callq 0x2a9a4
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x45
popq %rsi
movq %r15, %rdi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x2f151
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x2d
popq %rsi
pushq $0x4
popq %rdx
movl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movq %r15, %rdi
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x2f151
movq %rax, %rbp
movq %r15, %rdi
callq 0x2b774
movq %rax, %r12
movq %r15, %rdi
callq 0x2b774
movq %rax, %r13
pushq $0x43
popq %rsi
movq %r15, %rdi
movq %rbp, %rdx
movq %r12, %rcx
movq %rax, %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x2f151
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x6f
popq %rsi
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x45
popq %rsi
movq %r15, %rdi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x2f151
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x2f151
pushq $0x6e
popq %rsi
pushq $0x4
popq %rcx
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %r8
callq 0x2a9a4
cmpl $0x0, (%rbx)
jne 0x2f151
movq %r15, %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
je 0x2f160
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x47
popq %rsi
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a997