// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
callq 0x1fa40
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jge 0x1ba6a
leaq 0x10d00(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x2d, %edi
callq 0xf740
jmp 0x1bf46
movl $0x1, %edi
callq 0x1fab0
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x1baa0
leaq 0x10cca(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1a, %edi
callq 0xf740
jmp 0x1bf46
movq -0x8(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
je 0x1bacb
leaq 0x10c9f(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1f, %edi
callq 0xf740
jmp 0x1bf46
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x4, -0x4c(%rbp)
jne 0x1bc40
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x10, %rdi
movq -0x8(%rbp), %rax
movl 0x18(%rax), %esi
addl $0x1, %esi
callq 0x9700
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x10, %rax
movq %rax, -0x78(%rbp)
leaq 0x10c31(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1bb2a
jmp 0x1bf46
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
leaq 0x7261(%rip), %rcx      # 0x22d9c
cmpl (%rcx), %eax
jge 0x1bc0c
movb $0x1, -0x61(%rbp)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x70(%rbp), %rcx
movl 0x18(%rcx), %ecx
movq -0x70(%rbp), %rdx
addl 0x1c(%rdx), %ecx
cmpl %ecx, %eax
jge 0x1bbce
movq -0x78(%rbp), %rdi
movl -0x38(%rbp), %esi
addl $0x1, %esi
callq 0x9700
movsbl (%rax), %eax
movslq -0x34(%rbp), %rdx
leaq 0x1050d(%rip), %rcx     # 0x2c090
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movslq -0x38(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x1bbbb
movslq -0x34(%rbp), %rcx
leaq 0x104ec(%rip), %rax     # 0x2c090
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1bbc1
movb $0x0, -0x61(%rbp)
jmp 0x1bbce
jmp 0x1bbc3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1bb51
movslq -0x34(%rbp), %rcx
leaq 0x104b7(%rip), %rax     # 0x2c090
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1bbf4
movb $0x0, -0x61(%rbp)
cmpb $0x0, -0x61(%rbp)
je 0x1bbfc
jmp 0x1bc0c
jmp 0x1bbfe
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1bb31
movl -0x34(%rbp), %eax
leaq 0x7186(%rip), %rcx      # 0x22d9c
cmpl (%rcx), %eax
jne 0x1bc3b
leaq 0x10b2f(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x2c, %edi
callq 0xf740
jmp 0x1bf46
jmp 0x1bcc5
cmpl $0x2, -0x4c(%rbp)
jl 0x1bca2
cmpl $0x3, -0x4c(%rbp)
jg 0x1bca2
leaq 0x7149(%rip), %rax      # 0x22d9c
cvtsi2sdl (%rax), %xmm1
movl $0x1, %edi
movsd 0x63a4(%rip), %xmm0     # 0x22008
callq 0x1fb80
cvttsd2si %xmm0, %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
leaq 0x10ad6(%rip), %rax     # 0x2c750
cmpl $0x2, 0x18(%rax)
jne 0x1bc8e
leaq 0x10ac9(%rip), %rax     # 0x2c750
movl $0x2c, 0x18(%rax)
leaq 0x10abb(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1bca0
jmp 0x1bf46
jmp 0x1bcc3
leaq 0x10aa7(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x25, %edi
callq 0xf740
jmp 0x1bf46
jmp 0x1bcc5
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
leaq 0x10a76(%rip), %rax     # 0x2c750
movb $0x1, 0x2a8(%rax)
movl $0x2, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x1bd46
movl -0x3c(%rbp), %edi
callq 0x1fab0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1bd39
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x44(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x115f0
leaq 0x10a21(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1bd37
jmp 0x1bd46
jmp 0x1bd39
jmp 0x1bd3b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1bce8
leaq 0x10a03(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1bd66
leaq 0x109f6(%rip), %rax     # 0x2c750
movb $0x0, 0x2a8(%rax)
jmp 0x1bf46
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x81d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1bdb5
leaq 0x109c3(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1, %edi
callq 0xf740
leaq 0x109a7(%rip), %rax     # 0x2c750
movb $0x0, 0x2a8(%rax)
jmp 0x1bf46
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
addq $0x4, %rdi
callq 0x81d0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x1be05
leaq 0x10973(%rip), %rax     # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1, %edi
callq 0xf740
leaq 0x10957(%rip), %rax     # 0x2c750
movb $0x0, 0x2a8(%rax)
jmp 0x1bf46
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x2, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x1be7a
movl -0x3c(%rbp), %edi
callq 0x1fab0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1be6d
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x11690
leaq 0x108ed(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1be6b
jmp 0x1be7a
jmp 0x1be6d
jmp 0x1be6f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1be1c
movq -0x58(%rbp), %rdx
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0x108ba(%rip), %rax     # 0x2c750
cmpl $0x0, 0x18(%rax)
jne 0x1beca
movslq -0x34(%rbp), %rcx
leaq 0x101e9(%rip), %rax     # 0x2c090
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl -0x44(%rbp), %edi
addl -0x48(%rbp), %edi
movq -0x28(%rbp), %rsi
callq *%rax
movl %eax, %ecx
leaq 0x10889(%rip), %rax     # 0x2c750
movl %ecx, 0x6c(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x2, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x1bf26
movl -0x3c(%rbp), %edi
callq 0x1fab0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1bf19
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x11ff0
jmp 0x1bf1b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1bed9
movq -0x28(%rbp), %rdi
callq 0x81c0
movq -0x58(%rbp), %rdi
callq 0x81c0
leaq 0x10811(%rip), %rax     # 0x2c750
movb $0x0, 0x2a8(%rax)
addq $0x80, %rsp
popq %rbp
retq
nop