// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: prv_compute_whole_hex_part
static void prv_compute_whole_hex_part(subtilis_parser_t *p,
				       subtilis_ir_operand_t str_data,
				       subtilis_ir_operand_t base,
				       subtilis_ir_operand_t ptr,
				       subtilis_ir_operand_t ret_val,
				       subtilis_ir_operand_t overflow_label,
				       subtilis_ir_operand_t end_label,
				       subtilis_ir_operand_t factor,
				       subtilis_error_t *err)
/* clang-format off */

{
	subtilis_ir_operand_t sign;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t condee;
	subtilis_ir_operand_t byte;
	subtilis_ir_operand_t ored_byte;
	subtilis_ir_operand_t product;
	subtilis_ir_operand_t new_ptr;
	subtilis_ir_operand_t overflow;
	subtilis_ir_operand_t whole_start_label;
	subtilis_ir_operand_t process_whole_label;
	subtilis_ir_operand_t hex_digit_label;
	subtilis_ir_operand_t skip_dec_label;
	subtilis_ir_operand_t dec_digit_label;
	subtilis_ir_operand_t check_overflow_label;

	whole_start_label.label = subtilis_ir_section_new_label(p->current);
	process_whole_label.label = subtilis_ir_section_new_label(p->current);
	hex_digit_label.label = subtilis_ir_section_new_label(p->current);
	dec_digit_label.label = subtilis_ir_section_new_label(p->current);
	skip_dec_label.label = subtilis_ir_section_new_label(p->current);
	check_overflow_label.label = subtilis_ir_section_new_label(p->current);

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

	new_ptr.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOV, ptr, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, whole_start_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 1;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_SUBI_I32, new_ptr, new_ptr, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_GTE_I32, new_ptr, str_data, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  condee, process_whole_label,
					  end_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, process_whole_label.label,
				      err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 0;
	byte.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I8, new_ptr, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = '9';
	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_GTI_I32, byte, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  condee, hex_digit_label,
					  dec_digit_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, hex_digit_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 32;
	ored_byte.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ORI_I32, byte, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 'a' - 10;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_SUBI_I32, byte, ored_byte, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(p->current, SUBTILIS_OP_INSTR_JMP,
					     skip_dec_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, dec_digit_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = '0';
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_SUBI_I32, byte, byte, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, skip_dec_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	product.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_MUL_I32, byte, factor, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 4;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_LSLI_I32, factor, factor, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_ADD_I32,
					  ret_val, ret_val, product, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  ret_val, check_overflow_label,
					  whole_start_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, check_overflow_label.label,
				      err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * Now check for overflow.  We EOR the sign and the sum
	 * together.  If the top bit is set we've overflowed.
	 */

	overflow.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_EOR_I32, ret_val, sign, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = 0x80000000;
	overflow.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ANDI_I32, overflow, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  overflow, overflow_label,
					  whole_start_label, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
movq 0x98(%rsp), %r14
movq 0x90(%rsp), %r12
movq 0x48(%rdi), %rdi
callq 0x2d00a
movq %rax, 0x10(%rsp)
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, %rbp
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, 0x38(%rsp)
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, 0x30(%rsp)
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, 0x28(%rsp)
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, 0x20(%rsp)
movq 0x48(%r15), %rdi
movl $0x1d, %esi
movq %r12, 0x18(%rsp)
movq %r12, %rdx
movq %r14, %rcx
callq 0x2c189
movq %rax, 0x40(%rsp)
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x1d, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2c189
cmpl $0x0, (%r14)
jne 0x35870
movq %rax, %r12
movq 0x48(%r15), %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x1, %r8d
movl $0xb, %esi
movq %r12, %rdx
movq %r12, %rcx
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x3f, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq %rbp, %rcx
movq 0x50(%rsp), %r8
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x11, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq %rax, %rbx
movq 0x48(%r15), %rdi
movl $0x39, %ecx
movl $0x35, %esi
movq %rax, %rdx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movq 0x38(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x20, %ecx
movl $0x27, %esi
movq %rbx, %rdx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x57, %r8d
movl $0xb, %esi
movq %rbx, %rdx
movq %rax, %rcx
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x45, %esi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
callq 0x2c19f
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x30, %r8d
movl $0xb, %esi
movq %rbx, %rdx
movq %rbx, %rcx
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x4, %esi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq %rax, %rbx
movq 0x48(%r15), %rdi
movl $0x4, %r8d
movl $0x4c, %esi
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rcx
movq %rcx, %rdx
movq %rbx, %r8
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x28, %esi
movq 0x8(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x35870
movq 0x48(%r15), %rdi
movl $0x80000000, %ecx       # imm = 0x80000000
movl $0x25, %esi
movq %rax, %rdx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
je 0x3587f
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x48(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %r14, %r9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c0c2