// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: optimize_func_many_args
static opt_t optimize_func_many_args(s7_scheme *sc, s7_pointer expr, s7_pointer func, int32_t hop, int32_t args, int32_t pairs, int32_t symbols, int32_t quotes, int32_t bad_pairs, s7_pointer e)
                {
                    bool func_is_closure;
                    /* fprintf(stderr, "%s[%d]: %s, args: %d, bad: %d, quotes: %d\n", __func__, __LINE__, DISPLAY_80(expr), args, bad_pairs, quotes); */

                    if (quotes > 0)
                    {
                        if (direct_memq(sc->quote_symbol, e))
                            return(OPT_OOPS);
                        if ((bad_pairs == quotes) &&
                                (is_constant_symbol(sc, car(expr))))
                            hop = 1;
                    }

                    if ((is_c_function(func)) &&
                            (c_function_required_args(func) <= args) &&
                            (c_function_all_args(func) >= args))
                    {
                        if ((hop == 0) && (symbol_id(car(expr)) == 0)) hop = 1;

                        if (is_safe_procedure(func))
                        {
                            if (pairs == 0)
                            {
                                if (symbols == 0)
                                {
                                    set_safe_optimize_op(expr, hop + OP_SAFE_C_D);
                                    choose_c_function(sc, expr, func, args);
                                    return(OPT_T);
                                }
                                if ((symbols == args) &&
                                        (args < GC_TRIGGER_SIZE))
                                {
                                    if (symbols_are_safe(sc, cdr(expr), e))
                                        set_safe_optimize_op(expr, hop + OP_SAFE_C_ALL_S);
                                    else
                                    {
                                        set_safe_optimize_op(expr, hop + ((args == 4) ? OP_SAFE_C_4A : OP_SAFE_C_FX));
                                        annotate_args(sc, cdr(expr), e);
                                    }
                                    set_opt3_arglen(expr, make_permanent_integer(args));
                                    choose_c_function(sc, expr, func, args);
                                    return(OPT_T);
                                }
                            }

                            if (args < GC_TRIGGER_SIZE)
                            {
                                if (fx_count(sc, expr) == args)
                                {
                                    s7_pointer p;
                                    set_optimized(expr);
                                    set_optimize_op(expr, hop + ((args == 4) ? OP_SAFE_C_4A : OP_SAFE_C_FX));
                                    annotate_args(sc, cdr(expr), e);
                                    set_opt3_arglen(expr, make_permanent_integer(args));
                                    choose_c_function(sc, expr, func, args);

                                    for (p = cdr(expr); (is_pair(p)) && (is_pair(cdr(p))); p = cddr(p))
                                    {
                                        if (is_normal_symbol(car(p)))
                                            break;
                                        if ((is_pair(car(p))) &&
                                                ((!is_pair(cdar(p))) || (caar(p) != sc->quote_symbol)))
                                            break;
                                    }
                                    if (is_null(p))
                                    {
                                        set_optimize_op(expr, hop + OP_SAFE_C_ALL_CA);
                                        for (p = cdr(expr); is_pair(p); p = cddr(p))
                                        {
                                            clear_has_fx(p);
                                            set_opt2_any(p, (is_pair(car(p))) ? cadar(p) : car(p));
                                        }
                                    }
                                    return(OPT_T);
                                }
                                return(set_safe_c_fp(sc, func, expr, e, args, hop + OP_SAFE_C_FP));
                            }
                        }
                        else /* c_func is not safe */
                        {
                            if ((args < GC_TRIGGER_SIZE) &&
                                    (fx_count(sc, expr) == args))
                            {
                                set_unsafe_optimize_op(expr, hop + OP_C_FX);
                                annotate_args(sc, cdr(expr), e);
                                set_opt3_arglen(expr, make_permanent_integer(args));
                                choose_c_function(sc, expr, func, args);
                                return(OPT_F);
                            }
                            return(set_safe_c_fp(sc, func, expr, e, 3, hop + OP_SAFE_C_FP));
                        }
                        return((is_optimized(expr)) ? OPT_T : OPT_F);
                    }

                    func_is_closure = is_closure(func);
                    if (func_is_closure)
                    {
                        int32_t arit;

                        arit = closure_arity_to_int(sc, func);
                        if (arit != args)
                        {
                            if ((arit == -1) &&
                                    (is_symbol(closure_args(func))))
                                return(optimize_func_dotted_args(sc, expr, func, hop, args, e));
                            return(OPT_F);
                        }
                        if (is_immutable(func)) hop = 1;

                        if ((fx_count(sc, expr) == args) &&
                                (args < GC_TRIGGER_SIZE))
                        {
                            bool safe_case;
                            set_unsafely_optimized(expr);
                            safe_case = is_safe_closure(func);
                            set_unsafe_optimize_op(expr, hop + ((safe_case) ? OP_SAFE_CLOSURE_FX : OP_CLOSURE_FX));
                            annotate_args(sc, cdr(expr), e);
                            set_opt3_arglen(expr, make_permanent_integer(args));
                            set_opt1_lambda(expr, func);

                            if ((symbols == args) &&
                                    (symbols_are_safe(sc, cdr(expr), e)))
                            {
                                if (safe_case)
                                    set_optimize_op(expr, hop + OP_SAFE_CLOSURE_ALL_S);
                                else set_optimize_op(expr, hop + ((args == 4) ? ((is_null(cdr(closure_body(func)))) ? OP_CLOSURE_4S_P : OP_CLOSURE_4S) : OP_CLOSURE_ALL_S));
                            }
                            return(OPT_F);
                        }

                        if ((is_safe_closure(func)) &&
                                (args < GC_TRIGGER_SIZE))
                            return(set_safe_closure_fp(sc, func, expr, e, args, hop + OP_SAFE_CLOSURE_FP));
                    }

                    if ((is_closure_star(func)) &&
                            ((!lambda_has_simple_defaults(closure_body(func))) ||
                             (closure_star_arity_to_int(sc, func) == 0) ||
                             (closure_star_arity_to_int(sc, func) == 1)))
                        return(OPT_F);

                    if ((is_c_function_star(func)) &&
                            (fx_count(sc, expr) == args))
                    {
                        if (is_immutable(func)) hop = 1;
                        set_safe_optimize_op(expr, hop + OP_SAFE_C_FUNCTION_STAR_FX);
                        annotate_args(sc, cdr(expr), e);
                        set_opt3_arglen(expr, make_permanent_integer(args));
                        set_c_function(expr, func);
                        return(OPT_T);
                    }

                    if (args < GC_TRIGGER_SIZE)
                    {
                        if (((func_is_closure) ||
                                    (is_closure_star(func))) &&
                                (fx_count(sc, expr) == args))
                        {
                            set_unsafely_optimized(expr);
                            if (func_is_closure)
                                set_optimize_op(expr, hop + ((is_safe_closure(func)) ? OP_SAFE_CLOSURE_FX : OP_CLOSURE_FX));
                            else set_optimize_op(expr, hop + ((is_safe_closure(func)) ? OP_SAFE_CLOSURE_STAR_FX : OP_CLOSURE_STAR_FX));
                            annotate_args(sc, cdr(expr), e);
                            set_opt3_arglen(expr, make_permanent_integer(args));
                            set_opt1_lambda(expr, func);
                            return(OPT_F);
                        }
                    }
                    return((is_optimized(expr)) ? OPT_T : OPT_F);
                }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r11
