// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtins_ir_str_to_fp
void subtilis_builtins_ir_str_to_fp(subtilis_parser_t *p,
				    subtilis_ir_section_t *current,
				    subtilis_error_t *err)
{
	subtilis_ir_section_t *old_current;
	subtilis_ir_operand_t str;
	subtilis_ir_operand_t str_data;
	subtilis_ir_operand_t str_len;
	subtilis_ir_operand_t end_str;
	subtilis_ir_operand_t ptr;
	subtilis_ir_operand_t condee;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t ret_val;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t factor;
	subtilis_ir_operand_t plus_minus_label;
	subtilis_ir_operand_t inf_label;
	subtilis_ir_operand_t finish_label;
	subtilis_symbol_table_t *old_st;
	subtilis_exp_t *e = NULL;

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

	old_st = p->local_st;
	p->local_st = subtilis_symbol_table_new(err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * Wow this is nasty.  The call to is_inf below reserves some
	 * stack space so we need to swap out the symbol table.
	 */

	str.reg = SUBTILIS_IR_REG_TEMP_START;
	end_label.label = current->end_label;
	ret_val.reg = current->ret_reg;
	plus_minus_label.label = subtilis_ir_section_new_label(current);
	inf_label.label = subtilis_ir_section_new_label(current);
	finish_label.label = subtilis_ir_section_new_label(current);

	op1.real = 0;
	subtilis_ir_section_add_instr_no_reg2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_REAL, ret_val, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	str_len.reg = subtilis_reference_type_get_size(p, str.reg, 0, err);
	;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 0;
	condee.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_GTI_I32, str_len, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC,
					  condee, plus_minus_label, end_label,
					  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	str_data.reg = subtilis_reference_get_data(p, str.reg, 0, err);
	;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	end_str.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, str_data, str_len, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = '9';
	ptr.reg = prv_find_first_stop(p, str_data, str_len, op1, true, end_str,
				      finish_label, &factor, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	factor.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOV_I32_FP, factor, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	prv_compute_whole_part(p, str_data, ptr, ret_val, factor, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_compute_fractional_part(p, end_str, ptr, ret_val, factor, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	e = subtilis_exp_new_real_var(ret_val.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC,
					  e->exp.ir_op, inf_label, end_label,
					  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	subtilis_exp_delete(e);
	e = subtilis_exp_new_int32(SUBTILIS_ERROR_CODE_NUMBER_TOO_BIG, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_generate_error(p, e, err);
	e = NULL;
	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, ret_val, err);

	current->locals = p->local_st->max_allocated;

cleanup:

	subtilis_symbol_table_delete(p->local_st);
	p->local_st = old_st;

	subtilis_exp_delete(e);
	p->current = old_current;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %r12
movq 0x68(%rdi), %rbp
movq %rsi, 0x48(%rdi)
movq %rdx, %rdi
callq 0x2e528
movq %rax, 0x68(%rbx)
cmpl $0x0, (%r15)
je 0x32636
xorl %r13d, %r13d
jmp 0x326dc
movq 0x98(%r14), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x8(%rsp)
movq 0xa8(%r14), %r12
movq %r14, %rdi
callq 0x2d00a
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0x2d00a
movq %rax, 0x30(%rsp)
movq %r14, %rdi
callq 0x2d00a
movq %rax, 0x40(%rsp)
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
movl $0x1c, %esi
movq %r12, 0x10(%rsp)
movq %r12, %rdx
movq 0x8(%rsp), %r12
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2c1ac
cmpl $0x0, (%r15)
jne 0x326dc
xorl %r13d, %r13d
movl $0x4, %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4d908
cmpl $0x0, (%r15)
jne 0x326dc
xorl %r13d, %r13d
movq %r14, %rdi
movl $0x35, %esi
movq %rax, %rdx
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
je 0x32704
movq 0x68(%rbx), %rdi
callq 0x2e5e7
movq %rbp, 0x68(%rbx)
movq %r13, %rdi
callq 0x2b4c3
movq %r12, 0x48(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x20(%rsp), %r13
movq %r13, %rcx
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0x2c0c2
cmpl $0x0, (%r15)
jne 0x3262e
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x3262e
xorl %r13d, %r13d
movl $0x4, %esi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4d29c
cmpl $0x0, (%r15)
movq 0x18(%rsp), %rcx
jne 0x326dc
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
movq %rax, %rdx
movq %r15, %r8
movq %rax, 0x20(%rsp)
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x326dc
movq %r15, (%rsp)
leaq 0x38(%rsp), %r9
movl $0x39, %edx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %rsi, %r13
movl $0x1, %ecx
movq %rax, 0x18(%rsp)
movq %rax, %r8
callq 0x32937
cmpl $0x0, (%r15)
jne 0x3262e
movq %rax, %r12
movq 0x48(%rbx), %rdi
movq 0x38(%rsp), %rdx
movl $0x51, %esi
movq %r15, %rcx
callq 0x2c189
movq %rax, 0x38(%rsp)
cmpl $0x0, (%r15)
jne 0x326f5
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r13
movq %rax, %r8
movq %r15, %r9
callq 0x329f7
cmpl $0x0, (%r15)
jne 0x32843
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %r15, %r9
callq 0x32c2f
cmpl $0x0, (%r15)
jne 0x32843
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
je 0x32850
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
jmp 0x326dc
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x2baf9
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x32846
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x375e1
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x32846
movq 0x148(%r13), %rdx
movq %r14, %rdi
movl $0x43, %esi
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0x2c0c2
cmpl $0x0, (%r15)
jne 0x32846
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x32846
movq %r13, %rdi
callq 0x2b4c3
movl $0x14, %edi
movq %r15, %rsi
callq 0x2bb29
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x32846
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2bdd4
cmpl $0x0, (%r15)
jne 0x32843
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x32843
movq %r14, %rdi
movl $0x49, %esi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2c19f
movq 0x68(%rbx), %rax
movq 0x310(%rax), %rax
movq %rax, 0x10(%r14)
jmp 0x32843