// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtins_ir_rnd_real
void subtilis_builtins_ir_rnd_real(subtilis_parser_t *p,
				   subtilis_ir_section_t *current,
				   subtilis_error_t *err)
{
	subtilis_ir_section_t *old_current;
	subtilis_ir_operand_t one_label;
	subtilis_ir_operand_t zero_label;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t result;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t cond;
	subtilis_exp_t *e = NULL;

	/*
	 * This is a bit nasty.  The expression functions take a parser
	 * and not a section.  As we don't want to add to the current section
	 * here we need to temporarily replace the current section.  We should
	 * probably update the expression functions to take an explicit section.
	 */

	old_current = p->current;
	p->current = current;

	one_label.label = subtilis_ir_section_new_label(current);
	zero_label.label = subtilis_ir_section_new_label(current);
	end_label.label = current->end_label;

	result.reg = current->ret_reg;

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

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC, cond,
					  one_label, zero_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	e = subtilis_builtins_ir_rnd_1(p, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg2(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(current, SUBTILIS_OP_INSTR_JMP,
					     end_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	e = subtilis_builtins_ir_rnd_0(p, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

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

	subtilis_ir_section_add_instr_no_reg(
	    current, SUBTILIS_OP_INSTR_RET_REAL, result, err);

cleanup:

	p->current = old_current;

	subtilis_exp_delete(e);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x4, -0x48(%rbp)
movl $0x1, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x2d, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40df7
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x58(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40e23
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40e42
jmp 0x40f5b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x405e0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40e61
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %r8
movq -0x40(%rbp), %rdx
movq 0x148(%rax), %rcx
movl $0x1e, %esi
callq 0x385a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40e90
jmp 0x40f5b
movq -0x60(%rbp), %rdi
callq 0x36ee0
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movl $0x45, %esi
callq 0x38540
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40ec5
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40ee1
jmp 0x40f5b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x404a0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40efd
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %r8
movq -0x40(%rbp), %rdx
movq 0x148(%rax), %rcx
movl $0x1e, %esi
callq 0x385a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40f29
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40f45
jmp 0x40f5b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl $0x49, %esi
callq 0x38540
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x60(%rbp), %rdi
callq 0x36ee0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)