// File: /workspace/github_cpp_makefile_star2_O2/baziotis[P]minijava-cpp/parse.cpp
// Function: parse_expr_primary()
static Expression *parse_expr_primary() {
    if (match_token(TOK::LPAR)) {
        Expression *expr = parse_expr();
        expect_token(TOK::RPAR);
        return expr;
    }
    Expression *expr = new Expression;
    expr->loc = loc;
    switch (token.kind) {
    case TOK::FALSE:
    {
        next_token();
        expr->kind = EXPR::BOOL_LIT;
        expr->lit_val = 0;
    } break;
    case TOK::ID:
    {
        expr->kind = EXPR::ID;
        expr->id = token.id;
        next_token();
    } break;
    case TOK::INTLIT:
    {
        expr->kind = EXPR::INT_LIT;
        expr->lit_val = token.val;
        next_token();
    } break;
    case TOK::THIS:
    {
        next_token();
        expr->kind = EXPR::THIS;
    } break;
    case TOK::NEW:
    {
        next_token();
        if (match_token(TOK::INT)) { // ArrayAllocationExpression
            expr->kind = EXPR::ARR_ALLOC;
            expect_token_in_rule(TOK::LBRACKET, "array allocation expression");
            expr->e1 = parse_expr();
            expect_token_in_rule(TOK::RBRACKET, "array allocation expression");
        } else if (is_token(TOK::ID)) {
            expr->kind = EXPR::ALLOC;
            expr->id = token.id;
            next_token();
            expect_token_in_rule(TOK::LPAR, "allocation expression");
            expect_token_in_rule(TOK::RPAR, "allocation expression");
        }
    } break;
    case TOK::TRUE:
    {
        next_token();
        expr->kind = EXPR::BOOL_LIT;
        expr->lit_val = 1;
    } break;
    default:
    {
        syntax_error("An expression can't start with: `", token, "`");
        expr->kind = EXPR::UNDEFINED;
    }
    }
    return expr;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
pushq $0x3
popq %rdi
callq 0x5d0d
testb %al, %al
je 0x6b76
callq 0x67e3
movq %rax, %rbx
pushq $0x19
popq %rdi
callq 0x6744
jmp 0x6ce0
pushq $0x18
popq %rdi
callq 0x6f0a
movq %rax, %rbx
leaq 0x11b08(%rip), %rax     # 0x18690
movl (%rax), %edi
movl %edi, (%rbx)
leaq 0x11b05(%rip), %r15     # 0x18698
movl (%r15), %r14d
leal -0x12(%r14), %eax
cmpl $0x3, %eax
ja 0x6bc7
leaq 0x8c52(%rip), %rcx      # 0xf7f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x351d
movl $0xc, 0x4(%rbx)
movl $0x1, 0x10(%rbx)
jmp 0x6ce0
cmpl $0x2, %r14d
je 0x6be4
cmpl $0x8, %r14d
jne 0x6c0d
movl $0xa, 0x4(%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x10(%rbx)
jmp 0x6bf2
movl $0xb, 0x4(%rbx)
movl 0x8(%r15), %eax
movl %eax, 0x10(%rbx)
callq 0x351d
jmp 0x6ce0
callq 0x351d
movl $0xd, 0x4(%rbx)
jmp 0x6ce0
movq 0x8(%r15), %r15
callq 0x6085
callq 0x609f
callq 0x60bb
leaq 0x800f(%rip), %rdi      # 0xec36
callq 0x60d7
callq 0x60e8
callq 0x6104
leaq 0x9228(%rip), %rdi      # 0xfe65
leaq 0x8d9d(%rip), %rcx      # 0xf9e1
movl %r14d, %esi
movq %r15, %rdx
callq 0x618c
pushq $0xa
popq %rdi
callq 0x2160
andl $0x0, 0x4(%rbx)
jmp 0x6ce0
callq 0x351d
pushq $0x6
popq %rdi
callq 0x5d0d
testb %al, %al
je 0x6ca9
movl $0xe, 0x4(%rbx)
leaq 0x91ca(%rip), %r14      # 0xfe49
pushq $0x24
popq %rdi
movq %r14, %rsi
callq 0x5d30
callq 0x67e3
movq %rax, 0x10(%rbx)
pushq $0x1b
jmp 0x6cd7
callq 0x351d
movl $0xc, 0x4(%rbx)
andl $0x0, 0x10(%rbx)
jmp 0x6ce0
cmpl $0x8, (%r15)
jne 0x6ce0
movl $0xf, 0x4(%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x10(%rbx)
callq 0x351d
leaq 0x9185(%rip), %r14      # 0xfe4f
pushq $0x3
popq %rdi
movq %r14, %rsi
callq 0x5d30
pushq $0x19
popq %rdi
movq %r14, %rsi
callq 0x5d30
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq