// File: /workspace/github_c_makefile_star2_O3/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 0x2cc99
movq %rax, %r12
movq 0x48(%r14), %rdi
callq 0x2cc99
movq %rax, 0x10(%rsp)
movq 0x48(%r14), %rdi
callq 0x2cc99
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 0x2b166
leaq 0x48e3e(%rip), %rsi     # 0x73b07
leaq 0x49c48(%rip), %rdx     # 0x74918
movq %r14, %rdi
movq %rbx, %rcx
callq 0x33394
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x2acf4
cmpl $0x20, %ecx
jne 0x2ade3
movq %rbx, %rdi
callq 0x143b4
jmp 0x2ad0b
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x310df
cmpl $0x0, (%rbx)
jne 0x2ade3
leaq 0x48dfe(%rip), %rsi     # 0x73b10
leaq 0x49ab7(%rip), %rdx     # 0x747d0
movq %r14, %rdi
movq %rbx, %rcx
callq 0x33394
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x2ad3d
cmpl $0x20, %ecx
jne 0x2ade3
movq %rbx, %rdi
callq 0x143b4
jmp 0x2ad54
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x31486
cmpl $0x0, (%rbx)
jne 0x2ade3
movq 0x48(%r14), %rdi
xorl %ebp, %ebp
movl $0x2d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x2ade5
movq %rax, %rbp
movq 0x48(%r14), %rdi
movl $0x1, %ecx
movl $0x2d, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x2ade3
movq 0x48(%r14), %rdi
movl $0x26, %esi
movq %rbp, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x2ade3
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x2ade3
movq 0x48(%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
je 0x2adfe
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0x2b166
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48d0b(%rip), %rsi     # 0x73b10
leaq 0x499c4(%rip), %r9      # 0x747d0
movq %r14, %rdi
movq %r13, %rdx
movl $0x9, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x0
callq 0x1ea76
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x2ade5
movq 0x48(%r14), %rdi
movq 0x148(%rbp), %rcx
movl $0x1e, %esi
movq %r15, %rdx
movq %rbx, %r8
callq 0x2be2c
cmpl $0x0, (%rbx)
jne 0x2ade5
movq %rbp, %rdi
callq 0x2b166
movq 0x48(%r14), %rdi
movl $0x45, %esi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
callq 0x2be1f
cmpl $0x0, (%rbx)
jne 0x2ade3
movq 0x48(%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
jne 0x2ade3
leaq 0x48c71(%rip), %rsi     # 0x73b07
leaq 0x49a7b(%rip), %r9      # 0x74918
movq %r14, %rdi
movq %r13, %rdx
movl $0x9, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x0
callq 0x1ea76
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x2ade5
movq 0x48(%r14), %rdi
movq 0x148(%rbp), %rcx
movl $0x51, %esi
movq %r15, %rdx
movq %rbx, %r8
callq 0x2be2c
cmpl $0x0, (%rbx)
jne 0x2ade5
movq %rbp, %rdi
callq 0x2b166
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
jne 0x2ade3
movl %r15d, %edi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b77f
nop