// File: /workspace/github_c_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
cmpq $0x0, 0xc0(%rdx)
je 0x51c1b
movq %rdx, %rbx
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %r12
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x51c31
movq 0x20(%r12), %r11
xorl %r10d, %r10d
xorl %r15d, %r15d
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%r11)
sete %dl
setne %sil
addq %rsi, %r15
addq %rdx, %r10
addq $0x18, %r11
decq %rax
jne 0x51bfb
jmp 0x51c37
leaq 0x23f8c(%rip), %rdx     # 0x75bae
movq %r9, %rdi
movl $0xf, %esi
movl $0x353, %ecx            # imm = 0x353
jmp 0x51c60
xorl %r15d, %r15d
xorl %r10d, %r10d
cmpq $0x11, %r10
setae %al
cmpq $0x11, %r15
setae %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x51c76
leaq 0x23f5b(%rip), %rdx     # 0x75bae
movq %r9, %rdi
movl $0xf, %esi
movl $0x360, %ecx            # imm = 0x360
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movl %ecx, 0x4c(%rsp)
movq %rdi, 0x50(%rsp)
movl %r8d, 0x3c(%rsp)
movq %r10, 0x30(%rsp)
movq %r9, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
cmpq $0x5, %r15
movq %rbx, 0x8(%rsp)
movq %r12, 0x28(%rsp)
jb 0x51d9e
movq 0x10(%r12), %r14
movq %r15, %rcx
testq %r14, %r14
je 0x51da1
leaq (%r14,%r14,2), %rax
decq %r14
leaq -0x10(,%rax,8), %rbp
movq $0x0, 0x20(%rsp)
movq %r15, %rcx
movq $0x0, 0x18(%rsp)
movq 0x20(%r12), %rax
cmpl $0x1, -0x8(%rax,%rbp)
je 0x51d88
movq %rcx, 0x40(%rsp)
movq (%rax,%rbp), %r12
movq %rbx, %rdi
movl $0x13, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x51f8d
movq %rax, %r13
movq 0x18(%rsp), %rbx
addq $0x4, %rbx
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rsp), %rcx
movq %rax, 0xc0(%rsp,%rcx,8)
incq %rcx
movq %rcx, 0x20(%rsp)
movl $0xe, 0x8(%r13)
movq %r12, %rdi
callq 0x4eff7
movq %rax, 0x10(%r13)
movq $0xd, 0x18(%r13)
movl $0x1, 0x20(%r13)
movq %rbx, 0x18(%rsp)
movl %ebx, 0x28(%r13)
movq 0x8(%rsp), %rbx
movl $0x10001, 0x48(%r13)    # imm = 0x10001
movq 0x40(%rsp), %rcx
decq %rcx
movq 0x28(%rsp), %r12
addq $-0x1, %r14
jae 0x51da1
addq $-0x18, %rbp
cmpq $0x4, %rcx
ja 0x51ce0
jmp 0x51da1
movq %r15, %rcx
movq 0x30(%rsp), %rax
movq %rax, %rdx
cmpq $0x5, %rax
movq %rcx, 0x40(%rsp)
jb 0x51e7b
movq 0x10(%r12), %r14
movq 0x30(%rsp), %rdx
testq %r14, %r14
je 0x51e7b
leaq (%r14,%r14,2), %rax
decq %r14
leaq -0x10(,%rax,8), %r13
xorl %ebp, %ebp
movq 0x30(%rsp), %rdx
movq 0x20(%r12), %rax
cmpl $0x1, -0x8(%rax,%r13)
jne 0x51e67
movq %rbx, %r12
movq 0x18(%rsp), %rbx
addq $0x8, %rbx
movq (%rax,%r13), %rsi
movq 0xc0(%r12), %rax
movq 0x48(%rax), %rax
movq %rax, 0x58(%rsp)
movq %r12, %rdi
movq %rdx, 0x20(%rsp)
callq 0x4f02d
movl $0xd, %edx
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, 0x18(%rsp)
movq %rbx, %rcx
movq 0x10(%rsp), %rbx
movq %rbx, %r8
callq *0x58(%rsp)
movq 0x20(%rsp), %rdx
cmpl $0x0, (%rbx)
jne 0x51f8d
movq 0x8(%rsp), %rbx
movq 0x28(%rbx), %rax
movq %rax, 0x60(%rsp,%rbp,8)
incq %rbp
decq %rdx
movq 0x28(%rsp), %r12
movq 0x40(%rsp), %rcx
addq $-0x1, %r14
jae 0x51e7b
addq $-0x18, %r13
cmpq $0x4, %rdx
ja 0x51de1
cmpq $0x0, 0x10(%r12)
movq %rdx, 0x20(%rsp)
je 0x51f10
testq %rcx, %rcx
je 0x51f10
movl $0x1, %r14d
movl $0x8, %r13d
xorl %ebp, %ebp
movq 0x20(%r12), %rax
cmpl $0x0, -0x8(%rax,%r13)
jne 0x51efd
movq (%rax,%r13), %rdi
callq 0x4eff7
subq $0x8, %rsp
movq %rbx, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %rbp, %r8
movq %rax, %r9
movq 0x18(%rsp), %rbx
pushq %rbx
callq 0x5060d
movq 0x30(%rsp), %rdx
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x51f8d
incq %rbp
movq 0x8(%rsp), %rbx
movq 0x28(%rsp), %r12
movq 0x40(%rsp), %rcx
cmpq 0x10(%r12), %r14
jae 0x51f10
incq %r14
addq $0x18, %r13
cmpq %rcx, %rbp
jb 0x51e9f
cmpq $0x0, 0x10(%r12)
je 0x51f8d
testq %rdx, %rdx
je 0x51f8d
movl $0x1, %r14d
movl $0x8, %r13d
xorl %ebp, %ebp
movq 0x28(%rsp), %rcx
movq 0x20(%rcx), %rax
cmpl $0x1, -0x8(%rax,%r13)
jne 0x51f7b
movq (%rax,%r13), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4f02d
movq 0xc0(%rbx), %r8
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rcx
callq *0x50(%r8)
movq 0x20(%rsp), %rdx
cmpl $0x0, (%rbx)
jne 0x51f8d
incq %rbp
movq 0x28(%rsp), %rcx
cmpq 0x10(%rcx), %r14
jae 0x51f8d
incq %r14
addq $0x18, %r13
cmpq %rdx, %rbp
jb 0x51f2b
movq 0x10(%rsp), %rbx
cmpl $0x0, (%rbx)
jne 0x51fce
subq $0x8, %rsp
movl $0xd, %ecx
movl $0x4800, %r8d           # imm = 0x4800
movq 0x10(%rsp), %rdi
movl $0x15, %esi
movl $0xe, %edx
movl $0x5, %r9d
pushq %rbx
pushq $0x0
pushq $0x1
callq 0x50bb6
addq $0x20, %rsp
cmpl $0x0, (%rbx)
je 0x51fe0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %r13
movq 0x50(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x52027
movq 0x30(%rsp), %rax
cmpq $0x4, %rax
movl $0x4, %ebp
cmovbq %rax, %rbp
movq 0xc0(%rdi), %rax
movl %ebp, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq *0x28(%rax)
movq %rax, 0x18(%rsp)
cmpl $0x0, (%rbx)
jne 0x51fce
jmp 0x52036
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
cmpb $0x0, 0x3c(%rsp)
movq 0x10(%rsp), %r14
je 0x52078
subq $0x8, %rsp
movl $0xe, %r8d
movl $0xf, %r9d
movq 0x10(%rsp), %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
pushq %r14
callq 0x5060d
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x51fce
movq 0x8(%rsp), %rdi
movl $0x16, %esi
movq %r14, %rdx
callq 0x4f73a
cmpl $0x0, (%r14)
jne 0x51fce
movq %rax, %r12
movl $0xe, 0x8(%rax)
movb $0x1, 0xc(%rax)
movl 0x4c(%rsp), %eax
movl %eax, 0x10(%r12)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x3c(%rsp), %ebx
testb %bl, %bl
je 0x520c4
movq %rax, %rdi
callq 0x4eff7
movq 0x8(%rsp), %rdi
movq %rax, 0x18(%r12)
movb %bl, 0xe(%r12)
movq 0x28(%rdi), %r14
movq 0x50(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x5210a
movq 0xc0(%rdi), %rax
movl %ebp, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq *0x30(%rax)
cmpl $0x0, (%rbx)
jne 0x51fce
movq %rax, %r12
movq 0x8(%rsp), %rdi
jmp 0x52110
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
subq $0x8, %rsp
movl $0xd, %ecx
movl $0x4800, %r8d           # imm = 0x4800
movl $0x14, %esi
movl $0xe, %edx
movl $0x5, %r9d
movq 0x18(%rsp), %rbx
pushq %rbx
pushq $0x0
pushq $0x1
callq 0x50bb6
addq $0x20, %rsp
cmpl $0x0, (%rbx)
jne 0x51fce
movq 0x8(%rsp), %rdi
movq 0x28(%rdi), %rdx
subq $0x8, %rsp
leaq 0x68(%rsp), %rax
leaq 0xc8(%rsp), %r10
movq %r13, %rsi
movq 0x20(%rsp), %rcx
movq %r12, %r8
movq %r15, %r9
pushq %rbx
pushq %rax
pushq %r10
pushq %r14
pushq 0x58(%rsp)
callq 0x4f187
addq $0x30, %rsp
jmp 0x51fce