// File: /workspace/github_cpp_makefile_star2_O2/Fohlen[P]cubescript-standalone/command.cpp
// Function: compilelookup(vector<unsigned int>&, char const*&, int)
static void compilelookup(vector<uint> &code, const char *&p, int ltype)
{
    char *lookup = NULL;
    int lookuplen = 0;
    switch(*++p)
    {
        case '(':
        case '[':
            if(!compileword(code, p, VAL_STR, lookup, lookuplen)) goto invalid;
            break;
        case '$':
            compilelookup(code, p, VAL_STR);
            break;
        case '\"':
            lookup = cutstring(p, lookuplen);
            goto lookupid;
        default:
        {
            lookup = cutword(p, lookuplen);
            if(!lookup) goto invalid;
        lookupid:
            ident *id = newident(lookup, IDF_UNKNOWN);
            if(id) switch(id->type)
            {
                case ID_VAR: code.add(CODE_IVAR|((ltype >= VAL_ANY ? VAL_INT : ltype)<<CODE_RET)|(id->index<<8)); goto done;
                case ID_FVAR: code.add(CODE_FVAR|((ltype >= VAL_ANY ? VAL_FLOAT : ltype)<<CODE_RET)|(id->index<<8)); goto done;
                case ID_SVAR: code.add(CODE_SVAR|((ltype >= VAL_ANY ? VAL_STR : ltype)<<CODE_RET)|(id->index<<8)); goto done;
                case ID_ALIAS: code.add((id->index < MAXARGS ? CODE_LOOKUPARG : CODE_LOOKUP)|((ltype >= VAL_ANY ? VAL_STR : ltype)<<CODE_RET)|(id->index<<8)); goto done;
                case ID_COMMAND:
                {
                    int comtype = CODE_COM, numargs = 0;
                    code.add(CODE_ENTER);
                    for(const char *fmt = id->args; *fmt; fmt++) switch(*fmt)
                    {
                        case 's': compilestr(code, NULL, 0, true); numargs++; break;
                        case 'i': compileint(code); numargs++; break;         
                        case 'b': compileint(code, INT_MIN); numargs++; break;
                        case 'f': compilefloat(code); numargs++; break;
                        case 't': compilenull(code); numargs++; break;
                        case 'e': compileblock(code); numargs++; break;
                        case 'r': compileident(code); numargs++; break;
                        case '$': compileident(code, id); numargs++; break;
                        case 'N': compileint(code, -1); numargs++; break;
                        case 'C': comtype = CODE_COMC; numargs = 1; goto endfmt;
                        case 'V': comtype = CODE_COMV; numargs = 2; goto endfmt;
                        case '1': case '2': case '3': case '4': break; 
                    }
                endfmt:
                    code.add(comtype|(ltype < VAL_ANY ? ltype<<CODE_RET : 0)|(id->index<<8));
                    code.add(CODE_EXIT|(ltype < VAL_ANY ? ltype<<CODE_RET : 0));
                    goto done;
                }
                default: goto invalid;
            }
            compilestr(code, lookup, lookuplen, true);
            break;
        }
    }
    code.add(CODE_LOOKUPU|((ltype < VAL_ANY ? ltype<<CODE_RET : 0)));
done:
    delete[] lookup;
    switch(ltype)
    {
        case VAL_CODE: code.add(CODE_COMPILE); break;
        case VAL_IDENT: code.add(CODE_IDENTU); break;
    }
    return;
invalid:
    switch(ltype)
    {
        case VAL_NULL: case VAL_ANY: compilenull(code); break;
        default: compileval(code, ltype, NULL, 0); break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rdi, %rbx
andq $0x0, -0x38(%rbp)
andl $0x0, -0x30(%rbp)
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
movzbl 0x1(%rax), %eax
cmpl $0x22, %eax
je 0xb570
cmpl $0x24, %eax
je 0xb55d
cmpl $0x5b, %eax
je 0xb539
cmpl $0x28, %eax
jne 0xb588
pushq $0x3
popq %rdx
leaq -0x38(%rbp), %rcx
leaq -0x30(%rbp), %r8
movq %rbx, %rdi
callq 0xaa72
testb %al, %al
je 0xb5e3
movq -0x38(%rbp), %r15
jmp 0xb617
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0xb4f7
xorl %r15d, %r15d
jmp 0xb617
leaq -0x30(%rbp), %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0xb490
movq %rax, %r15
movq %rax, -0x38(%rbp)
jmp 0xb5a3
leaq -0x30(%rbp), %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0xb840
movq %rax, %r15
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0xb5e3
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x3be8
testq %rax, %rax
je 0xb606
movq %rax, %r12
movl (%rax), %eax
cmpq $0x4, %rax
ja 0xb5e3
leaq 0x5ff3(%rip), %rcx      # 0x115b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %r14d, %eax
shll $0x6, %eax
orl $0x1a, %eax
cmpl $0x4, %r14d
pushq $0x5a
popq %rcx
jmp 0xb7d9
movq %rbx, %rdi
testl $0xfffffffb, %r14d      # imm = 0xFFFFFFFB
jne 0xb67e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb253
movl -0x30(%rbp), %edx
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb0b6
movl %r14d, %eax
shll $0x6, %eax
orl $0x21, %eax
cmpl $0x4, %r14d
pushq $0x21
popq %rcx
cmovll %eax, %ecx
leaq -0x2c(%rbp), %rsi
movl %ecx, (%rsi)
movq %rbx, %rdi
callq 0xd7c0
testq %r15, %r15
je 0xb645
movq %r15, %rdi
callq 0xf9a8
cmpl $0x7, %r14d
je 0xb65d
cmpl $0x5, %r14d
jne 0xb66f
leaq -0x2c(%rbp), %rsi
movl $0xa, (%rsi)
jmp 0xb667
leaq -0x2c(%rbp), %rsi
movl $0xe, (%rsi)
movq %rbx, %rdi
callq 0xd7c0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb88a
movl 0x3c(%r12), %eax
xorl %ecx, %ecx
cmpl $0x19, %eax
setl %cl
cmpl $0x3, %r14d
pushq $0x3
popq %rdx
cmovll %r14d, %edx
shll $0x6, %edx
leal (%rdx,%rcx,2), %ecx
shll $0x8, %eax
orl %ecx, %eax
orl $0x20, %eax
jmp 0xb7e6
cmpl $0x3, %r14d
pushq $0x3
popq %rax
cmovll %r14d, %eax
shll $0x6, %eax
movl 0x3c(%r12), %ecx
shll $0x8, %ecx
orl %eax, %ecx
orl $0x18, %ecx
jmp 0xb62a
leaq -0x2c(%rbp), %rsi
movl $0x3, (%rsi)
movq %rbx, %rdi
callq 0xd7c0
movq %r12, -0x40(%rbp)
movq 0x20(%r12), %r13
leaq 0x5ec7(%rip), %r12      # 0x115cc
movzbl (%r13), %eax
leal -0x62(%rax), %ecx
cmpl $0x7, %ecx
jbe 0xb74e
cmpl $0x24, %eax
je 0xb7b3
cmpl $0x4e, %eax
je 0xb7a6
cmpl $0x72, %eax
je 0xb79a
cmpl $0x73, %eax
je 0xb789
cmpl $0x74, %eax
je 0xb77f
testl %eax, %eax
je 0xb7f1
cmpl $0x43, %eax
je 0xb7f9
cmpl $0x56, %eax
jne 0xb7bf
jmp 0xb7f5
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movl $0x80000000, %esi       # imm = 0x80000000
jmp 0xb7ac
movq %rbx, %rdi
callq 0xb270
jmp 0xb7bf
xorps %xmm0, %xmm0
movq %rbx, %rdi
callq 0xbc5f
jmp 0xb7bf
movq %rbx, %rdi
xorl %esi, %esi
jmp 0xb7ac
movq %rbx, %rdi
callq 0xb253
jmp 0xb7bf
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0xb0b6
jmp 0xb7bf
movq %rbx, %rdi
xorl %esi, %esi
callq 0xb2d7
jmp 0xb7bf
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xb1fc
jmp 0xb7bf
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0xb309
incq %r13
jmp 0xb705
movl %r14d, %eax
shll $0x6, %eax
orl $0x1e, %eax
cmpl $0x4, %r14d
movl $0x9e, %ecx
cmovll %eax, %ecx
movl 0x3c(%r12), %eax
shll $0x8, %eax
orl %ecx, %eax
leaq -0x2c(%rbp), %rsi
movl %eax, (%rsi)
jmp 0xb630
pushq $0x10
jmp 0xb7fb
pushq $0x13
jmp 0xb7fb
pushq $0x12
popq %rax
movl %r14d, %ecx
shll $0x6, %ecx
xorl %r13d, %r13d
cmpl $0x4, %r14d
cmovll %ecx, %r13d
movq -0x40(%rbp), %rcx
movl 0x3c(%rcx), %ecx
shll $0x8, %ecx
orl %eax, %ecx
orl %r13d, %ecx
leaq -0x2c(%rbp), %r12
movl %ecx, (%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd7c0
orl $0x4, %r13d
movl %r13d, (%r12)
leaq -0x2c(%rbp), %rsi
jmp 0xb630