// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/array_string_type.c
// Function: prv_set
static void prv_set(subtilis_parser_t *p, const char *var_name,
		    const subtilis_type_t *type, size_t mem_reg, size_t loc,
		    subtilis_exp_t *e, bool check_size, subtilis_error_t *err)
{
	subtilis_ir_operand_t sizee;
	subtilis_ir_operand_t ptr;
	subtilis_ir_operand_t end_ptr;
	subtilis_ir_operand_t string_size;
	subtilis_ir_operand_t start_label;
	subtilis_ir_operand_t loop_label;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t gt_zero;
	subtilis_ir_operand_t condee;
	subtilis_exp_t *e_dup;

	start_label.label = subtilis_ir_section_new_label(p->current);
	end_label.label = subtilis_ir_section_new_label(p->current);
	loop_label.label = subtilis_ir_section_new_label(p->current);

	e = subtilis_type_if_coerce_type(p, e, &subtilis_type_string, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	sizee.reg = subtilis_reference_type_get_size(p, mem_reg, loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (check_size) {
		gt_zero.label = subtilis_ir_section_new_label(p->current);
		subtilis_ir_section_add_instr_reg(p->current,
						  SUBTILIS_OP_INSTR_JMPC, sizee,
						  gt_zero, end_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

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

	ptr.reg = subtilis_reference_get_data(p, mem_reg, loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	/*
	 * TODO: Pointer arithmetic here.
	 */

	end_ptr.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, ptr, sizee, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LT_I32, ptr, end_ptr, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  condee, loop_label, end_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	e_dup = subtilis_type_if_dup(e, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_string_type_assign_ref(p, &subtilis_type_string, ptr.reg, 0,
					e_dup, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_ADDI_I32, ptr, ptr, string_size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg(p->current, SUBTILIS_OP_INSTR_JMP,
					     start_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

cleanup:

	subtilis_exp_delete(e);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movl %r8d, 0x14(%rsp)
movq %rcx, %r13
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2d00a
movq %rax, %r15
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, %r12
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, %rbp
leaq 0x35a38(%rip), %rdx     # 0x74b88
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rcx
callq 0x379c3
cmpl $0x0, (%rbx)
je 0x3f172
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x30(%rsp)
movl 0x14(%rsp), %r13d
movq %rbp, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r12, 0x8(%rsp)
movq %r14, %rdi
movq 0x38(%rsp), %r12
movq %r12, %rsi
movq 0x40(%rsp), %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4d908
movq %rax, 0x28(%rsp)
cmpl $0x0, (%rbx)
je 0x3f1c8
movq 0x30(%rsp), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b4c3
testb %r13b, %r13b
je 0x3f210
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, %rbp
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq 0x28(%rsp), %rdx
movq %rax, %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4d29c
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq %rax, %r12
leaq 0x35958(%rip), %rdi     # 0x74b88
movq %rbx, %rsi
callq 0x35ed8
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq %rax, %rbp
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq %rax, %r15
movq 0x48(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movl $0x3b, %esi
movq %r12, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x362d2
cmpl $0x0, (%rbx)
jne 0x3f1b0
leaq 0x3588a(%rip), %rsi     # 0x74b88
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
movq %rax, %r8
movq %rbx, %r9
callq 0x4906e
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movl %ebp, %r8d
movl $0x9, %esi
movq %r12, %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movl $0x45, %esi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
callq 0x2c19f
cmpl $0x0, (%rbx)
jne 0x3f1b0
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
jmp 0x3f1b0
nop