// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtin_ir_call_ref_grow
subtilis_exp_t *
subtilis_builtin_ir_call_ref_grow(subtilis_parser_t *p, size_t a1_mem_reg,
				  size_t a1_size_reg, size_t gran_reg,
				  size_t a2_size_reg, subtilis_error_t *err)
{
	subtilis_ir_section_t *fn;
	subtilis_ir_arg_t *args = NULL;
	char *name_dup = NULL;
	const subtilis_type_t *ptype[4];
	const char *const name = "_ref_grow";

	ptype[0] = &subtilis_type_integer;
	ptype[1] = &subtilis_type_integer;
	ptype[2] = &subtilis_type_integer;
	ptype[3] = &subtilis_type_integer;

	fn = prv_add_args(p, name, 4, ptype, &subtilis_type_integer, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		if (err->type != SUBTILIS_ERROR_ALREADY_DEFINED)
			return NULL;
		subtilis_error_init(err);
	} else {
		prv_builtins_ir_gen_ref_grow(p, fn, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
	}

	args = malloc(sizeof(*args) * 4);
	if (!args) {
		subtilis_error_set_oom(err);
		return NULL;
	}

	name_dup = malloc(strlen(name) + 1);
	if (!name_dup) {
		subtilis_error_set_oom(err);
		goto cleanup;
	}
	strcpy(name_dup, name);

	args[0].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[0].reg = a1_mem_reg;
	args[1].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[1].reg = a1_size_reg;
	args[2].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[2].reg = gran_reg;
	args[3].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[3].reg = a2_size_reg;

	return subtilis_exp_add_call(p, name_dup, SUBTILIS_BUILTINS_MAX, NULL,
				     args, &subtilis_type_integer, 4, true,
				     err);

cleanup:
	free(args);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x3d3d2(%rip), %r8      # 0x6e8c8
leaq 0x20(%rsp), %rcx
movq %r8, (%rcx)
movq %r8, 0x8(%rcx)
movq %r8, 0x10(%rcx)
movq %r8, 0x18(%rcx)
leaq 0x3dd1f(%rip), %rsi     # 0x6f230
pushq $0x4
popq %rdx
callq 0x314be
movq %rax, %r12
movl (%rbx), %eax
testl %eax, %eax
je 0x315c6
cmpl $0x20, %eax
jne 0x3168e
movq %rbx, %rdi
callq 0x140a4
movq %r15, %r12
pushq $0x60
popq %rdi
callq 0x121d0
testq %rax, %rax
je 0x31627
movq %rax, %r15
pushq $0xa
popq %rdi
callq 0x121d0
testq %rax, %rax
je 0x31640
movabsq $0x6f72675f6665725f, %rcx # imm = 0x6F72675F6665725F
movq %rcx, (%rax)
movw $0x77, 0x8(%rax)
andl $0x0, (%r15)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%r15)
andl $0x0, 0x18(%r15)
movq %r12, 0x20(%r15)
andl $0x0, 0x30(%r15)
movq %rbp, 0x38(%r15)
andl $0x0, 0x48(%r15)
movq %r13, 0x50(%r15)
subq $0x8, %rsp
leaq 0x3d323(%rip), %r9      # 0x6e8c8
pushq $0x9
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
movq %r15, %r8
pushq %rbx
pushq $0x1
pushq $0x4
callq 0x29dcc
addq $0x68, %rsp
jmp 0x31694
movq %r15, (%rsp)
movq %rbp, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movq 0x48(%r14), %rbp
movq %r12, 0x48(%r14)
movq 0x98(%r12), %r13
movq 0xa8(%r12), %r15
pushq $0x4
popq %rdx
pushq $0x5
popq %rcx
pushq $0x6
popq %r8
pushq $0x7
popq %r9
movq %r14, %rdi
xorl %esi, %esi
pushq %rbx
pushq %r15
callq 0x4b6b5
popq %rax
popq %rcx
cmpl $0x0, (%rbx)
jne 0x31621
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
je 0x31661
movq %rbp, 0x48(%r14)
jmp 0x3168e
leaq 0x3dbeb(%rip), %rdx     # 0x6f219
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0xa29, %ecx            # imm = 0xA29
callq 0x1429e
jmp 0x3168e
leaq 0x3dbd2(%rip), %rdx     # 0x6f219
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0xa2f, %ecx            # imm = 0xA2F
callq 0x1429e
movq %r15, %rdi
callq 0x122c0
jmp 0x3168e
movq 0x48(%r14), %rdi
pushq $0x47
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
movq %rbp, 0x48(%r14)
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbp
movq (%rsp), %r15
je 0x31537
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq