// File: /workspace/github_c_makefile_star2_O3/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, %rax
movq %rdi, %r12
movq 0x8(%rdi), %r15
movq 0x30(%r15), %rdx
cmpq %rdx, 0x10(%rcx)
jae 0x8de22
callq 0x8d94e
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x8db75
movq %rbx, %rdi
callq 0x107ca9
testq %r14, %r14
je 0x8dfd8
movq (%r14), %rdi
callq 0x1074f1
jmp 0x8dfda
movq %rsi, %r14
jne 0x8df8c
cmpq $0x0, 0x10(%r12)
movq %rax, 0x28(%rsp)
je 0x8dff0
leaq 0x10df8d(%rip), %rax    # 0x19bdd0
movq (%rax), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, 0x58(%rsp)
movq %rbp, %rdi
callq 0xd6675
movq $0x3, 0x10(%rbp)
callq 0x7f70d
movabsq $-0x8f0f83b86d2b0b3, %rdx # imm = 0xF70F07C4792D4F4D
movl $0x3, %esi
movq %rbp, %rdi
movq %rax, %rcx
callq 0xd68a8
movq %r12, %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movq %rax, 0x48(%rsp)
movq %rax, %rcx
callq 0x8dca6
testq %rax, %rax
jne 0x8e153
movq %r14, 0x50(%rsp)
movq %rbx, 0x20(%rsp)
cmpq $0x0, 0x30(%r15)
je 0x8df12
movq 0x48(%rsp), %rax
leaq 0x78(%rax), %rbp
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x28(%r15), %rax
movq (%rax,%rbx,8), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0xd4234
movq 0x8(%r13), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x107eb1
incq %rbx
addq $0x18, %r14
cmpq 0x30(%r15), %rbx
jb 0x8dec2
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
movq 0x48(%rsp), %r14
je 0x8df5c
movq 0x10(%rbx), %rax
movq %rax, 0x40(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0x30(%rsp)
testb $0x2, %al
je 0x8df4e
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x107590
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq 0x10(%r12), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x832b1
testq %rax, %rax
movq 0x50(%rsp), %r14
jne 0x8e153
movq %rbx, %rdi
callq 0x82aab
leaq 0x58(%rsp), %rdi
jmp 0x8e17b
cmpq $0x1, %rdx
leaq 0xba77e(%rip), %rax     # 0x148715
leaq 0xab982(%rip), %rcx     # 0x139920
cmoveq %rax, %rcx
leaq 0xaace5(%rip), %rsi     # 0x138c8e
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0x8dd3f
testq %rax, %rax
je 0x8e1bc
movq %rax, %rbx
leaq 0x10de08(%rip), %rax    # 0x19bdd0
movq (%rax), %rdi
callq 0xd6d2c
movq %rbx, %rbp
jmp 0x8e1bc
xorl %eax, %eax
movq %r14, (%rbx)
movq %rax, 0x8(%rbx)
movq $0x2, 0x10(%rbx)
xorl %ebp, %ebp
jmp 0x8e1bc
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x8e019
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq 0x8d3fb
testq %rax, %rax
jne 0x8e1aa
jmp 0x8e180
cmpq $0x0, 0x20(%r12)
je 0x8e160
movq %r14, %r15
movq %rbx, 0x20(%rsp)
leaq 0x10dd9c(%rip), %rax    # 0x19bdd0
movq (%rax), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
callq 0xd6675
movq $0x4, 0x10(%rbp)
xorl %eax, %eax
callq 0xbae9e
movabsq $-0x78ea303a4f284a4, %rdx # imm = 0xF8715CFC5B0D7B5C
movl $0x4, %esi
movq %rbp, %rdi
movq %rax, %rcx
callq 0xd68a8
movq %rax, %rbp
movq 0x28(%r12), %rax
cmpq $0x0, 0x10(%rax)
je 0x8e0df
xorl %r14d, %r14d
xorl %ebx, %ebx
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0xbb23d
movq 0x28(%r12), %rcx
movq 0x8(%rcx), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x107eb1
incq %rbx
movq 0x28(%r12), %rax
addq $0x18, %r14
cmpq 0x10(%rax), %rbx
jb 0x8e089
cmpq $0x0, 0x10(%r13)
je 0x8e12e
xorl %ebx, %ebx
xorl %r14d, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0xbb23d
movq 0x8(%r13), %rsi
addq %rbx, %rsi
movq %rax, %rdi
callq 0x107eb1
incq %r14
addq $0x18, %rbx
cmpq 0x10(%r13), %r14
jb 0x8e0eb
movq 0x20(%r12), %rdi
movq %r15, %r14
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %rbx
movq %rbx, %r8
callq 0x8ddc3
testq %rax, %rax
je 0x8e176
movq %rax, %rbp
leaq 0x98(%rsp), %rdi
jmp 0x8e1b7
leaq 0xaaafe(%rip), %rsi     # 0x138c65
movq %r14, %rdi
xorl %eax, %eax
callq 0x8dd3f
jmp 0x8e00b
leaq 0x30(%rsp), %rdi
callq 0xd6d0d
movq 0x30(%r12), %rdi
testq %rdi, %rdi
je 0x8dfe9
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rcx
movq %rbx, %r8
callq 0x899ec
testq %rax, %rax
je 0x8dfe9
movq %rax, %rbp
leaq 0x10dc1c(%rip), %rax    # 0x19bdd0
movq (%rax), %rdi
callq 0xd6d2c
movq %rbp, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq