// File: /workspace/github_c_makefile_star2_O2/msteveb[P]autosetup/./jimsh0.c
// Function: Jim_SetVariableLink
int Jim_SetVariableLink(Jim_Interp *interp, Jim_Obj *nameObjPtr,
    Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
{
    const char *varName;
    const char *targetName;
    Jim_CallFrame *framePtr;
    Jim_VarVal *vv;
    int len;
    int varnamelen;


    switch (SetVariableFromAny(interp, nameObjPtr)) {
        case JIM_DICT_SUGAR:

            Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
            return JIM_ERR;

        case JIM_OK:
            vv = nameObjPtr->internalRep.varValue.vv;

            if (vv->linkFramePtr == NULL) {
                Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
                return JIM_ERR;
            }


            vv->linkFramePtr = NULL;
            break;
    }



    varName = Jim_GetString(nameObjPtr, &varnamelen);

    if (varName[0] == ':' && varName[1] == ':') {
        while (*varName == ':') {
            varName++;
            varnamelen--;
        }

        framePtr = interp->topFramePtr;
    }
    else {
        framePtr = interp->framePtr;
    }

    targetName = Jim_GetString(targetNameObjPtr, &len);
    if (targetName[0] == ':' && targetName[1] == ':') {
        while (*targetName == ':') {
            targetName++;
            len--;
        }
        targetNameObjPtr = Jim_NewStringObj(interp, targetName, len);
        targetCallFrame = interp->topFramePtr;
    }
    Jim_IncrRefCount(targetNameObjPtr);

    if (framePtr->level < targetCallFrame->level) {
        Jim_SetResultFormatted(interp,
            "bad variable name \"%#s\": upvar won't create namespace variable that refers to procedure variable",
            nameObjPtr);
        Jim_DecrRefCount(interp, targetNameObjPtr);
        return JIM_ERR;
    }


    if (framePtr == targetCallFrame) {
        Jim_Obj *objPtr = targetNameObjPtr;


        while (1) {
            if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) {
                Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
                Jim_DecrRefCount(interp, targetNameObjPtr);
                return JIM_ERR;
            }
            if (SetVariableFromAny(interp, objPtr) != JIM_OK)
                break;
            vv = objPtr->internalRep.varValue.vv;
            if (vv->linkFramePtr != targetCallFrame)
                break;
            objPtr = vv->objPtr;
        }
    }


    Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);

    nameObjPtr->internalRep.varValue.vv->linkFramePtr = targetCallFrame;
    Jim_DecrRefCount(interp, targetNameObjPtr);
    return JIM_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, -0x38(%rbp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0xb6e9
testl %eax, %eax
je 0xba3e
cmpl $0x64, %eax
jne 0xba52
leaq 0x1b28b(%rip), %rsi     # 0x26cc4
jmp 0xbb62
movq 0x18(%r15), %rax
cmpq $0x0, 0x8(%rax)
je 0xbb5b
andq $0x0, 0x8(%rax)
leaq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x7fc7
movq %rax, %r13
pushq $0x58
popq %rax
cmpb $0x3a, (%r13)
jne 0xba8f
cmpb $0x3a, 0x1(%r13)
jne 0xba8f
movl -0x2c(%rbp), %ecx
decl %ecx
movb $0x3a, %dl
pushq $0x60
popq %rax
cmpb $0x3a, %dl
jne 0xba8f
movl %ecx, -0x2c(%rbp)
movb 0x1(%r13), %dl
incq %r13
decl %ecx
jmp 0xba7c
movq (%rbx,%rax), %r12
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
callq 0x7fc7
cmpb $0x3a, (%rax)
jne 0xbac5
cmpb $0x3a, 0x1(%rax)
movq -0x38(%rbp), %rcx
jne 0xbadd
movb $0x3a, %cl
movl -0x30(%rbp), %edx
cmpb $0x3a, %cl
jne 0xbacb
decl %edx
movl %edx, -0x30(%rbp)
movb 0x1(%rax), %cl
incq %rax
jmp 0xbab3
movq -0x38(%rbp), %rcx
jmp 0xbadd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7363
movq %rax, %r14
movq 0x60(%rbx), %rcx
incl 0x10(%r14)
movl 0x8(%r12), %eax
cmpl 0x8(%rcx), %eax
jge 0xbb10
leaq 0x1b24f(%rip), %rsi     # 0x26d41
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x68a7
movl 0x10(%r14), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%r14)
pushq $0x1
popq %r15
jmp 0xbb49
movq %r14, -0x40(%rbp)
movq %rcx, -0x38(%rbp)
cmpq %rcx, %r12
je 0xbb85
movq %rbx, %rdi
movq %r15, %rsi
movq -0x40(%rbp), %r14
movq %r14, %rdx
callq 0x8306
movq 0x18(%r15), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl 0x10(%r14), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%r14)
xorl %r15d, %r15d
cmpl $0x1, %eax
jg 0xbb73
movq %rbx, %rdi
movq %r14, %rsi
callq 0x73bf
jmp 0xbb73
leaq 0x1b1c1(%rip), %rsi     # 0x26d23
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x68a7
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0xa61a
cmpl -0x2c(%rbp), %eax
jne 0xbbb1
movq %r14, %rdi
callq 0x7340
movslq -0x2c(%rbp), %rdx
movq %rax, %rdi
movq %r13, %rsi
callq 0x6390
testl %eax, %eax
je 0xbbd7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb6e9
testl %eax, %eax
jne 0xbb1d
movq 0x18(%r14), %rax
cmpq %r12, 0x8(%rax)
jne 0xbb1d
movq (%rax), %r14
jmp 0xbb89
leaq 0x1b1c4(%rip), %rsi     # 0x26da2
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x7363
movq %rax, %r14
incl 0x10(%rax)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0xbc08
movq %rbx, %rdi
callq 0x73bf
movq %r14, (%rbx)
movq -0x40(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
pushq $0x1
popq %r15
cmpl $0x1, %eax
jg 0xbb73
movq %rbx, %rdi
jmp 0xbb54