// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/collection.c
// Function: subtilis_collection_copy_scalar
void subtilis_collection_copy_scalar(subtilis_parser_t *p, subtilis_exp_t *obj1,
				     subtilis_exp_t *obj2, bool cow,
				     subtilis_error_t *err)
{
	subtilis_ir_operand_t size1;
	subtilis_ir_operand_t size2;
	subtilis_ir_operand_t skip_label;
	subtilis_ir_operand_t no_skip_label;
	subtilis_ir_operand_t condee;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t final_size;
	size_t ptr1;
	size_t ptr2;
	size_t buf_size;

	skip_label.label = subtilis_ir_section_new_label(p->current);
	no_skip_label.label = subtilis_ir_section_new_label(p->current);

	if (obj2->type.type == SUBTILIS_TYPE_CONST_STRING) {
		buf_size = subtilis_buffer_get_size(&obj2->exp.str);
		if (buf_size < 2)
			goto cleanup;
		buf_size--;
		ptr2 = subtilis_string_type_lca_const(
		    p, subtilis_buffer_get_string(&obj2->exp.str), buf_size,
		    err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		op1.integer = buf_size;
		size2.reg = subtilis_ir_section_add_instr2(
		    p->current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
	} else if (subtilis_type_if_is_scalar_ref(&obj2->type, err)) {
		size2.reg = subtilis_reference_type_get_size(
		    p, obj2->exp.ir_op.reg, 0, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		ptr2 =
		    subtilis_reference_get_data(p, obj2->exp.ir_op.reg, 0, err);
	} else if ((obj2->type.type == SUBTILIS_TYPE_REC) &&
		   subtilis_type_rec_is_scalar(&obj2->type)) {
		op1.integer = subtilis_type_rec_size(&obj2->type);
		size2.reg = subtilis_ir_section_add_instr2(
		    p->current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
		ptr2 = obj2->exp.ir_op.reg;
	} else {
		if (err->type == SUBTILIS_ERROR_OK)
			subtilis_error_set_expected(
			    err,
			    "string, constant string or array of numeric types "
			    "or scalar RECS",
			    subtilis_type_name(&obj2->type), p->l->stream->name,
			    p->l->line);
		goto cleanup;
	}
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LTE_I32, size1, size2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	final_size.reg = p->current->reg_counter++;
	subtilis_ir_section_add_instr4(p->current, SUBTILIS_OP_INSTR_CMOV_I32,
				       final_size, condee, size1, size2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  final_size, no_skip_label, skip_label,
					  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	if (cow)
		ptr1 = subtilis_reference_type_copy_on_write(
		    p, obj1->exp.ir_op.reg, 0, size1.reg, err);
	else
		ptr1 =
		    subtilis_reference_get_data(p, obj1->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_reference_type_memcpy_dest(p, ptr1, ptr2, final_size.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, skip_label.label, err);

cleanup:

	subtilis_exp_delete(obj2);
	subtilis_exp_delete(obj1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x6f685
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x16270
movq %rax, -0x78(%rbp)
cmpq $0x2, -0x78(%rbp)
jae 0x6f611
jmp 0x6f94a
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x16760
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq -0x78(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x65d80
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f65b
jmp 0x6f94a
movq -0x78(%rbp), %rax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rcx
movq -0x58(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x38(%rbp)
jmp 0x6f7a8
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4a0f0
testb $0x1, %al
jne 0x6f698
jmp 0x6f6eb
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f6c6
jmp 0x6f94a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x70(%rbp)
jmp 0x6f7a6
movq -0x18(%rbp), %rax
cmpl $0x16, (%rax)
jne 0x6f73e
movq -0x18(%rbp), %rdi
callq 0x3f160
testb $0x1, %al
jne 0x6f703
jmp 0x6f73e
movq -0x18(%rbp), %rdi
callq 0x3f0d0
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rcx
movq -0x58(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x6f7a4
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x6f79f
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3e190
movq -0x88(%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 0x3d31d(%rip), %rdx     # 0xacaa4
leaq 0x3d357(%rip), %rax     # 0xacae5
movq %rax, (%rsp)
movl $0x4b, 0x8(%rsp)
callq 0x156d0
jmp 0x6f94a
jmp 0x6f7a6
jmp 0x6f7a8
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f7b6
jmp 0x6f94a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f7e4
jmp 0x6f94a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x37, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f814
jmp 0x6f94a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movl $0x8a, %esi
movq %rax, (%rsp)
callq 0x386c0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f867
jmp 0x6f94a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r9
movq -0x60(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f897
jmp 0x6f94a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x39960
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f8ba
jmp 0x6f94a
testb $0x1, -0x19(%rbp)
je 0x6f8e6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %edx
callq 0x6e000
movq %rax, -0x68(%rbp)
jmp 0x6f906
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f911
jmp 0x6f94a
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x6dad0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f935
jmp 0x6f94a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x39960
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x10(%rbp), %rdi
callq 0x36ee0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)