// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rdi), %rax
movq %rax, 0x68(%rsp)
movq %rsi, 0x48(%rdi)
movq %rdx, %rdi
callq 0x2ca24
movq %rax, 0x68(%rbx)
cmpl $0x0, (%r15)
je 0x30849
xorl %r13d, %r13d
jmp 0x308db
movq 0x98(%r14), %rax
movq %rax, 0x38(%rsp)
movq 0xa8(%r14), %r12
movq %r14, %rdi
callq 0x2b774
movq %rax, %rbp
movq %r14, %rdi
callq 0x2b774
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x2b774
movq %rax, 0x60(%rsp)
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
pushq $0x1c
popq %rsi
movq %r12, 0x30(%rsp)
movq %r12, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2a9a4
cmpl $0x0, (%r15)
jne 0x308db
xorl %r13d, %r13d
pushq $0x4
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4acab
cmpl $0x0, (%r15)
jne 0x308db
movq %rax, %r12
xorl %r13d, %r13d
pushq $0x35
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
je 0x3090d
movq 0x68(%rbx), %rdi
callq 0x2cac8
movq 0x68(%rsp), %rax
movq %rax, 0x68(%rbx)
movq %r13, %rdi
callq 0x29d88
movq 0x70(%rsp), %rax
movq %rax, 0x48(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x43
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
movq %rbp, %rcx
movq 0x38(%rsp), %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
xorl %r13d, %r13d
pushq $0x4
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4a690
cmpl $0x0, (%r15)
jne 0x308db
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %rax, %r12
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x308db
movq %rax, %rbp
movq %r15, (%rsp)
pushq $0x39
popq %rdx
pushq $0x1
popq %rcx
leaq 0x50(%rsp), %r9
movq %rbx, %rdi
movq %r12, 0x18(%rsp)
movq %r12, %rsi
movq %rax, %r8
callq 0x310ea
cmpl $0x0, (%r15)
jne 0x30841
movq %rax, %r12
movq 0x48(%rbx), %rdi
movq 0x50(%rsp), %rdx
pushq $0x51
popq %rsi
movq %r15, %rcx
callq 0x2a981
movq %rax, 0x50(%rsp)
cmpl $0x0, (%r15)
jne 0x308fe
movq %rax, %r13
movq %rbp, 0x40(%rsp)
movq %r12, 0x10(%rsp)
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x28(%rsp)
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, %r12
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x20(%rsp)
movq 0x48(%rbx), %rdi
pushq $0x1e
popq %rsi
movq %r13, 0x58(%rsp)
movq %r13, %rdx
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x30841
movq %rax, %rbp
movq 0x48(%rbx), %rdi
pushq $0x1d
popq %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2a981
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %r8
movq 0x8(%rsp), %rcx
movq %rcx, %rdx
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x3f
popq %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq %r12, %rcx
movq 0x20(%rsp), %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
pushq $0x11
popq %rsi
movq 0x8(%rsp), %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x308db
movq %rax, %r12
movq 0x48(%rbx), %rdi
pushq $0xb
popq %rsi
pushq $0x30
popq %r8
movq %rax, %rdx
movq %rax, %rcx
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x51
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x5
popq %rsi
movq %rax, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq %rax, %r13
movq 0x48(%rbx), %rdi
pushq $0xe
popq %rsi
movabsq $0x4024000000000000, %r8 # imm = 0x4024000000000000
movq %rbp, %rdx
movq %rbp, %rcx
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x1
popq %rsi
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
movq %r13, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x45
popq %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, %r13
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, %rbp
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x18(%rsp)
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x8(%rsp)
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x20(%rsp)
movq 0x48(%rbx), %rdi
callq 0x2b774
movq %rax, 0x28(%rsp)
movq 0x48(%rbx), %rdi
pushq $0x3b
popq %rsi
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
xorl %r13d, %r13d
pushq $0x11
popq %rsi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x308db
movq %rax, %r12
movq 0x48(%rbx), %rdi
pushq $0x2d
popq %rsi
pushq $0x2e
popq %rcx
movq %rax, %rdx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movabsq $0x3fb999999999999a, %rcx # imm = 0x3FB999999999999A
movq 0x48(%rbx), %rdi
pushq $0xe
popq %rsi
movq 0x58(%rsp), %rdx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq %rax, %r13
movq 0x48(%rbx), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movabsq $0x3fb9999900000030, %rax # imm = 0x3FB9999900000030
movq 0x48(%rbx), %rdi
leaq -0x2f(%rax), %r8
pushq $0x9
popq %rsi
movq 0x10(%rsp), %rcx
movq %rcx, %rdx
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x3b
popq %rsi
movq 0x10(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x20(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movabsq $0x3fb9999900000030, %rax # imm = 0x3FB9999900000030
leaq -0x30(%rax), %r8
pushq $0x11
popq %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x41
popq %rsi
movq %r12, %rdx
movabsq $0x3fb9999900000030, %rcx # imm = 0x3FB9999900000030
movq %r15, %r8
callq 0x2a819
movq %rax, 0x18(%rsp)
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movabsq $0x3fb9999900000030, %rax # imm = 0x3FB9999900000030
leaq 0x9(%rax), %rcx
pushq $0x39
popq %rsi
movq %r12, %rdx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x24
popq %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x8(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0xb
popq %rsi
movq %r12, %rcx
movq %r12, %rdx
movabsq $0x3fb9999900000030, %r8 # imm = 0x3FB9999900000030
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x51
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x5
popq %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x30841
movq %rax, %r12
movq 0x48(%rbx), %rdi
pushq $0xe
popq %rsi
movq %r13, %rdx
movq %r13, %rcx
movabsq $0x3fb999999999999a, %r8 # imm = 0x3FB999999999999A
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x1
popq %rsi
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
movq %r12, %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
pushq $0x45
popq %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
cmpl $0x0, (%r15)
jne 0x30841
movq 0x48(%rbx), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq %r14, %rdi
movq 0x60(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2a358
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x308db
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x355c8
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x308db
movq 0x148(%r13), %rdx
pushq $0x43
popq %rsi
movq %r14, %rdi
movq 0x48(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x308db
movq %r14, %rdi
movq 0x48(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x308db
movq %r13, %rdi
callq 0x29d88
pushq $0x14
popq %rdi
movq %r15, %rsi
callq 0x2a369
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x308db
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2a5f4
cmpl $0x0, (%r15)
jne 0x30841
movq %r14, %rdi
movq 0x38(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x30841
pushq $0x49
popq %rsi
movq %r14, %rdi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
movq 0x68(%rbx), %rax
movq 0x310(%rax), %rax
movq %rax, 0x10(%r14)
jmp 0x30841