// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_rnd.c
// Function: prv_rnd_var
static subtilis_exp_t *prv_rnd_var(subtilis_parser_t *p, subtilis_exp_t *e,
				   subtilis_error_t *err)
{
	size_t reg;
	subtilis_ir_section_t *fn;
	size_t zero;
	size_t one;
	size_t cond;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t else_label;
	subtilis_ir_operand_t zero_one_label;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t result;

	zero_one_label.label = subtilis_ir_section_new_label(p->current);
	else_label.label = subtilis_ir_section_new_label(p->current);
	end_label.label = subtilis_ir_section_new_label(p->current);

	result.reg = p->current->freg_counter++;
	reg = e->exp.ir_op.reg;
	subtilis_exp_delete(e);
	e = NULL;

	fn = subtilis_builtins_ir_add_1_arg_int(p, "_rnd_int",
						&subtilis_type_integer, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		if (err->type != SUBTILIS_ERROR_ALREADY_DEFINED)
			goto cleanup;
		subtilis_error_init(err);
	} else {
		subtilis_builtins_ir_rnd_int(p, fn, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	fn = subtilis_builtins_ir_add_1_arg_int(p, "_rnd_real",
						&subtilis_type_real, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		if (err->type != SUBTILIS_ERROR_ALREADY_DEFINED)
			goto cleanup;
		subtilis_error_init(err);
	} else {
		subtilis_builtins_ir_rnd_real(p, fn, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	op1.reg = reg;
	op2.integer = 0;
	zero = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_EQI_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op2.integer = 1;
	one = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_EQI_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.reg = zero;
	op2.reg = one;
	cond = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_OR_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.reg = cond;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  op1, zero_one_label, else_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, zero_one_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_parser_call_1_arg_fn(
	    p, "_rnd_real", reg, SUBTILIS_BUILTINS_MAX,
	    SUBTILIS_IR_REG_TYPE_INTEGER, &subtilis_type_real, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg2(
	    p->current, SUBTILIS_OP_INSTR_MOVFP, result, e->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(e);
	e = NULL;

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

	subtilis_ir_section_add_label(p->current, else_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_parser_call_1_arg_fn(
	    p, "_rnd_int", reg, SUBTILIS_BUILTINS_MAX,
	    SUBTILIS_IR_REG_TYPE_INTEGER, &subtilis_type_integer, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg2(p->current,
					      SUBTILIS_OP_INSTR_MOV_I32_FP,
					      result, e->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(e);
	e = NULL;

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

	return subtilis_exp_new_real_var(result.reg, err);

cleanup:

	subtilis_exp_delete(e);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2d00a
movq %rax, %r12
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, 0x10(%rsp)
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, 0x8(%rsp)
movq 0x48(%r14), %rax
movq 0x20(%rax), %r15
leaq 0x1(%r15), %rcx
movq %rcx, 0x20(%rax)
movq 0x148(%rbp), %r13
movq %rbp, %rdi
callq 0x2b4c3
leaq 0x48ac6(%rip), %rsi     # 0x73aef
leaq 0x498c8(%rip), %rdx     # 0x748f8
movq %r14, %rdi
movq %rbx, %rcx
callq 0x33542
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x2b054
cmpl $0x20, %ecx
jne 0x2b143
movq %rbx, %rdi
callq 0x14404
jmp 0x2b06b
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x312ab
cmpl $0x0, (%rbx)
jne 0x2b143
leaq 0x48a86(%rip), %rsi     # 0x73af8
leaq 0x49737(%rip), %rdx     # 0x747b0
movq %r14, %rdi
movq %rbx, %rcx
callq 0x33542
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x2b09d
cmpl $0x20, %ecx
jne 0x2b143
movq %rbx, %rdi
callq 0x14404
jmp 0x2b0b4
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x31652
cmpl $0x0, (%rbx)
jne 0x2b143
movq 0x48(%r14), %rdi
xorl %ebp, %ebp
movl $0x2d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x2b145
movq %rax, %rbp
movq 0x48(%r14), %rdi
movl $0x1, %ecx
movl $0x2d, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x2b143
movq 0x48(%r14), %rdi
movl $0x26, %esi
movq %rbp, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x2b143
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x2b143
movq 0x48(%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
je 0x2b15e
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0x2b4c3
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48993(%rip), %rsi     # 0x73af8
leaq 0x49644(%rip), %r9      # 0x747b0
movq %r14, %rdi
movq %r13, %rdx
movl $0x9, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x0
callq 0x1e9b2
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x2b145
movq 0x48(%r14), %rdi
movq 0x148(%rbp), %rcx
movl $0x1e, %esi
movq %r15, %rdx
movq %rbx, %r8
callq 0x2c1ac
cmpl $0x0, (%rbx)
jne 0x2b145
movq %rbp, %rdi
callq 0x2b4c3
movq 0x48(%r14), %rdi
movl $0x45, %esi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0x2c19f
cmpl $0x0, (%rbx)
jne 0x2b143
movq 0x48(%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x2b143
leaq 0x488f9(%rip), %rsi     # 0x73aef
leaq 0x496fb(%rip), %r9      # 0x748f8
movq %r14, %rdi
movq %r13, %rdx
movl $0x9, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x0
callq 0x1e9b2
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x2b145
movq 0x48(%r14), %rdi
movq 0x148(%rbp), %rcx
movl $0x51, %esi
movq %r15, %rdx
movq %rbx, %r8
callq 0x2c1ac
cmpl $0x0, (%rbx)
jne 0x2b145
movq %rbp, %rdi
callq 0x2b4c3
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x2b143
movl %r15d, %edi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2baf9
nop