// File: /workspace/github_cpp_makefile_star2_O1/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 0x2c6d
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 0x2bfd
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 0x2c0e
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
cmpb $0x1, 0x5553(%rip)      # 0x8168
jne 0x2c4e
movq %r13, %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0x25ea
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c4e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2180
leaq 0x5533(%rip), %rdi      # 0x8188
movq %rsp, %rsi
callq 0x3886
incq %rbx
addq $0x10, %r12
cmpq %rbx, %rbp
jne 0x2b8d
movq 0x5514(%rip), %r14      # 0x8188
movq 0x5515(%rip), %r15      # 0x8190
cmpq %r15, %r14
je 0x2cbb
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 0x3bff
movq %r14, %rdi
movq %r15, %rsi
callq 0x3cdb
cmpb $0x1, 0x54c2(%rip)      # 0x8184
jne 0x300e
movq 0x5301(%rip), %rdi      # 0x7fd0
leaq 0x2425(%rip), %rsi      # 0x50fb
movl $0x17, %edx
callq 0x21a0
movq 0x52e9(%rip), %rdi      # 0x7fd0
movq %rbp, %rsi
callq 0x20f0
movq %rax, %rbx
leaq 0x241a(%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 0x529c(%rip), %rbx      # 0x7fd0
leaq 0x23e2(%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 0x526a(%rip), %rdi      # 0x7fd0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movq 0x5256(%rip), %rbx      # 0x7fd0
leaq 0x240b(%rip), %rsi      # 0x518c
movl $0x23, %edx
movq %rbx, %rdi
callq 0x21a0
movq 0x53f3(%rip), %r14      # 0x8188
cmpq %r14, 0x53f4(%rip)      # 0x8190
je 0x2ff9
movl $0x4, %r15d
xorl %r12d, %r12d
movl (%r14,%r15), %eax
cmpl $0x100000, %eax         # imm = 0x100000
movl $0x80, %ebp
movl $0x400, %ecx            # imm = 0x400
cmovael %ecx, %ebp
cmpl $0x1, 0xc(%r14,%r15)
jne 0x2fc6
movl 0x4(%r14,%r15), %r13d
movl %eax, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2569
cmpl %ebp, %r13d
jle 0x2e05
cmpb $0x1, 0x5392(%rip)      # 0x8181
jne 0x2e05
movl $0x5, %edx
movq %rbx, %rdi
leaq 0x220a(%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), %rax
movq %r13, %rbp
addq %rax, %rbp
cmpb $0x0, 0xe1(%r13,%rax)
jne 0x2e65
movq %rbp, %rdi
movl $0x20, %esi
callq 0x2160
movb %al, 0xe0(%rbp)
movb $0x1, 0xe1(%rbp)
movb $0x20, 0xe0(%rbp)
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x6, 0x10(%r13,%rax)
movl 0x4(%r14,%r15), %esi
movq %r13, %rdi
callq 0x2250
cmpb $0x1, 0x52f0(%rip)      # 0x8181
jne 0x2ea7
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x216e(%rip), %rsi      # 0x5010
callq 0x21a0
movl 0x8(%r14,%r15), %eax
leaq 0x232a(%rip), %rsi      # 0x51dd
cmpq $0x4, %rax
ja 0x2ec7
leaq 0x262c(%rip), %rcx      # 0x54ec
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movl $0x8, %edx
movq %rbx, %rdi
callq 0x21a0
movl 0x10(%r14,%r15), %eax
testl %eax, %eax
je 0x2efb
leaq 0x2302(%rip), %rsi      # 0x51e6
cmpl $0xfff1, %eax           # imm = 0xFFF1
je 0x2f02
cmpl $0xfff2, %eax           # imm = 0xFFF2
jne 0x2f11
leaq 0x22f2(%rip), %rsi      # 0x51eb
jmp 0x2f02
leaq 0x22ee(%rip), %rsi      # 0x51f0
movl $0x4, %edx
movq %rbx, %rdi
callq 0x21a0
jmp 0x2f76
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 0x2f61
movq %r13, %rdi
movl $0x20, %esi
callq 0x2160
movb %al, 0xe0(%r13)
movb $0x1, 0xe1(%r13)
movb $0x20, 0xe0(%r13)
movl 0x10(%r14,%r15), %esi
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
incq %r12
movq 0x51c0(%rip), %rax      # 0x8190
movq 0x51b1(%rip), %r14      # 0x8188
subq %r14, %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rax
addq $0x38, %r15
cmpq %rax, %r12
jb 0x2dab
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 0x302a
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 0x3041
jmp 0x3041
jmp 0x3041
jmp 0x3041
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3060
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2280