// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_gen.c
// Function: subtilis_arm_gen_call_gen
void subtilis_arm_gen_call_gen(subtilis_ir_section_t *s, size_t start,
			       void *user_data,
			       subtilis_arm_br_link_type_t link_type,
			       bool indirect, subtilis_error_t *err)
{
	subtilis_arm_reg_t op0;
	subtilis_arm_instr_t *instr;
	subtilis_arm_br_instr_t *br;
	size_t stm_site;
	size_t ldm_site;
	size_t call_site;
	int i;
	subtilis_ir_call_t *call = &s->ops[start]->op.call;
	subtilis_arm_section_t *arm_s = user_data;
	size_t stf_site = INT_MAX;
	size_t ldf_site = INT_MAX;
	size_t int_args = 0;
	size_t real_args = 0;
	int save_real_start = INT_MAX;
	size_t int_arg_ops[SUBTILIS_IR_MAX_ARGS_PER_TYPE - 4];
	size_t real_arg_ops[SUBTILIS_IR_MAX_ARGS_PER_TYPE - 4];

	if (!arm_s->fp_if) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	for (i = 0; i < call->arg_count; i++) {
		if (call->args[i].type == SUBTILIS_IR_REG_TYPE_REAL)
			real_args++;
		else
			int_args++;
	}

	if (real_args > SUBTILIS_IR_MAX_ARGS_PER_TYPE ||
	    int_args > SUBTILIS_IR_MAX_ARGS_PER_TYPE) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	prv_stack_args(arm_s, call, int_args, real_args, int_arg_ops,
		       real_arg_ops, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op0 = 13;

	subtilis_arm_add_mtran(arm_s, SUBTILIS_ARM_INSTR_STM,
			       SUBTILIS_ARM_CCODE_AL, op0, 1 << 14 | 1 << 11,
			       SUBTILIS_ARM_MTRAN_FD, true, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	stm_site = arm_s->last_op;

	if (s->freg_counter > 0) {
		save_real_start = real_args > 4 ? 4 : real_args;
		stf_site =
		    arm_s->fp_if->preserve_regs_fn(arm_s, save_real_start, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	if (indirect) {
		subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false,
					 14, 15, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_AL;
	br->link = true;
	br->link_type = link_type;
	if (indirect)
		br->target.reg = subtilis_arm_ir_to_arm_reg(call->proc_id);
	else
		br->target.label = call->proc_id;
	br->indirect = indirect;

	call_site = arm_s->last_op;

	if (s->freg_counter > 0) {
		ldf_site =
		    arm_s->fp_if->restore_regs_fn(arm_s, save_real_start, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_arm_add_mtran(arm_s, SUBTILIS_ARM_INSTR_LDM,
			       SUBTILIS_ARM_CCODE_AL, op0, 1 << 14 | 1 << 11,
			       SUBTILIS_ARM_MTRAN_FD, true, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	ldm_site = arm_s->last_op;
	subtilis_arm_section_add_call_site(
	    arm_s, stm_site, ldm_site, stf_site, ldf_site, int_args, real_args,
	    call_site, int_arg_ops, real_arg_ops, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cmpq $0x0, 0xc0(%rdx)
je 0x51a9c
movq %rdx, %r14
movl %ecx, 0x44(%rsp)
movl %r8d, 0x14(%rsp)
movq %rdi, 0x48(%rsp)
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %r8
movq 0x10(%r8), %r10
testq %r10, %r10
je 0x51ab2
movq 0x20(%r8), %rax
xorl %r12d, %r12d
movq %r10, %rcx
xorl %r15d, %r15d
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%rax)
sete %dl
setne %sil
addq %rsi, %r15
addq %rdx, %r12
addq $0x18, %rax
decq %rcx
jne 0x51a7d
jmp 0x51ab8
leaq 0x2414b(%rip), %rdx     # 0x75bee
movq %r9, %rdi
movl $0xf, %esi
movl $0x353, %ecx            # imm = 0x353
jmp 0x51ae1
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x11, %r12
setae %al
cmpq $0x11, %r15
setae %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x51af7
leaq 0x2411a(%rip), %rdx     # 0x75bee
movq %r9, %rdi
movl $0xf, %esi
movl $0x360, %ecx            # imm = 0x360
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145a4
movq $0x0, 0x8(%rsp)
cmpq $0x5, %r15
movq %r9, (%rsp)
movq %r12, 0x38(%rsp)
movq %r8, 0x20(%rsp)
jb 0x51c11
testq %r10, %r10
je 0x51c11
leaq (%r10,%r10,2), %rax
decq %r10
leaq -0x10(,%rax,8), %rbp
movq $0x0, 0x28(%rsp)
movq %r15, %rcx
movq $0x0, 0x8(%rsp)
movq 0x20(%r8), %rax
cmpl $0x1, -0x8(%rax,%rbp)
je 0x51bf2
movq %rcx, 0x30(%rsp)
movq %r10, 0x18(%rsp)
movq (%rax,%rbp), %r12
movq %r14, %rdi
movl $0x13, %esi
movq %r14, %rbx
movq (%rsp), %r14
movq %r14, %rdx
callq 0x4f6e2
cmpl $0x0, (%r14)
jne 0x51e29
movq %rax, %r13
movq 0x8(%rsp), %r14
addq $0x4, %r14
movq 0x28(%rbx), %rax
movq 0x28(%rsp), %rcx
movq %rax, 0xb0(%rsp,%rcx,8)
incq %rcx
movq %rcx, 0x28(%rsp)
movl $0xe, 0x8(%r13)
movq %r12, %rdi
callq 0x4efba
movq %rax, 0x10(%r13)
movq $0xd, 0x18(%r13)
movl $0x1, 0x20(%r13)
movq %r14, 0x8(%rsp)
movl %r14d, 0x28(%r13)
movl $0x10001, 0x48(%r13)    # imm = 0x10001
movq 0x30(%rsp), %rcx
decq %rcx
movq %rbx, %r14
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r10
addq $-0x1, %r10
jae 0x51c06
addq $-0x18, %rbp
cmpq $0x4, %rcx
ja 0x51b45
movq 0x10(%r8), %r10
movq 0x38(%rsp), %r12
jmp 0x51c14
movq %r15, %rcx
cmpq $0x5, %r12
movq %rcx, 0x30(%rsp)
jb 0x51cd7
testq %r10, %r10
je 0x51cd7
leaq (%r10,%r10,2), %rax
decq %r10
leaq -0x10(,%rax,8), %r13
xorl %ebp, %ebp
movq 0x20(%r8), %rax
cmpl $0x1, -0x8(%rax,%r13)
jne 0x51cbf
movq %r10, 0x18(%rsp)
movq 0x8(%rsp), %rbx
addq $0x8, %rbx
movq (%rax,%r13), %rsi
movq 0xc0(%r14), %rax
movq 0x48(%rax), %rax
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x4eff0
movl $0xd, %edx
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, 0x8(%rsp)
movq %rbx, %rcx
movq %r14, %rbx
movq (%rsp), %r14
movq %r14, %r8
callq *0x28(%rsp)
cmpl $0x0, (%r14)
jne 0x51e29
movq 0x28(%rbx), %rax
movq %rax, 0x50(%rsp,%rbp,8)
incq %rbp
decq %r12
movq %rbx, %r14
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %rcx
addq $-0x1, %r10
jae 0x51cd3
addq $-0x18, %r13
cmpq $0x4, %r12
ja 0x51c3d
movq 0x10(%r8), %r10
testq %r10, %r10
movq %r12, 0x8(%rsp)
je 0x51d68
testq %rcx, %rcx
je 0x51d68
movl $0x1, %r13d
movl $0x8, %r12d
xorl %ebp, %ebp
movq 0x20(%r8), %rax
cmpl $0x0, -0x8(%rax,%r12)
jne 0x51d57
movq (%rax,%r12), %rdi
callq 0x4efba
subq $0x8, %rsp
movq %r14, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %rbp, %r8
movq %rax, %r9
movq %r14, %rbx
movq 0x8(%rsp), %r14
pushq %r14
callq 0x504b3
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x51e29
incq %rbp
movq 0x20(%rsp), %r8
movq 0x10(%r8), %r10
movq %rbx, %r14
movq 0x30(%rsp), %rcx
cmpq %r10, %r13
jae 0x51d68
incq %r13
addq $0x18, %r12
cmpq %rcx, %rbp
jb 0x51cf8
testq %r10, %r10
je 0x51de1
cmpq $0x0, 0x8(%rsp)
je 0x51de1
movl $0x1, %r12d
movl $0x8, %r13d
xorl %ebp, %ebp
movq 0x20(%r8), %rax
cmpl $0x1, -0x8(%rax,%r13)
jne 0x51dce
movq (%rax,%r13), %rsi
movq %r14, %rdi
callq 0x4eff0
movq 0xc0(%r14), %r8
movq %r14, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq %r14, %rbx
movq (%rsp), %r14
movq %r14, %rcx
callq *0x50(%r8)
cmpl $0x0, (%r14)
jne 0x51e29
incq %rbp
movq 0x20(%rsp), %r8
movq 0x10(%r8), %r10
movq %rbx, %r14
cmpq %r10, %r12
jae 0x51de1
incq %r12
addq $0x18, %r13
cmpq 0x8(%rsp), %rbp
jb 0x51d83
movq (%rsp), %rax
cmpl $0x0, (%rax)
jne 0x51e29
movq %r14, %r12
subq $0x8, %rsp
movl $0xd, %ecx
movl $0x4800, %r8d           # imm = 0x4800
movq %r14, %rdi
movl $0x15, %esi
movl $0xe, %edx
movl $0x5, %r9d
movq 0x8(%rsp), %r14
pushq %r14
pushq $0x0
pushq $0x1
callq 0x509ef
addq $0x20, %rsp
cmpl $0x0, (%r14)
je 0x51e3b
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%r12), %rbx
movq 0x48(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x51e80
movq 0x38(%rsp), %rax
cmpq $0x4, %rax
movl $0x4, %ebp
cmovbq %rax, %rbp
movq 0xc0(%r12), %rax
movq %r12, %rdi
movl %ebp, %esi
movq (%rsp), %r14
movq %r14, %rdx
callq *0x28(%rax)
cmpl $0x0, (%r14)
jne 0x51e29
movq %rax, %r13
jmp 0x51e8b
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
cmpb $0x0, 0x14(%rsp)
je 0x51ecb
subq $0x8, %rsp
movl $0xe, %r8d
movl $0xf, %r9d
movq %r12, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq 0x8(%rsp), %r14
pushq %r14
callq 0x504b3
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x51e29
movq %r12, %rdi
movl $0x16, %esi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x4f6e2
cmpl $0x0, (%r14)
jne 0x51e29
movq %rax, %rcx
movl $0xe, 0x8(%rax)
movb $0x1, 0xc(%rax)
movl 0x44(%rsp), %eax
movl %eax, 0x10(%rcx)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
cmpb $0x0, 0x14(%rsp)
je 0x51f1c
movq %rax, %rdi
movq %rcx, %r14
callq 0x4efba
movq %r14, %rcx
movq %r12, %rdi
movq %rax, 0x18(%rcx)
movl 0x14(%rsp), %eax
movb %al, 0xe(%rcx)
movq 0x28(%r12), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x51f63
movq 0xc0(%rdi), %rax
movl %ebp, %esi
movq %r13, %r14
movq (%rsp), %r13
movq %r13, %rdx
callq *0x30(%rax)
cmpl $0x0, (%r13)
jne 0x51e29
jmp 0x51f6b
movq %r13, %r14
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
subq $0x8, %rsp
movl $0xd, %ecx
movl $0x4800, %r8d           # imm = 0x4800
movq %r12, %rdi
movl $0x14, %esi
movl $0xe, %edx
movl $0x5, %r9d
movq 0x8(%rsp), %r13
pushq %r13
pushq $0x0
pushq $0x1
callq 0x509ef
addq $0x20, %rsp
cmpl $0x0, (%r13)
movq 0x18(%rsp), %r8
jne 0x51e29
movq 0x28(%r12), %rdx
subq $0x8, %rsp
leaq 0x58(%rsp), %rax
leaq 0xb8(%rsp), %r10
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rcx
movq %r15, %r9
pushq 0x8(%rsp)
pushq %rax
pushq %r10
pushq 0x28(%rsp)
pushq 0x60(%rsp)
callq 0x4f12d
addq $0x30, %rsp
jmp 0x51e29