// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x98(%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 -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3c180
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x419bb
jmp 0x41d72
movq $0x4, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %r8
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0x1c, %esi
callq 0x385a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41a3f
jmp 0x41d72
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41a66
jmp 0x41d72
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0x35, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41a99
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x50(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x58(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41ac5
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41ae4
jmp 0x41d72
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41b0b
jmp 0x41d72
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %r8
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41b38
jmp 0x41d72
movl $0x39, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x40(%rbp), %r9
movq -0x88(%rbp), %r11
movl $0x1, %r8d
leaq -0x70(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x41db0
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41b8d
jmp 0x41d72
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl $0x51, %esi
callq 0x38490
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41bb9
jmp 0x41da6
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x70(%rbp), %r8
callq 0x41f20
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41be4
jmp 0x41d72
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x70(%rbp), %r8
callq 0x42220
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41c0f
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41c31
jmp 0x41d72
movq -0x60(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rsi
callq 0x377d0
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41c55
jmp 0x41d72
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x49c50
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41c7e
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rax
movq -0x18(%rbp), %r9
movq 0x148(%rax), %rdx
movq -0x80(%rbp), %rcx
movq -0x58(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41cb4
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41cd3
jmp 0x41d72
movq -0x98(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rsi
movl $0x14, %edi
callq 0x37800
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41cff
jmp 0x41d72
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x37d10
movq $0x0, -0x98(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41d29
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x41d45
jmp 0x41d72
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x60(%rbp), %rdx
movl $0x49, %esi
callq 0x38540
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq 0x310(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x3c2b0
movq -0x90(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x98(%rbp), %rdi
callq 0x36ee0
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
addq $0xb0, %rsp
popq %rbp
retq
nop