// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_append_scalar_array
void subtilis_array_append_scalar_array(subtilis_parser_t *p,
					subtilis_exp_t *a1, subtilis_exp_t *a2,
					subtilis_error_t *err)
{
	subtilis_type_t el_type;
	subtilis_ir_operand_t el_size;
	size_t dest_reg;
	subtilis_ir_operand_t a1_size;
	subtilis_ir_operand_t a2_size;
	subtilis_ir_operand_t a2_size_zero;
	subtilis_ir_operand_t a2_size_gt_zero;
	subtilis_ir_operand_t a2_data;
	subtilis_ir_operand_t op1;
	bool a2_dynamic;
	subtilis_exp_t *e;

	a2_size_zero.label = SIZE_MAX;
	el_type.type = SUBTILIS_TYPE_VOID;

	if (!subtilis_type_if_is_vector(&a1->type)) {
		subtilis_error_set_expected(err, "vector",
					    subtilis_type_name(&a1->type),
					    p->l->stream->name, p->l->line);
		goto cleanup;
	}

	subtilis_type_if_element_type(p, &a1->type, &el_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_check_arrays_compat(p, &el_type, a1, a2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	el_size.integer = subtilis_type_if_size(&el_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a2_size.reg =
	    subtilis_reference_type_get_size(p, a2->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a2_dynamic = subtilis_type_if_is_vector(&a2->type);
	if (a2_dynamic) {
		a2_size_zero.label = subtilis_ir_section_new_label(p->current);
		a2_size_gt_zero.label =
		    subtilis_ir_section_new_label(p->current);

		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_JMPC, a2_size,
		    a2_size_gt_zero, a2_size_zero, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

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

	a1_size.reg =
	    subtilis_reference_type_get_size(p, a1->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_builtin_ir_call_ref_grow(p, a1->exp.ir_op.reg, a1_size.reg,
					      a2_size.reg, a2_size.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	dest_reg = e->exp.ir_op.reg;
	subtilis_exp_delete(e);

	a2_data.reg = subtilis_reference_get_data(p, a2->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_reference_type_memcpy_dest(p, dest_reg, a2_data.reg,
					    a2_size.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(a2);
	a2 = subtilis_type_if_load_from_mem(p, &subtilis_type_integer,
					    a1->exp.ir_op.reg,
					    SUBTIILIS_ARRAY_DIMS_OFF, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (el_size.integer > 1) {
		op1.reg =
		    prv_div_by_const(p, a2_size.reg, el_size.integer, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else {
		op1.reg = a2_size.reg;
	}

	a2->exp.ir_op.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, a2->exp.ir_op, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_type_if_assign_to_mem(p, a1->exp.ir_op.reg,
				       SUBTIILIS_ARRAY_DIMS_OFF, a2, err);
	a2 = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (a2_dynamic)
		subtilis_ir_section_add_label(p->current, a2_size_zero.label,
					      err);

cleanup:
	subtilis_type_free(&el_type);
	subtilis_exp_delete(a2);
	subtilis_exp_delete(a1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $-0x1, -0x190(%rbp)
movl $0x8, -0x168(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4a040
testb $0x1, %al
jne 0x6130a
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3e190
movq -0x1c0(%rbp), %rdi
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x4b6c7(%rip), %rdx     # 0xac9b4
leaq 0x4b689(%rip), %rax     # 0xac97d
movq %rax, (%rsp)
movl $0xb62, 0x8(%rsp)       # imm = 0xB62
callq 0x156d0
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq -0x168(%rbp), %rdx
callq 0x47b70
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61330
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x168(%rbp), %rsi
callq 0x61690
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6135a
jmp 0x61667
movq -0x20(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x47420
movl %eax, -0x170(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6137e
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x188(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x613af
jmp 0x61667
movq -0x18(%rbp), %rdi
callq 0x4a040
andb $0x1, %al
movb %al, -0x1a9(%rbp)
testb $0x1, -0x1a9(%rbp)
je 0x61456
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x190(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x198(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %r9
movq -0x188(%rbp), %rdx
movq -0x198(%rbp), %rcx
movq -0x190(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6142e
jmp 0x61667
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x198(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39960
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61454
jmp 0x61667
jmp 0x61456
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x180(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61487
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x180(%rbp), %rdx
movq -0x188(%rbp), %rcx
movq -0x188(%rbp), %r8
movq -0x20(%rbp), %r9
callq 0x42ca0
movq %rax, -0x1b8(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x614c9
jmp 0x61667
movq -0x1b8(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x178(%rbp)
movq -0x1b8(%rbp), %rdi
callq 0x36ee0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x1a0(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6151b
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x178(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
movq -0x188(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0x6dad0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6154b
jmp 0x61667
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rdx
movq -0x20(%rbp), %r8
leaq 0x4a362(%rip), %rsi     # 0xab8d0
movl $0x10, %ecx
callq 0x48080
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6158a
jmp 0x61667
cmpl $0x1, -0x170(%rbp)
jle 0x615c4
movq -0x8(%rbp), %rdi
movq -0x188(%rbp), %rsi
movl -0x170(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x61780
movq %rax, -0x1a8(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x615c2
jmp 0x61667
jmp 0x615d2
movq -0x188(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x1a8(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x148(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61610
jmp 0x61667
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x10, %edx
callq 0x47f20
movq $0x0, -0x18(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61644
jmp 0x61667
testb $0x1, -0x1a9(%rbp)
je 0x61665
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x190(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39960
jmp 0x61667
leaq -0x168(%rbp), %rdi
callq 0x3e100
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x10(%rbp), %rdi
callq 0x36ee0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nop