// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_expr.c
// Function: parsePrimary
static void parsePrimary(Compiler *comp, const Ident *ident, const Type **type, Const *constant, bool *isVar, bool *isCall)
{
    switch (ident->kind)
    {
        case IDENT_CONST:
        {
            if (constant)
                *constant = ident->constant;
            else
                doPushConst(comp, ident->type, &ident->constant);

            *type = ident->type;
            *isVar = false;
            *isCall = false;
            lexNext(&comp->lex);
            break;
        }

        case IDENT_VAR:
        {
            if (constant)
                comp->error.handler(comp->error.context, "Constant expected but variable %s found", ident->name);

            doPushVarPtr(comp, ident);

            if (typeStructured(ident->type))
                *type = ident->type;
            else
                *type = typeAddPtrTo(&comp->types, &comp->blocks, ident->type);
            *isVar = true;
            *isCall = false;
            lexNext(&comp->lex);
            break;
        }

        // Built-in function call
        case IDENT_BUILTIN_FN:
        {
            lexNext(&comp->lex);
            parseBuiltinCall(comp, type, constant, ident->builtin);

            // Copy result to a temporary local variable to collect it as garbage when leaving the block
            if (typeGarbageCollected(*type) && ident->builtin != BUILTIN_SELFPTR && ident->builtin != BUILTIN_TYPEPTR)
                doCopyResultToTempVar(comp, *type);

            *isVar = false;
            *isCall = true;
            break;
        }

        default: comp->error.handler(comp->error.context, "Unexpected identifier %s", ident->name);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
testl %eax, %eax
je 0x108de
jmp 0x108bf
movl -0x34(%rbp), %eax
subl $0x1, %eax
je 0x1094d
jmp 0x108cd
movl -0x34(%rbp), %eax
subl $0x3, %eax
je 0x10a07
jmp 0x10a7e
cmpq $0x0, -0x20(%rbp)
je 0x108f9
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x120(%rcx), %rcx
movq %rcx, (%rax)
jmp 0x10918
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x108(%rax), %rsi
movq -0x10(%rbp), %rdx
addq $0x120, %rdx            # imm = 0x120
callq 0xce30
movq -0x10(%rbp), %rax
movq 0x108(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
jmp 0x10aa7
cmpq $0x0, -0x20(%rbp)
je 0x1097d
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x4, %rdx
leaq 0x1c8307(%rip), %rsi    # 0x1d8c80
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xd010
movq -0x10(%rbp), %rax
movq 0x108(%rax), %rdi
callq 0xcfa0
testb $0x1, %al
jne 0x109a0
jmp 0x109b4
movq -0x10(%rbp), %rax
movq 0x108(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x109e4
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movq -0x10(%rbp), %rax
movq 0x108(%rax), %rdx
callq 0x21fa0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movb $0x1, (%rax)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
jmp 0x10aa7
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x120(%rax), %ecx
callq 0x10d50
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0xee80
testb $0x1, %al
jne 0x10a44
jmp 0x10a6e
movq -0x10(%rbp), %rax
cmpl $0x26, 0x120(%rax)
je 0x10a6e
movq -0x10(%rbp), %rax
cmpl $0x29, 0x120(%rax)
je 0x10a6e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0xd070
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
movb $0x1, (%rax)
jmp 0x10aa7
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x4, %rdx
leaq 0x1c8205(%rip), %rsi    # 0x1d8ca8
movb $0x0, %al
callq *%rcx
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)