movq 0x68(%rsp), %rcx
movl 0x58(%rsp), %eax
testl %eax, %eax
jle 0xdfe81
cmpb $0x1, (%rcx)
jne 0xdfe21
movq 0x17b0(%rdi), %rsi
movq %rcx, %rdx
cmpq %rsi, 0x8(%rdx)
je 0xe008d
movq 0x10(%rdx), %rdx
cmpb $0x1, (%rdx)
je 0xdfe0e
cmpl %eax, 0x60(%rsp)
jne 0xdfe81
movq 0x8(%r11), %rax
movq (%rax), %rdx
btl $0x18, %edx
jb 0xdfe7c
btq $0x30, %rdx
jae 0xdfe81
movq 0x8(%rdi), %rdx
movq 0x18(%rdx), %r8
movq 0x20(%rax), %rsi
movl $0x18, %r10d
cmpq %rsi, %r8
je 0xdfe6a
jle 0xdfe61
movq 0x10(%rdx), %rdx
movq 0x18(%rdx), %r8
cmpq %r8, %rsi
jl 0xdfe54
cmpq %rsi, %r8
jne 0xe04c7
movq (%rax,%r10), %rsi
cmpb $0x20, (%rsi)
jne 0xdfe81
movq (%rsi), %rax
btl $0x18, %eax
jae 0xdfe81
movl $0x1, %ebx
movl 0x50(%rsp), %edx
movb (%r15), %r13b
cmpb $0x30, %r13b
jae 0xdffd0
movq %rbx, (%rsp)
cmpb $0x28, %r13b
sete %r14b
jne 0xe0372
movl %edx, %ebx
movq %r11, 0x8(%rsp)
movq %r15, %rsi
movq %rdi, %r12
callq 0xccf45
cmpl %ebp, %eax
jne 0xe0098
movq (%r15), %r13
btl $0x18, %r13d
movl $0x1, %eax
movq (%rsp), %rcx
cmovbl %eax, %ecx
movq %rcx, (%rsp)
movq %r12, 0x10(%rsp)
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0xe067a
cmpl $0x3f, %ebp
jg 0xe01a6
cmpl %ebp, %eax
jne 0xe01a6
movq 0x8(%rsp), %r12
orq $0x800800, (%r12)       # imm = 0x800800
movl (%r15), %r14d
movq (%rsp), %rcx
leal 0x112(%rcx), %eax
addl $0x108, %ecx            # imm = 0x108
btl $0xc, %r14d
cmovbl %eax, %ecx
movw %cx, 0x4(%r12)
movq 0x10(%r12), %rsi
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq 0x68(%rsp), %rdx
callq 0xd151a
movslq %ebp, %rdi
callq 0xe05f3
movq %r12, %rdx
movq 0x10(%r12), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%r12), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq %r15, 0x18(%r12)
xorl %r12d, %r12d
cmpl %ebp, %ebx
jne 0xe05e1
movq 0x10(%rdx), %rsi
movq %r13, %rdi
movq 0x68(%rsp), %rdx
callq 0xe5935
testb %al, %al
je 0xe05e1
btl $0xc, %r14d
jb 0xe0542
movl $0x10a, %eax            # imm = 0x10A
cmpl $0x4, %ebp
movq (%rsp), %rbx
movq 0x8(%rsp), %rsi
jne 0xdffc5
movq 0x10(%r15), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
cmpq 0x110(%rdx), %rax
sete %cl
leal 0xf8(,%rcx,2), %eax
addl %ebx, %eax
movw %ax, 0x4(%rsi)
jmp 0xe05e1
movslq %ebp, %r12
cmpq %r12, 0x18(%r15)
jg 0xdffe3
cmpq %r12, 0x28(%r15)
jge 0xe00d2
movq %rbx, (%rsp)
xorl %r14d, %r14d
cmpb $0x29, %r13b
sete %al
cmpl $0x3f, %ebp
jg 0xe0333
orb %r14b, %al
je 0xe0333
movq %r11, %rsi
movq %rdi, %r12
movq %rcx, %r13
movl %ebp, %ebx
movq %r11, %rbp
callq 0xe067a
movq %rbp, %r11
cmpl %ebx, %eax
jne 0xe0333
movl %ebx, %ebp
movq %r13, %rdx
movq %r12, %rdi
orq $0x800800, (%r11)       # imm = 0x800800
btl $0xc, (%r15)
movl $0x108, %eax            # imm = 0x108
movl $0x112, %ecx            # imm = 0x112
cmovael %eax, %ecx
movl $0x11a, %eax            # imm = 0x11A
movl $0x120, %esi            # imm = 0x120
cmovael %eax, %esi
testb %r14b, %r14b
cmovnel %ecx, %esi
addl (%rsp), %esi
movw %si, 0x4(%r11)
movq 0x10(%r11), %rsi
movq %r11, %rbx
callq 0xd151a
movslq %ebp, %rdi
callq 0xe05f3
movq 0x10(%rbx), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%rbx), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq %r15, 0x18(%rbx)
jmp 0xe0360
movl $0x2, %r12d
jmp 0xe05e1
movq %r12, %rdi
xorl %r12d, %r12d
cmpl $-0x1, %eax
movq 0x8(%rsp), %rsi
jne 0xe05e1
movq 0x8(%r15), %rax
cmpb $0xa, (%rax)
jne 0xe05e1
movq %r15, %rdx
movq (%rsp), %rcx
movl %ebp, %r8d
movq 0x68(%rsp), %r9
callq 0xe11b1
jmp 0xe05e1
movl $0x1, %r13d
testl %ebx, %ebx
jne 0xe00ec
movq 0x8(%r11), %rax
xorl %r13d, %r13d
cmpq $0x0, 0x20(%rax)
sete %r13b
testb $0x20, 0x2(%r15)
jne 0xe01e6
cmpl $0x3f, %ebp
jg 0xe0345
movq %r11, %rsi
movq %rdi, %r14
movq %r11, %rbx
callq 0xe067a
movq %rbx, %r11
movq 0x68(%rsp), %rcx
movq %r14, %rdi
cmpl %ebp, %eax
jne 0xe0345
orq $0x800800, (%r11)       # imm = 0x800800
orl $0x12a, %r13d           # imm = 0x12A
movw %r13w, 0x4(%r11)
movq 0x10(%r11), %rsi
movq %rcx, %rdx
movq %rdi, %r14
movq %r11, %rbx
callq 0xd151a
movq %r12, %rdi
callq 0xe05f3
movq 0x10(%rbx), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%rbx), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq 0x8(%r15), %rax
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq %rax, 0x18(%rbx)
movq 0x8(%r15), %rax
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq 0x10(%rax), %rax
movq %rax, 0x20(%rbx)
orb $0x4, 0x6(%rbx)
jmp 0xe0360
cmpl $0x40, %ebp
setge %al
btl $0xc, %r13d
setae %cl
orb %al, %cl
movq 0x68(%rsp), %rcx
jne 0xe0368
movq (%rsp), %r9
addl $0x128, %r9d            # imm = 0x128
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %r8d
callq 0xe1532
jmp 0xe0360
testl %r9d, %r9d
je 0xe0477
cmpl $0x3f, %ebp
jg 0xe0333
movq %r13, (%rsp)
movq %rcx, %r13
movq %r11, %rsi
movq %rdi, %r14
movq %r11, %rbx
callq 0xe067a
cmpl %ebp, %eax
jne 0xe04f5
orb $0x8, 0x1(%rbx)
xorl %eax, %eax
cmpl $0x4, %ebp
setne %al
movq (%rsp), %rcx
leal (%rcx,%rax,2), %eax
addl $0x76, %eax
movw %ax, 0x4(%rbx)
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xd151a
movq %r12, %rdi
callq 0xe05f3
movq 0x10(%rbx), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%rbx), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq 0x8(%r15), %rax
movl $0x1, %r12d
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq %rax, 0x18(%rbx)
movq 0x8(%r15), %rax
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq 0x10(%rax), %rax
movq %rax, 0x20(%rbx)
orb $0x4, 0x6(%rbx)
movq 0x10(%rbx), %rax
cmpb $0x1, (%rax)
movq %rax, %rcx
jne 0xe02ef
movq %rax, %rcx
movq 0x10(%rcx), %rdx
cmpb $0x1, (%rdx)
jne 0xe02ef
movq 0x8(%rcx), %rsi
movzbl (%rsi), %edi
cmpl $0x1, %edi
je 0xe02d0
cmpl $0xa, %edi
jne 0xe02e6
testb $-0x80, 0x6(%rsi)
jne 0xe02e6
jmp 0xe02ef
movq 0x10(%rsi), %rdi
cmpb $0x1, (%rdi)
jne 0xe02ef
movq 0x8(%rsi), %rsi
cmpq 0x17b0(%r14), %rsi
jne 0xe02ef
movq 0x10(%rdx), %rcx
cmpb $0x1, (%rcx)
je 0xe02ae
cmpq 0x110(%r14), %rcx
jne 0xe05e1
movq (%rsp), %rcx
orl $0x7a, %ecx
movw %cx, 0x4(%rbx)
cmpb $0x1, (%rax)
jne 0xe05e1
andb $-0x5, 0x6(%rax)
movq 0x8(%rax), %rcx
cmpb $0x1, (%rcx)
jne 0xe0325
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
jmp 0xe0307
xorl %r12d, %r12d
cmpw $0x801, (%r11)          # imm = 0x801
sete %r12b
jmp 0xe05e1
orl $0x162, %r13d           # imm = 0x162
movq %r15, %rsi
movq %r11, %rdx
movl $0x3, %r8d
movq %r13, %r9
callq 0xe5828
xorl %r12d, %r12d
jmp 0xe05e1
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r11
cmpb $0x29, %r13b
jne 0xe03d9
movq 0x10(%r15), %rax
xorl %r12d, %r12d
testb $0x4, 0x1(%rax)
je 0xe05e1
movq %r11, 0x8(%rsp)
movq 0x8(%r15), %rdx
movq %r15, %rsi
movq %rdi, %r13
callq 0x9a1d8
cmpl $0x0, 0x28(%r15)
je 0xe05e1
movq 0x8(%r15), %rdx
movq %r13, 0x10(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x9a1d8
cmpl $0x1, 0x28(%r15)
je 0xe05e1
movb (%r15), %r13b
movq 0x10(%rsp), %rdi
movq 0x68(%rsp), %rcx
movq 0x8(%rsp), %r11
cmpb $0x2f, %r13b
jne 0xdffea
movq %r11, %rsi
movq %rdi, %rbx
movq %r11, %r12
callq 0xe067a
movb $0x2f, %r13b
movq %rbx, %rdi
cmpl %ebp, %eax
jne 0xe046a
movq (%rsp), %rbx
addl $0x9a, %ebx
btl $0x18, (%r15)
movl $0x9b, %eax
cmovael %ebx, %eax
orw $0x800, (%r12)          # imm = 0x800
movw %ax, 0x4(%r12)
movq 0x10(%r12), %rsi
movq 0x68(%rsp), %rdx
callq 0xd151a
movslq %ebp, %rdi
callq 0xe05f3
movq 0x10(%r12), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%r12), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq %r15, 0x18(%r12)
movq 0x10(%r15), %rax
movq %rax, 0x20(%r12)
orb $0x4, 0x6(%r12)
movl $0x1, %r12d
jmp 0xe05e1
movq 0x68(%rsp), %rcx
movq %r12, %r11
jmp 0xdffea
testl %edx, %edx
je 0xe0514
cmpl %ebp, %edx
setne %al
cmpl $0x40, %ebp
setge %dl
orb %al, %dl
jne 0xe01ef
movq %r13, (%rsp)
movq 0x10(%r11), %r13
movq %r13, %rsi
movq %rcx, %rdx
movq %rdi, %r14
movq %r11, %rbx
callq 0xe5935
orb $0x8, 0x1(%rbx)
testb %al, %al
je 0xe055a
movq (%rsp), %rax
orl $0x1c, %eax
movw %ax, 0x4(%rbx)
jmp 0xe0580
movl $0x10, %r10d
cmpb $0x1c, (%rdx)
jne 0xdfe6a
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0xe04ef
cmpq %rax, 0x8(%rsi)
je 0xdfe6e
movq 0x18(%rsi), %rsi
jmp 0xe04da
movq 0x10(%rdx), %rdx
jmp 0xe04cd
movq (%rsp), %r9
orl $0x162, %r9d            # imm = 0x162
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movl %ebp, %r8d
jmp 0xe035b
orb $0x8, 0x1(%r11)
orl $0x2, %r13d
movw %r13w, 0x4(%r11)
movq 0x8(%r15), %rax
movl $0x1, %r12d
movq %r15, %rsi
movl %ebp, %edx
movq %r11, %rcx
movq %rdi, %r14
movl $0x1, %r8d
movq %r11, %rbx
jmp 0xe05b6
movq (%rsp), %rbx
addl $0x116, %ebx            # imm = 0x116
movq 0x8(%rsp), %rax
movw %bx, 0x4(%rax)
jmp 0xe05e1
xorl %eax, %eax
cmpl $0x4, %ebp
setne %al
movq (%rsp), %rcx
leal (%rcx,%rax,2), %eax
addl $0x76, %eax
movw %ax, 0x4(%rbx)
movq %r14, %rdi
movq %r13, %rsi
movq 0x68(%rsp), %rdx
callq 0xd151a
movq %r12, %rdi
callq 0xe05f3
movq 0x10(%rbx), %rcx
movq %rax, 0x28(%rcx)
movq 0x10(%rbx), %rax
andq $-0x40001, (%rax)       # imm = 0xFFFBFFFF
movq 0x8(%r15), %rax
movl $0x1, %r12d
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq %rax, 0x18(%rbx)
movq 0x8(%r15), %rax
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq *0x48(%rax)
movq 0x10(%rax), %rax
movq %rax, 0x20(%rbx)
orb $0x4, 0x6(%rbx)
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq