// File: /workspace/github_cpp_makefile_star2_O2/fondoger[P]C0-Compiler/src/grammar.cpp
// Function: pFactor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, DataType&)
static void pFactor(std::string &res, DataType &res_dtype)
{
    std::string id, temp_var;
    std::stringstream ss;
    TabEntry entry;
    DataType temp_dtype;
    // For conveniency, we assume all identifiers here are non-void-function-call
    test3(Symset({IDENTSY, CHARVALUE, LPARENT, PLUS, MINUS, INTVALUE}));
    switch (g_sym) {
        case IDENTSY:   id = g_id;
                        readSymbol(); 
                        if (!tabFind(id, entry)) {
                            // undefined identifier
                            error(ERR_UNDEFINED_IDENTIFIER);
                            return;
                        }
                        // entry.itype might be:
                        // IT_FUNCTION, IT_ARRAY, IT_VARIABLE, IT_CONST

                        // 1. handle functions
                        if (entry.itype == IT_FUNCTION) {
                            pNonVoidFunctionCall(res, res_dtype, id, entry);
                            return;
                        } else if (g_sym == LPARENT) { 
                            // use function call on a not-a-function identifier
                            error(ERR_NOT_A_FUNCTION);
                            return;
                        }
                        // 2. handle arrays
                        if (entry.itype == IT_ARRAY) {
                            pArrayRead(res, res_dtype, id, entry);
                            return;
                        }
                        assert(entry.itype == IT_CONST || entry.itype == IT_VARIABLE);
                        assert(entry.dtype == DT_CHAR || entry.dtype == DT_INT);
                        // 3. handle consts variable
                        if (entry.itype == IT_CONST) {
                            // return consts' character directly
                            if (entry.dtype == DT_CHAR) {
                                res_dtype = DT_CHAR;
                                ss << '\'' << (char)entry.value << '\'';
                            } else {
                                res_dtype = DT_INT;
                                ss << entry.value;
                            }
                            res = ss.str();
                        } 
                        // 4. handle normal variable (int or char)
                        else {
                            // return identifier directly
                            res = id;
                            res_dtype = entry.dtype;
                        }
                        break;
        case CHARVALUE: readSymbol();
                        ss << '\'' << g_char << '\'';
                        res = ss.str();
                        res_dtype = DT_CHAR;
                        break;
        case LPARENT:   readSymbol();
                        pExpression(res, temp_dtype);
                        res_dtype = DT_INT;           // ('p') should be convert to int
                        test3(Symset({RPARENT}));
                        readSymbol();
                        break;
        default:        pSignedInteger();  // a signed integer is stored at g_num
                        ss << g_num;
                        res = ss.str();
                        res_dtype = DT_INT;
                        break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rsi, %r14
movq %rdi, %rbx
leaq -0xf0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x1a8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x340(%rbp), %rdi
callq 0x31f0
movups 0x86bd(%rip), %xmm0     # 0x16350
leaq -0x50(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x1100000014, %r15     # imm = 0x1100000014
movq %r15, 0x10(%rsi)
leaq -0x140(%rbp), %rdi
pushq $0x6
popq %rdx
callq 0xef20
movabsq $0x2600000022, %r12     # imm = 0x2600000022
leaq -0x90(%rbp), %rsi
movq %r12, (%rsi)
leaq -0x138(%rbp), %rdi
pushq $0x2
popq %rdx
callq 0xef20
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0x9f5f
leaq -0x50(%rbp), %rsi
movups 0x8658(%rip), %xmm0     # 0x16350
movaps %xmm0, (%rsi)
movq %r15, 0x10(%rsi)
leaq -0x90(%rbp), %rdi
pushq $0x6
popq %rdx
callq 0xef20
leaq 0x168fb(%rip), %r13     # 0x24610
movl (%r13), %eax
movq -0x90(%rbp), %rcx
btq %rax, %rcx
jae 0xde9e
cmpl $0x1d, %eax
je 0xde25
cmpl $0x10, %eax
je 0xddc1
testl %eax, %eax
jne 0xdea5
leaq 0x168cd(%rip), %rsi     # 0x24618
leaq -0x100(%rbp), %rdi
callq 0x3160
callq 0x13808
leaq -0x100(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x140e9
testb %al, %al
je 0xdeef
movl -0xa8(%rbp), %eax
cmpl $0x2, %eax
jne 0xdf54
cmpl $0x0, -0xa4(%rbp)
je 0xe204
leaq -0x100(%rbp), %rdi
callq 0x14064
movq %rax, %r15
cmpl $0x1d, (%r13)
jne 0xe22a
movq %r15, %rdi
callq 0xe5d7
movq (%r15), %rax
movq 0x8(%r15), %rsi
jmp 0xe265
callq 0x13808
leaq -0x330(%rbp), %rdi
pushq $0x27
popq %rsi
callq 0x32f0
leaq 0x1685c(%rip), %rcx     # 0x24638
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x32f0
pushq $0x27
popq %rsi
movq %rax, %rdi
callq 0x32f0
leaq -0x328(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x33d0
leaq -0x50(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3310
movq %r15, %rdi
callq 0x3498
movl $0x2, (%r14)
jmp 0xdf1e
callq 0x13808
leaq -0x154(%rbp), %rsi
movq %rbx, %rdi
callq 0xd7bf
movl $0x1, (%r14)
leaq -0x90(%rbp), %rsi
movl $0x1e, (%rsi)
leaq -0x130(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
leaq -0x50(%rbp), %rsi
movq %r12, (%rsi)
leaq -0x128(%rbp), %rdi
pushq $0x2
popq %rdx
callq 0xef20
movq -0x130(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x9f5f
leaq -0x90(%rbp), %rsi
movl $0x1e, (%rsi)
leaq -0x50(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
callq 0x13808
jmp 0xdf1e
callq 0xe508
leaq -0x330(%rbp), %rdi
leaq 0x16784(%rip), %rax     # 0x2463c
movl (%rax), %esi
callq 0x3420
leaq -0x328(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x33d0
leaq -0x50(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3310
movq %r15, %rdi
callq 0x3498
movl $0x1, (%r14)
jmp 0xdf1e
leaq 0x857d(%rip), %rsi      # 0x16473
leaq -0x198(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x30f0
leaq -0x198(%rbp), %rdi
callq 0xa247
leaq -0x198(%rbp), %rdi
callq 0x3498
leaq -0x340(%rbp), %rdi
callq 0x34a0
leaq -0x1b8(%rbp), %rdi
callq 0x3498
leaq -0x100(%rbp), %rdi
callq 0x3498
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r13), %ecx
cmpl $0x1d, %ecx
jne 0xdf89
leaq 0x8531(%rip), %rsi      # 0x16495
leaq -0x178(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x30f0
leaq -0x178(%rbp), %rdi
callq 0xa247
leaq -0x178(%rbp), %rdi
jmp 0xdf19
cmpl $0x3, %eax
jne 0xe346
cmpl $0x1f, %ecx
je 0xdfc0
leaq 0x8676(%rip), %rsi      # 0x16614
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x30f0
leaq -0x50(%rbp), %rdi
callq 0xa247
leaq -0x50(%rbp), %rdi
callq 0x3498
leaq -0x70(%rbp), %rsi
movl $0x1f, (%rsi)
leaq -0x150(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
leaq -0x90(%rbp), %rsi
movq %r12, (%rsi)
leaq -0x148(%rbp), %rdi
pushq $0x2
popq %rdx
callq 0xef20
movq -0x150(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x9f5f
leaq -0x70(%rbp), %rsi
movl $0x1f, (%rsi)
leaq -0x90(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
movq -0x90(%rbp), %rax
movl (%r13), %ecx
btq %rcx, %rax
jae 0xe3b9
callq 0x13808
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x90(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xd7bf
cmpl $0x1, -0xb8(%rbp)
je 0xe08d
leaq 0x85cd(%rip), %rsi      # 0x16638
leaq -0x70(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x30f0
leaq -0x70(%rbp), %rdi
callq 0xa247
leaq -0x70(%rbp), %rdi
callq 0x3498
leaq -0x90(%rbp), %rdi
leaq -0xb4(%rbp), %rsi
callq 0x10a5d
testb %al, %al
je 0xe0e8
movl -0xb4(%rbp), %eax
testl %eax, %eax
js 0xe0b6
cmpl -0xa0(%rbp), %eax
jl 0xe0e8
leaq 0x859c(%rip), %rsi      # 0x16659
leaq -0x120(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x30f0
leaq -0x120(%rbp), %rdi
callq 0xa247
leaq -0x120(%rbp), %rdi
callq 0x3498
leaq -0xe0(%rbp), %rdi
callq 0x1065a
leaq -0xe0(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3310
movq %r15, %rdi
callq 0x3498
movl -0xa4(%rbp), %eax
movl %eax, (%r14)
movl $0x17, -0x98(%rbp)
cmpl $0x1, %eax
leaq 0x852a(%rip), %rax      # 0x16655
leaq 0x7fb3(%rip), %rsi      # 0x160e5
cmoveq %rax, %rsi
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x30f0
leaq 0x11e10(%rip), %rcx     # 0x1ff60
leaq -0x98(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movq %rbx, %rdx
callq 0x100d0
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
callq 0x3498
movl $0xe, (%r14)
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq %rbx, %rcx
callq 0x100d0
leaq -0xb0(%rbp), %rsi
movl $0x20, (%rsi)
leaq -0xe0(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
leaq -0xc0(%rbp), %rsi
movq %r12, (%rsi)
leaq -0x98(%rbp), %rdi
pushq $0x2
popq %rdx
callq 0xef20
movq -0xe0(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x9f5f
leaq -0xb0(%rbp), %rsi
movl $0x20, (%rsi)
leaq -0xc0(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0xef20
callq 0x13808
jmp 0xe259
leaq 0x8347(%rip), %rsi      # 0x16552
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x30f0
leaq -0x50(%rbp), %rdi
callq 0xa247
leaq -0x50(%rbp), %rdi
jmp 0xdf19
movq 0x8(%r15), %rax
movq %rax, %rsi
cmpq (%r15), %rax
je 0xe265
leaq 0x833c(%rip), %rsi      # 0x16579
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x30f0
leaq -0x90(%rbp), %rdi
callq 0xa247
leaq -0x90(%rbp), %rdi
jmp 0xdf19
subq %rax, %rsi
movl $0xa, -0x120(%rbp)
sarq $0x2, %rsi
leaq -0x70(%rbp), %rdi
callq 0xf077
leaq 0x11cda(%rip), %rcx     # 0x1ff60
leaq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x100d0
leaq -0x70(%rbp), %rdi
callq 0x3498
leaq -0x70(%rbp), %rdi
callq 0x1065a
leaq -0x70(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3310
movq %r15, %rdi
callq 0x3498
movl -0xa4(%rbp), %eax
movl %eax, (%r14)
movl $0x17, -0x120(%rbp)
cmpl $0x1, %eax
leaq 0x8372(%rip), %rax      # 0x16655
leaq 0x7dfb(%rip), %rsi      # 0x160e5
cmoveq %rax, %rsi
leaq -0x70(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x30f0
leaq 0x11c5b(%rip), %rcx     # 0x1ff60
leaq -0x120(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movq %rbx, %rdx
callq 0x100d0
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x3498
movl $0xc, (%r14)
leaq 0x11c2e(%rip), %rdx     # 0x1ff60
leaq -0x70(%rbp), %rdi
movq %rdx, %rsi
movq %rbx, %rcx
callq 0x100d0
jmp 0xdf1e
cmpl $0x2, %eax
jae 0xe3fc
movl -0xa4(%rbp), %ecx
leal -0x1(%rcx), %edx
cmpl $0x2, %edx
jae 0xe41b
testl %eax, %eax
je 0xe382
leaq -0x100(%rbp), %rsi
movq %rbx, %rdi
callq 0x3160
movl -0xa4(%rbp), %eax
movl %eax, (%r14)
jmp 0xdf1e
leaq -0x330(%rbp), %rdi
cmpl $0x2, %ecx
jne 0xe3c3
movl $0x2, (%r14)
pushq $0x27
popq %rsi
callq 0x32f0
movsbl -0xa0(%rbp), %esi
movq %rax, %rdi
callq 0x32f0
pushq $0x27
popq %rsi
movq %rax, %rdi
callq 0x32f0
jmp 0xe3d5
callq 0x13808
jmp 0xdf1e
movl $0x1, (%r14)
movl -0xa0(%rbp), %esi
callq 0x3420
leaq -0x328(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x33d0
leaq -0x50(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
jmp 0xdf19
leaq 0x80c1(%rip), %rdi      # 0x164c4
leaq 0x7fda(%rip), %rsi      # 0x163e4
leaq 0x80e9(%rip), %rcx      # 0x164fa
movl $0x3bd, %edx            # imm = 0x3BD
callq 0x31c0
leaq 0x8100(%rip), %rdi      # 0x16522
leaq 0x7fbb(%rip), %rsi      # 0x163e4
leaq 0x80ca(%rip), %rcx      # 0x164fa
movl $0x3be, %edx            # imm = 0x3BE
callq 0x31c0
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0xe46c
jmp 0xe47f
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0xe46c
jmp 0xe47f
jmp 0xe4d9
jmp 0xe48b
jmp 0xe4d9
jmp 0xe47f
jmp 0xe47f
jmp 0xe47f
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x3498
jmp 0xe482
jmp 0xe47f
jmp 0xe47f
jmp 0xe47f
jmp 0xe47f
jmp 0xe4d9
jmp 0xe47f
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0xe4bb
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0xe4bb
jmp 0xe4d9
jmp 0xe49a
jmp 0xe4d9
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0xe4bb
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
jmp 0xe4bb
jmp 0xe4d9
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x3498
jmp 0xe4dc
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
jmp 0xe4d9
movq %rax, %rbx
jmp 0xe4e8
jmp 0xe4d9
movq %rax, %rbx
leaq -0x340(%rbp), %rdi
callq 0x34a0
leaq -0x1b8(%rbp), %rdi
callq 0x3498
leaq -0x100(%rbp), %rdi
callq 0x3498
movq %rbx, %rdi
callq 0x3430