// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/reference_type.c
// Function: subtilis_reference_type_init_ref
void subtilis_reference_type_init_ref(subtilis_parser_t *p, size_t dest_mem_reg,
				      size_t dest_loc, size_t source_reg,
				      bool check_size, bool ref,
				      subtilis_error_t *err)
{
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t copy;
	subtilis_ir_operand_t zero;
	subtilis_ir_operand_t gtzero;

	zero.label = SIZE_MAX;
	op0.reg = source_reg;

	op1.integer = SUBTIILIS_REFERENCE_SIZE_OFF;
	copy.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_mem_reg;
	op2.integer = dest_loc + SUBTIILIS_REFERENCE_SIZE_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, copy, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (check_size) {
		zero.label = subtilis_ir_section_new_label(p->current);
		gtzero.label = subtilis_ir_section_new_label(p->current);
		subtilis_ir_section_add_instr_reg(p->current,
						  SUBTILIS_OP_INSTR_JMPC, copy,
						  gtzero, zero, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
		subtilis_ir_section_add_label(p->current, gtzero.label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	op1.integer = SUBTIILIS_REFERENCE_DATA_OFF;
	copy.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_mem_reg;
	op2.integer = dest_loc + SUBTIILIS_REFERENCE_DATA_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, copy, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = SUBTIILIS_REFERENCE_HEAP_OFF;
	copy.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (ref) {
		subtilis_ir_section_add_instr_no_reg(
		    p->current, SUBTILIS_OP_INSTR_REF, copy, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	op1.reg = dest_mem_reg;
	op2.integer = dest_loc + SUBTIILIS_REFERENCE_HEAP_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, copy, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.integer = SUBTIILIS_REFERENCE_ORIG_SIZE_OFF;
	copy.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_mem_reg;
	op2.integer = dest_loc + SUBTIILIS_REFERENCE_ORIG_SIZE_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, copy, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (check_size)
		subtilis_ir_section_add_label(p->current, zero.label, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, 0x10(%rsp)
movl %r8d, 0x4(%rsp)
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0x50(%rsp), %rbx
movq 0x48(%rdi), %rdi
movl $0x12, %esi
movq %rcx, %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4ce76
movq %rax, %rbp
movq 0x48(%r14), %rdi
movl %r15d, %r8d
movl $0x17, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
je 0x4ce85
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $-0x1, %rax
cmpb $0x0, 0x4(%rsp)
je 0x4cee7
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, 0x8(%rsp)
movq 0x48(%r14), %rdi
callq 0x2d00a
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rbp, %rdx
movq %rax, %rbp
movq %rax, %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4ce76
movq 0x48(%r14), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x4ce76
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %r12, %rcx
movq 0x48(%r14), %rdi
movq %rcx, %rbp
orq $0x4, %rcx
movl $0x12, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4ce76
leal 0x4(%r15), %r8d
movq 0x48(%r14), %rdi
movl $0x17, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4ce76
movq 0x48(%r14), %rdi
movq %rbp, %rcx
orq $0x8, %rcx
movl $0x12, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4ce76
cmpb $0x0, 0x10(%rsp)
je 0x4cf93
movq 0x48(%r14), %rdi
movl $0x78, %esi
movq %rax, %rdx
movq %rbx, %rcx
movq %rax, 0x10(%rsp)
callq 0x2c19f
movq 0x10(%rsp), %rax
cmpl $0x0, (%rbx)
jne 0x4ce76
leal 0x8(%r15), %r8d
movq 0x48(%r14), %rdi
movl $0x17, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4ce76
movq 0x48(%r14), %rdi
orq $0xc, %rbp
movl $0x12, %esi
movq %r13, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4ce76
addl $0xc, %r15d
movq 0x48(%r14), %rdi
movl $0x17, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
setne %al
movl 0x4(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x4ce76
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d017