// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: prv_builtins_ir_hex_to_str
static void prv_builtins_ir_hex_to_str(subtilis_parser_t *p,
				       subtilis_ir_section_t *current,
				       subtilis_error_t *err)
{
	subtilis_ir_operand_t arg_int;
	subtilis_ir_operand_t arg_buf;
	subtilis_ir_operand_t arg_buf_copy;
	subtilis_ir_operand_t shift;
	subtilis_ir_operand_t count;
	subtilis_ir_operand_t chr;
	subtilis_ir_operand_t nibble;
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t have_written;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t main_loop_label;
	subtilis_ir_operand_t not_zero_label;
	subtilis_ir_operand_t all_zero_label;
	subtilis_ir_operand_t not_all_zero_label;
	subtilis_ir_operand_t zero_label;
	subtilis_ir_section_t *old_current;

	/*
	 * 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;

	end_label.label = current->end_label;

	all_zero_label.label = subtilis_ir_section_new_label(current);
	not_all_zero_label.label = subtilis_ir_section_new_label(current);
	main_loop_label.label = subtilis_ir_section_new_label(current);
	zero_label.label = subtilis_ir_section_new_label(current);
	not_zero_label.label = subtilis_ir_section_new_label(current);

	count.reg = current->ret_reg;

	arg_int.reg = SUBTILIS_IR_REG_TEMP_START;
	arg_buf.reg = SUBTILIS_IR_REG_TEMP_START + 1;

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC,
					  arg_int, not_all_zero_label,
					  all_zero_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	op2.integer = '0';
	chr.reg = subtilis_ir_section_add_instr2(
	    current, SUBTILIS_OP_INSTR_MOVI_I32, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op2.integer = 0;
	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_STOREO_I8,
					  chr, arg_buf, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 1;
	subtilis_ir_section_add_instr_no_reg(
	    current, SUBTILIS_OP_INSTR_RETI_I32, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	arg_buf_copy.reg = subtilis_ir_section_add_instr2(
	    current, SUBTILIS_OP_INSTR_MOV, arg_buf, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 32;
	shift.reg = subtilis_ir_section_add_instr2(
	    current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	op2.integer = 4;
	op0.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_SUBI_I32, shift, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg2(current, SUBTILIS_OP_INSTR_MOV,
					      shift, op0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op0.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_LSR_I32, arg_int, shift, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 15;
	nibble.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_ANDI_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	have_written.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_GT_I32, arg_buf, arg_buf_copy, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op0.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_OR_I32, nibble, have_written, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

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

	op2.integer = '0';
	chr.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_ADDI_I32, nibble, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 10;
	op0.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_GTEI_I32, nibble, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = ('0' - 'A') + 10;
	op0.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_MULI_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	chr.reg = subtilis_ir_section_add_instr(
	    current, SUBTILIS_OP_INSTR_ADD_I32, op0, chr, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op2.integer = 0;
	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_STOREO_I8,
					  chr, arg_buf, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.integer = 1;
	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_ADDI_I32,
					  arg_buf, arg_buf, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	subtilis_ir_section_add_instr_reg(current, SUBTILIS_OP_INSTR_JMPC,
					  shift, main_loop_label, end_label,
					  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_reg(current, SUBTILIS_OP_INSTR_SUB_I32,
					  count, arg_buf, arg_buf_copy, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg(current, SUBTILIS_OP_INSTR_RET_I32,
					     count, err);

cleanup:

	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 -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x39940
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x4, -0x20(%rbp)
movq $0x5, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x439df
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43a01
jmp 0x43e5a
movl $0x30, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43a30
jmp 0x43e5a
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x68(%rbp), %r8
movl $0x16, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43a63
jmp 0x43e5a
movl $0x1, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x60(%rbp), %rdx
movl $0x48, %esi
callq 0x38540
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43a8e
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43ab0
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rdx
movl $0x1d, %esi
callq 0x38490
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43ad8
jmp 0x43e5a
movl $0x20, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x60(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43b07
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43b26
jmp 0x43e5a
movl $0x4, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0xb, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43b59
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x38(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl $0x1d, %esi
callq 0x385a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43b81
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x4d, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43bad
jmp 0x43e5a
movl $0xf, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x25, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43be0
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x33, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43c0c
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x70(%rbp), %rcx
movl $0x26, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43c38
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x58(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0xa0(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43c6a
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43c8c
jmp 0x43e5a
movl $0x30, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0x9, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43cbf
jmp 0x43e5a
movl $0xa, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x41, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43cf2
jmp 0x43e5a
movl $0xfffffff9, -0x60(%rbp) # imm = 0xFFFFFFF9
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0xd, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43d25
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43d4e
jmp 0x43e5a
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x68(%rbp), %r8
movl $0x16, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43d81
jmp 0x43e5a
movl $0x1, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %r8
movl $0x9, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43db4
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43dd6
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x38(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x78(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43dff
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43e1b
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl $0x2, %esi
callq 0x38360
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x43e44
jmp 0x43e5a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl $0x47, %esi
callq 0x38540
movq -0xa8(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)