// File: /workspace/github_c_makefile_star2_O2/heltilda[P]cicada/ciclib.c
// Function: cclib_call
void cclib_call()
{
    window *functionNameWindow;
    view argView;
    char **pointerList, **argvHandles;
    ccInt functionID, charCounter, argCounter, numArgs, numDataWindows, numStrings, theType;
    arg_info *infoList, *argvInfo;
    ccBool match;
    
    numArgs = numBIF_args();
    if (numArgs < 1)  {  setError(wrong_argument_count_err, pcCodePtr-1);  return;  }
    
    
        // get first argument:  the function name/ID number
    
    functionNameWindow = getBIFmember(1);
    if (functionNameWindow == NULL)  {  setError(void_member_err, pcCodePtr-1);  return;  }
    if (functionNameWindow->width != 1)  {  setError(multiple_indices_not_allowed_err, pcCodePtr-1);  return;  }
    
    
        // if the user passed a name, then find its position in the UserFunctions list
    
    theType = functionNameWindow->variable_ptr->type;
    if (theType == string_type)    {
        
        window *functionNameCharWindow = LL_member(functionNameWindow->variable_ptr, functionNameWindow->offset+1)->memberWindow; 
        linkedlist *functionNameString = &(functionNameCharWindow->variable_ptr->mem.data); 
        if (errCode != passed)  return;   
        
        for (functionID = 0; functionID < userFunctionsNum; functionID++)   {
            match = ccTrue;
            for (charCounter = functionNameCharWindow->offset; 
                            charCounter < functionNameCharWindow->offset+functionNameCharWindow->width; charCounter++)   {
                if ((*(char *) element(functionNameString, charCounter+1) != UserFunctions[functionID].functionName[charCounter]) ||
                                    (UserFunctions[functionID].functionName[charCounter] == 0))   {
                    {  match = ccFalse;  break;  }    // 2nd condition to prevent crash if 0 is in the functionID string
            }   }
            if (UserFunctions[functionID].functionName[charCounter] != 0)  match = ccFalse;
            if (match)  break;     }
        
        if (functionID == userFunctionsNum)
            {  setError(user_function_not_found_err, pcCodePtr-1);  return;  }    }
    
    
        // if the user passed the position directly, we have less work to do
    
    else if ((theType >= int_type) && (theType <= double_type))  {
        
        functionID = (ccInt) getBIFnumArg(1, 1., (ccFloat) userFunctionsNum) - 1;
        if (errCode == out_of_range_err)  errCode = user_function_not_found_err;
        if (errCode != passed)  return;     }
    
    else  {  setError(string_expected_err, pcCodePtr-1);  return;  }
    
    
        // Now count the number of primitive arrays to pass to the function (note that variables count as arrays of 1)
        // These come from arguments 2-the last.
    
    numDataWindows = 0;
    numStrings = 0;
    
    extCallMode = ccTrue;
    
    for (argCounter = 2; argCounter <= numArgs; argCounter++)  {
        argView.windowPtr = getBIFmember(argCounter);
        if (argView.windowPtr != NULL)   {
            argView.offset = argView.windowPtr->offset;
            argView.width = argView.windowPtr->width;
            countDataLists(&argView, (void *) &numDataWindows, (void *) &numStrings);
            if (errCode != passed)  break;
    }   }
    if (errCode != passed)  {  extCallMode = ccFalse;  return;  }
    
    
        // Allocate space both for our argument pointers and for the info list that Cicada provides.
    
    pointerList = (char **) malloc((numDataWindows+numStrings+1)*sizeof(char *));
    if (pointerList == NULL)  {  setError(out_of_memory_err, pcCodePtr-1);  extCallMode = ccFalse;  return;  }
    infoList = (arg_info *) malloc((numDataWindows+numStrings)*sizeof(arg_info) + 4);     //  avoid size-0 malloc
    if (infoList == NULL)  {  setError(out_of_memory_err, pcCodePtr-1);  extCallMode = ccFalse;  return;  }
    
    
        // Now fill the argument pointer/info lists.
    
    argvHandles = pointerList;
    argvInfo = infoList;
    for (argCounter = 2; argCounter <= numArgs; argCounter++)  {
        argView.windowPtr = getBIFmember(argCounter);
        if (argView.windowPtr != NULL)  {
            argView.offset = argView.windowPtr->offset;
            argView.width = argView.windowPtr->width;
            argvFillHandles(&argView, (void *) &argvHandles, (void *) &argvInfo);
            if (errCode != passed)  break;
    }   }
    pointerList[numDataWindows+numStrings] = (char *) infoList;
    
    
        // store the return value of the function in intRegister
    
    if (errCode == passed)
        intRegister = (ccInt) UserFunctions[functionID].functionPtr(numDataWindows+numStrings, (char **) pointerList);
    
    
        // fix the string windows (in case the string linked lists were resized) and clean up
    
    argvHandles = pointerList;
    for (argCounter = 2; argCounter <= numArgs; argCounter++)  {
        argView.windowPtr = getBIFmember(argCounter);
        if (argView.windowPtr != NULL)  {
            argView.offset = argView.windowPtr->offset;
            argView.width = argView.windowPtr->width;
            argvFixStrings(&argView, (void *) &argvHandles, NULL);
    }   }
    
    free((void *) pointerList);
    free((void *) infoList);
    
    extCallMode = ccFalse;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
callq 0x170b2
testl %eax, %eax
jle 0x146ec
movl %eax, %r13d
pushq $0x1
popq %rdi
callq 0x170f5
testq %rax, %rax
je 0x14702
cmpl $0x1, 0x1c(%rax)
jne 0x14718
movq 0x10(%rax), %rdi
movl 0xc0(%rdi), %ecx
cmpl $0x4, %ecx
jne 0x14740
addq $0x10, %rdi
movl 0x18(%rax), %esi
incl %esi
callq 0x9088
leaq 0x10153(%rip), %rcx     # 0x24760
cmpl $0x0, 0x18(%rcx)
jne 0x14847
movq (%rax), %r15
movq 0x10(%r15), %rax
addq $0x10, %rax
movq %rax, 0x10(%rsp)
leaq 0x57de(%rip), %rax      # 0x19e0c
movl (%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %ebx
movl %eax, 0x20(%rsp)
cmovgl %eax, %ebx
movl %r13d, 0x24(%rsp)
movq %rbx, 0x18(%rsp)
cmpq %rbx, %rcx
je 0x147a1
movslq 0x18(%r15), %rax
movq %rcx, 0x28(%rsp)
movq %rcx, %r13
shlq $0x4, %r13
addq 0xc96e(%rip), %r13      # 0x20fd8
movq %rax, %rdx
shlq $0x20, %rdx
leal 0x1(%rax), %ebp
movq %rax, %r12
movq %rdx, %rbx
movslq 0x18(%r15), %rax
movslq 0x1c(%r15), %r14
addq %rax, %r14
cmpq %r14, %r12
jge 0x146be
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x9088
movq (%r13), %rcx
movb (%rcx,%r12), %sil
cmpb %sil, (%rax)
jne 0x146c2
leaq 0x1(%r12), %rax
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rbx, %rdx
incl %ebp
testb %sil, %sil
jne 0x14674
jmp 0x146c2
movq (%r13), %rcx
cmpq %r14, %r12
movl 0x24(%rsp), %r13d
jl 0x146da
sarq $0x20, %rbx
cmpb $0x0, (%rcx,%rbx)
je 0x1479c
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rbx
jmp 0x1464a
leaq 0x1006d(%rip), %rax     # 0x24760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
pushq $0x2d
jmp 0x1472c
leaq 0x10057(%rip), %rax     # 0x24760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
pushq $0x1a
jmp 0x1472c
leaq 0x10041(%rip), %rax     # 0x24760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
pushq $0x1f
popq %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc7c2
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x14786
leaq 0x56bd(%rip), %rax      # 0x19e0c
cvtsi2sdl (%rax), %xmm1
pushq $0x1
popq %rdi
movsd 0x48aa(%rip), %xmm0     # 0x19008
callq 0x1715f
leaq 0xfff6(%rip), %rax      # 0x24760
movl 0x18(%rax), %ecx
testl %ecx, %ecx
je 0x147c0
cmpl $0x2, %ecx
jne 0x14847
movl $0x2c, 0x18(%rax)
jmp 0x14847
leaq 0xffd3(%rip), %rax      # 0x24760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
pushq $0x25
jmp 0x1472c
movq 0x28(%rsp), %rbx
cmpl 0x20(%rsp), %ebx
jne 0x147c6
leaq 0xffb2(%rip), %rax      # 0x24760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
pushq $0x2c
jmp 0x1472c
cvttsd2si %xmm0, %ebx
decl %ebx
leaq 0xc(%rsp), %r14
andl $0x0, (%r14)
leaq 0x8(%rsp), %r15
andl $0x0, (%r15)
leaq 0xff81(%rip), %rax      # 0x24760
movb $0x1, 0x2a8(%rax)
pushq $0x2
popq %rbp
leaq 0x30(%rsp), %r12
cmpl %r13d, %ebp
jg 0x1482c
movl %ebp, %edi
callq 0x170f5
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x14828
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xd7fa
leaq 0xff3e(%rip), %rax      # 0x24760
cmpl $0x0, 0x18(%rax)
jne 0x14839
incl %ebp
jmp 0x147ee
leaq 0xff2d(%rip), %rax      # 0x24760
cmpl $0x0, 0x18(%rax)
je 0x14856
leaq 0xff20(%rip), %rax      # 0x24760
movb $0x0, 0x2a8(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x18(%rsp)
movslq 0xc(%rsp), %rax
movslq 0x8(%rsp), %rbx
addq %rax, %rbx
leaq 0x8(,%rbx,8), %rdi
callq 0x81d0
testq %rax, %rax
je 0x148f1
movq %rax, %r14
movslq %ebx, %rax
leaq 0x4(,%rax,8), %rdi
callq 0x81d0
testq %rax, %rax
je 0x148f1
leaq 0x48(%rsp), %r12
movq %r14, %rbx
movq %r14, (%r12)
leaq 0x50(%rsp), %r14
movq %rax, 0x10(%rsp)
movq %rax, (%r14)
pushq $0x2
popq %rbp
leaq 0x30(%rsp), %r15
cmpl %r13d, %ebp
jg 0x14917
movl %ebp, %edi
callq 0x170f5
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x148ed
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xd833
leaq 0xfe79(%rip), %rax      # 0x24760
cmpl $0x0, 0x18(%rax)
jne 0x14927
incl %ebp
jmp 0x148b3
leaq 0xfe68(%rip), %rbx      # 0x24760
movq 0xb8(%rbx), %rsi
addq $-0x4, %rsi
pushq $0x1
popq %rdi
callq 0xc7c2
movb $0x0, 0x2a8(%rbx)
jmp 0x14847
leaq 0xfe42(%rip), %rax      # 0x24760
cmpl $0x0, 0x18(%rax)
sete %al
jmp 0x14929
xorl %eax, %eax
movslq 0xc(%rsp), %rcx
movslq 0x8(%rsp), %rdi
addq %rcx, %rdi
movq 0x10(%rsp), %rcx
movq %rcx, (%rbx,%rdi,8)
testb %al, %al
je 0x14964
movslq 0x18(%rsp), %rax
shlq $0x4, %rax
leaq 0xf74d(%rip), %rcx      # 0x240a0
movq %rbx, %rsi
callq *0x8(%rcx,%rax)
leaq 0xfdff(%rip), %rcx      # 0x24760
movl %eax, 0x6c(%rcx)
leaq 0x48(%rsp), %r12
movq %rbx, (%r12)
pushq $0x2
popq %rbp
leaq 0x30(%rsp), %r15
cmpl %r13d, %ebp
jg 0x149a5
movl %ebp, %edi
callq 0x170f5
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x149a1
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xde36
incl %ebp
jmp 0x14975
movq %rbx, %rdi
callq 0x81c0
movq 0x10(%rsp), %rdi
callq 0x81c0
jmp 0x14839