// File: /workspace/github_cpp_makefile_star2_O3/coduin[P]epiphany-bin-info/epiphany-bin-info.cpp
// Function: parseSymbolTable(Elf32_Sym*, unsigned long, char const*, unsigned long)
void parseSymbolTable(Elf32_Sym* symbol, size_t count, const char* symstr,
                      size_t symstrsize) {
    Symbol sym;
    for (size_t i = 0; i < count; i++) {
        sym.index = i;
        sym.value = symbol[i].st_value;
        sym.size = symbol[i].st_size;
        sym.type = ELF32_ST_TYPE(symbol[i].st_info);
        sym.bind = ELF32_ST_BIND(symbol[i].st_info);
        sym.section = symbol[i].st_shndx;
        if (symbol[i].st_name < symstrsize)
            sym.name = ((char*)(&symstr[symbol[i].st_name]));
        else
            sym.name.clear();

        if (demangleNames)
            sym.name = demangle(sym.name);

        symbols.push_back(sym);
    }
    sort(symbols.begin(), symbols.end());

    if (showSymbols) {
        cout << "\nSymbol table contains " << count << " symbols." << endl;
        cout << "Showing only global symbols. Highlighting symbol sizes larger "
                "than 128 Bytes (local) or 1024 Bytes (external)."
             << endl;
        cout << "VALUE        SIZE TYPE    SEC NAME\n";
        for (size_t i = 0; i < symbols.size(); i++) {
            Symbol& sym = symbols[i];
            bool is_large = false;
            if (isExtmem(sym.value)) {
                is_large = sym.size > 1024;
            } else {
                is_large = sym.size > 128;
            }
            if (sym.bind == STB_GLOBAL) {
                cout << addr(sym.value);

                if (is_large)
                    outputSetPurple();
                cout << ' ' << dec << setfill(' ') << setw(6) << sym.size;
                outputReset();

                switch (sym.type) {
                case STT_NOTYPE:
                    cout << " NOTYPE ";
                    break;
                case STT_OBJECT:
                    cout << " OBJECT ";
                    break;
                case STT_FUNC:
                    cout << " FUNC   ";
                    break;
                case STT_SECTION:
                    cout << " SECTION";
                    break;
                case STT_FILE:
                    cout << " FILE   ";
                    break;
                default:
                    cout << " Unknown";
                    break;
                }

                switch (sym.section) {
                case SHN_ABS:
                    cout << " ABS";
                    break;
                case SHN_COMMON:
                    cout << " COM";
                    break;
                case SHN_UNDEF:
                    cout << " UND";
                    break;
                default:
                    cout << dec << setw(4) << setfill(' ') << sym.section;
                    break;
                }

                cout << ' ' << sym.name;
                cout << endl;
            }
        }
        cout << dec;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x60(%rsp)
movq %rsi, %rbp
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
testq %rsi, %rsi
je 0x2c5e
movq %rcx, %r14
movq %rdi, %r12
addq $0xe, %r12
xorl %ebx, %ebx
leaq 0x38(%rsp), %r13
movq %rcx, 0x58(%rsp)
movl %ebx, (%rsp)
movq -0xa(%r12), %rax
movq %rax, 0x4(%rsp)
movzbl -0x2(%r12), %eax
movl %eax, %ecx
andl $0xf, %ecx
movl %ecx, 0xc(%rsp)
shrl $0x4, %eax
movl %eax, 0x10(%rsp)
movzwl (%r12), %eax
movl %eax, 0x14(%rsp)
movl -0xe(%r12), %r15d
cmpq %r14, %r15
jae 0x2bee
addq 0x60(%rsp), %r15
movq %r13, %r14
movq %rbp, %r13
movq 0x20(%rsp), %rbp
movq %r15, %rdi
callq 0x20c0
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r13, %rbp
movq %r14, %r13
movq 0x58(%rsp), %r14
movq %r15, %rcx
movq %rax, %r8
callq 0x2220
jmp 0x2bff
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
cmpb $0x1, 0x5562(%rip)      # 0x8168
jne 0x2c3f
movq %r13, %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0x25e3
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c3f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0x5542(%rip), %rdi      # 0x8188
movq %rsp, %rsi
callq 0x3870
incq %rbx
addq $0x10, %r12
cmpq %rbx, %rbp
jne 0x2b7e
movq 0x5523(%rip), %r14      # 0x8188
movq 0x5524(%rip), %r15      # 0x8190
cmpq %r15, %r14
je 0x2cac
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3bc5
movq %r14, %rdi
movq %r15, %rsi
callq 0x3ca1
cmpb $0x1, 0x54d1(%rip)      # 0x8184
jne 0x2ffe
movq 0x5310(%rip), %rdi      # 0x7fd0
leaq 0x2434(%rip), %rsi      # 0x50fb
movl $0x17, %edx
callq 0x21a0
movq 0x52f8(%rip), %rdi      # 0x7fd0
movq %rbp, %rsi
callq 0x20f0
movq %rax, %rbx
leaq 0x2429(%rip), %rsi      # 0x5113
movl $0x9, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x52ab(%rip), %rbx      # 0x7fd0
leaq 0x23f1(%rip), %rsi      # 0x511d
movl $0x6e, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x5279(%rip), %rdi      # 0x7fd0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x5265(%rip), %rbx      # 0x7fd0
leaq 0x241a(%rip), %rsi      # 0x518c
movl $0x23, %edx
movq %rbx, %rdi
callq 0x21a0
movq 0x540a(%rip), %rax      # 0x8190
movq 0x53fb(%rip), %r14      # 0x8188
cmpq %r14, %rax
je 0x2fe9
movl $0x4, %r15d
xorl %r12d, %r12d
movl (%r14,%r15), %ecx
cmpl $0x100000, %ecx         # imm = 0x100000
movl $0x80, %ebp
movl $0x400, %edx            # imm = 0x400
cmovael %edx, %ebp
cmpl $0x1, 0xc(%r14,%r15)
jne 0x2fc1
movl 0x4(%r14,%r15), %r13d
movl %ecx, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2562
cmpl %ebp, %r13d
jle 0x2dfa
cmpb $0x1, 0x539d(%rip)      # 0x8181
jne 0x2dfa
movl $0x5, %edx
movq %rbx, %rdi
leaq 0x2215(%rip), %rsi      # 0x500a
callq 0x21a0
movb $0x20, 0x38(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x21a0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r13,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%r13,%rcx)
movq -0x18(%rax), %rcx
movq %r13, %rbp
addq %rcx, %rbp
cmpb $0x0, 0xe1(%r13,%rcx)
jne 0x2e58
movq %rbp, %rdi
movl $0x20, %esi
callq 0x2160
movb $0x1, 0xe1(%rbp)
movq (%r13), %rax
movb $0x20, 0xe0(%rbp)
movq -0x18(%rax), %rax
movq $0x6, 0x10(%r13,%rax)
movl 0x4(%r14,%r15), %esi
movq %r13, %rdi
callq 0x2250
cmpb $0x1, 0x5301(%rip)      # 0x8181
jne 0x2e96
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x217f(%rip), %rsi      # 0x5010
callq 0x21a0
movl 0x8(%r14,%r15), %eax
leaq 0x233b(%rip), %rsi      # 0x51dd
cmpq $0x4, %rax
ja 0x2eb6
leaq 0x263d(%rip), %rcx      # 0x54ec
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21a0
movl 0x10(%r14,%r15), %esi
testl %esi, %esi
je 0x2eec
leaq 0x2313(%rip), %rax      # 0x51e6
cmpl $0xfff1, %esi           # imm = 0xFFF1
je 0x2ef3
cmpl $0xfff2, %esi           # imm = 0xFFF2
jne 0x2f05
leaq 0x2301(%rip), %rax      # 0x51eb
jmp 0x2ef3
leaq 0x22fd(%rip), %rax      # 0x51f0
movl $0x4, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x21a0
jmp 0x2f63
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
movq $0x4, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %r13
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0x2f53
movq %r13, %rdi
movl $0x20, %esi
callq 0x2160
movb $0x1, 0xe1(%r13)
movl 0x10(%r14,%r15), %esi
movb $0x20, 0xe0(%r13)
movq %rbx, %rdi
callq 0x2250
movb $0x20, 0x38(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x21a0
movq 0x14(%r14,%r15), %rsi
movq 0x1c(%r14,%r15), %rdx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x51d6(%rip), %rax      # 0x8190
movq 0x51c7(%rip), %r14      # 0x8188
incq %r12
movq %rax, %rcx
subq %r14, %rcx
sarq $0x3, %rcx
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rdx, %rcx
addq $0x38, %r15
cmpq %rcx, %r12
jb 0x2d9f
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x301a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3031
jmp 0x3031
jmp 0x3031
jmp 0x3031
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3050
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2280