// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore.xo.c
// Function: x_btcl_function_s_call
er_t x_btcl_function_s_call( x_btcl_function_s* o, x_source_point_s* source_point, x_btcl_frame_s* lexical_frame, bcore_arr_sr_s* arg_list, sr_s* result )
{
    // bcore_x_btcl.x:811:1
    
    const x_btcl_signature_s* signature = o->signature;
    if( arg_list->size < signature->arg_list.size )
    {
        sr_s_asm(result,x_btcl_function_s_setup_wrapped_function(x_btcl_function_s_create(),o, arg_list) );
        return  0;
    }
    else if( arg_list->size == signature->arg_list.size )
    {
        if( o->block )
        {BLM_INIT_LEVEL(3);
            x_btcl_frame_s* frame = ((x_btcl_frame_s*)BLM_LEVEL_T_PUSH(3,x_btcl_frame_s,x_btcl_frame_s_create()));
            BLM_TRY(x_btcl_function_s_setup_frame(o,lexical_frame, source_point, frame ))
            for(sz_t i = 0; i < signature->arg_list.size; i++ ) sr_s_fork_from(x_btcl_frame_s_var_set(frame,signature->arg_list.data[ i ], sr_null() ),&(arg_list->data[ i ] ));
            sr_s_clear(result);
            BLM_TRY(x_btcl_block_s_eval(o->block,frame, result ))
            x_btcl_clone_if_weak(result );
        BLM_DOWN();}
        else if( o->external_function )
        {
            BLM_TRY(x_btcl_external_function_s_execute(o->external_function,source_point, lexical_frame, arg_list, result ))
        }
        else if( o->wrapped_function )
        {BLM_INIT_LEVEL(4);
            bcore_arr_sr_s* full_arg_list = ((bcore_arr_sr_s*)BLM_LEVEL_T_PUSH(4,bcore_arr_sr_s,bcore_arr_sr_s_create()));
            for(sz_t i = 0; i < o->wrapped_arg_list->size; i++ ) sr_s_fork_from(bcore_arr_sr_s_push_sr(full_arg_list,sr_null() ),&(o->wrapped_arg_list->data[ i ] ));
            for(sz_t i = 0; i < arg_list->size          ; i++ ) sr_s_fork_from(bcore_arr_sr_s_push_sr(full_arg_list,sr_null() ),&(arg_list->data[ i ] ));
            BLM_TRY(x_btcl_function_s_call(o->wrapped_function,source_point, lexical_frame, full_arg_list, result ))
        BLM_DOWN();}
        else
        {
            BLM_TRY(x_source_point_s_parse_error_fa(source_point,"Internal error: Function is incomplete.\n" ))
        }
    
        // chain of functions ...
        if( o->tail )
        {
            BLM_TRY(x_btcl_function_s_call_unary(o->tail,source_point, lexical_frame, result, result ))
        }
        return  0;
    }
    else
    {
        BLM_TRY(x_source_point_s_parse_error_fa(source_point,"Too many arguments. Function accepts #<sz_t> argument#<sc_t>.\n", signature->arg_list.size, signature->arg_list.size != 1 ? "s" : "" ))
    }
    return  0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %rbp
movq %rdi, %r12
movq 0x8(%rdi), %r14
movq 0x30(%r14), %rdx
cmpq %rdx, 0x10(%rcx)
jae 0x41a5b
callq 0x41729
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x417ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c408
xorl %ebp, %ebp
jmp 0x41d99
movq %rsi, %r8
jne 0x41b46
movq %r8, 0x18(%rsp)
cmpq $0x0, 0x10(%r12)
je 0x41b92
leaq 0xd6354(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x98(%rsp), %r15
movq %r15, 0x58(%rsp)
movq %r15, %rdi
callq 0x717f5
movq $0x3, 0x10(%r15)
callq 0x3a466
pushq $0x3
popq %rsi
movabsq $-0x8f0f83b86d2b0b3, %rdx # imm = 0xF70F07C4792D4F4D
movq %r15, %rdi
movq %rax, %rcx
callq 0x71967
movq %rax, %r15
movq %r12, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x41900
testq %rax, %rax
jne 0x41d2b
movq %rbp, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
movq %r15, 0x50(%rsp)
movq %r15, %rbp
addq $0x78, %rbp
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq 0x30(%r14), %rbx
jae 0x41bc5
movq 0x28(%r14), %rax
movq (%rax,%rbx,8), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x6f857
movq 0x8(%r13), %rsi
addq %r15, %rsi
movq %rax, %rdi
callq 0x8d2dd
incq %rbx
addq $0x18, %r15
jmp 0x41af3
cmpq $0x1, %rdx
leaq 0x84a7b(%rip), %rax     # 0xc65cc
leaq 0x751f4(%rip), %rcx     # 0xb6d4c
cmoveq %rax, %rcx
leaq 0x74557(%rip), %rsi     # 0xb60ba
xorl %ebp, %ebp
movq %r8, %rdi
xorl %eax, %eax
callq 0x41984
testq %rax, %rax
je 0x41d99
movq %rax, %rbx
leaq 0xd624e(%rip), %rax     # 0x117dd0
movq (%rax), %rdi
callq 0x71b64
movq %rbx, %rbp
jmp 0x41d99
movq 0x18(%r12), %rdi
testq %rdi, %rdi
movq %rbp, 0x28(%rsp)
je 0x41c09
movq 0x18(%rsp), %r15
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq 0x415d6
testq %rax, %rax
jne 0x41d87
jmp 0x41d5d
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2f2f4
movq 0x10(%r12), %rdi
movq 0x50(%rsp), %rsi
movq %rbx, %rdx
callq 0x3c554
testq %rax, %rax
jne 0x41d2b
movq %rbx, %rdi
callq 0x3c21d
leaq 0x58(%rsp), %rdi
callq 0x71b48
movq 0x18(%rsp), %r15
jmp 0x41d5d
cmpq $0x0, 0x20(%r12)
je 0x41d38
movq %rbx, 0x20(%rsp)
leaq 0xd61af(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x98(%rsp), %r15
movq %r15, 0x30(%rsp)
movq %r15, %rdi
callq 0x717f5
movq $0x4, 0x10(%r15)
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x5d23d
pushq $0x4
popq %rsi
movabsq $-0x78ea303a4f284a4, %rdx # imm = 0xF8715CFC5B0D7B5C
movq %r15, %rdi
movq %rax, %rcx
callq 0x71967
movq %rax, %rbp
xorl %ebx, %ebx
movq 0x28(%r12), %rax
cmpq 0x10(%rax), %rbx
jae 0x41cbd
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x5d3e3
movq 0x28(%r12), %rcx
movq 0x8(%rcx), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x8d2dd
incq %rbx
addq $0x18, %r14
jmp 0x41c68
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x18(%rsp), %r15
cmpq 0x10(%r13), %rbx
jae 0x41d09
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x5d3e3
movq 0x8(%r13), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x8d2dd
incq %rbx
addq $0x18, %r14
jmp 0x41cc7
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %rbx
movq %rbx, %r8
callq 0x41a08
testq %rax, %rax
je 0x41d53
movq %rax, %rbp
leaq 0x98(%rsp), %rdi
jmp 0x41d94
leaq 0x74352(%rip), %rsi     # 0xb6091
movq 0x18(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x41984
jmp 0x41bb7
leaq 0x30(%rsp), %rdi
callq 0x71b48
movq 0x30(%r12), %rdi
testq %rdi, %rdi
je 0x41a54
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rcx
movq %rbx, %r8
callq 0x40408
testq %rax, %rax
je 0x41a54
movq %rax, %rbp
leaq 0xd603f(%rip), %rax     # 0x117dd0
movq (%rax), %rdi
callq 0x71b64
movq %rbp, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq