// File: /workspace/github_c_makefile_star2_O2/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 0x2b774
movq %rax, %r15
movq 0x48(%r14), %rdi
callq 0x2b774
movq %rax, %r12
movq 0x48(%r14), %rdi
callq 0x2b774
movq %rax, %rbp
leaq 0x31ef8(%rip), %rdx     # 0x6eb58
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rcx
callq 0x35977
cmpl $0x0, (%rbx)
je 0x3cc82
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 0x4acab
movq %rax, 0x28(%rsp)
cmpl $0x0, (%rbx)
je 0x3ccd8
movq 0x30(%rsp), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29d88
testb %r13b, %r13b
je 0x3cd1e
movq 0x48(%r14), %rdi
callq 0x2b774
movq %rax, %rbp
movq 0x48(%r14), %rdi
pushq $0x43
popq %rsi
movq 0x28(%rsp), %rdx
movq %rax, %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4a690
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq %rax, %r12
leaq 0x31e1a(%rip), %rdi     # 0x6eb58
movq %rbx, %rsi
callq 0x33df0
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq %rax, %rbp
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq %rax, %r15
movq 0x48(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
pushq $0x3b
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x341c4
cmpl $0x0, (%rbx)
jne 0x3ccc0
leaq 0x31d50(%rip), %rsi     # 0x6eb58
movq %r14, %rdi
movq %r12, %rdx
xorl %ecx, %ecx
movq %rax, %r8
movq %rbx, %r9
callq 0x46684
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
movl %ebp, %r8d
pushq $0x9
popq %rsi
movq %r12, %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
pushq $0x45
popq %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x3ccc0
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x2b781
jmp 0x3ccc0