// File: /workspace/github_cpp_makefile_star2_O2/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 %rcx, %r15
movq %rdx, 0x8(%rsp)
movq %rsi, %r14
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %r13
movb $0x0, (%rax)
addq $0xe, %r13
xorl %ebx, %ebx
leaq 0x48(%rsp), %rbp
cmpq %rbx, %r14
je 0x29d9
movl %ebx, 0x10(%rsp)
movq -0xa(%r13), %rax
movq %rax, 0x14(%rsp)
movzbl -0x2(%r13), %eax
movl %eax, %ecx
andl $0xf, %ecx
movl %ecx, 0x1c(%rsp)
shrl $0x4, %eax
movl %eax, 0x20(%rsp)
movzwl (%r13), %eax
movl %eax, 0x24(%rsp)
movl -0xe(%r13), %esi
cmpq %r15, %rsi
jae 0x2982
addq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdi
callq 0x22d0
jmp 0x2990
andq $0x0, 0x30(%rsp)
movq 0x28(%rsp), %rax
movb $0x0, (%rax)
cmpb $0x1, 0x47e9(%rip)      # 0x7180
jne 0x29bc
movq %rbp, %rdi
leaq 0x28(%rsp), %r12
movq %r12, %rsi
callq 0x2544
movq %r12, %rdi
movq %rbp, %rsi
callq 0x21d0
movq %rbp, %rdi
callq 0x20c0
leaq 0x47dd(%rip), %rdi      # 0x71a0
leaq 0x10(%rsp), %rsi
callq 0x324c
incq %rbx
addq $0x10, %r13
jmp 0x2934
movq 0x47c0(%rip), %rdi      # 0x71a0
movq 0x47c1(%rip), %rsi      # 0x71a8
callq 0x355b
cmpb $0x1, 0x47a9(%rip)      # 0x719c
leaq 0x28(%rsp), %rdi
jne 0x2c2f
movq 0x45cb(%rip), %rdi      # 0x6fd0
leaq 0x16ef(%rip), %rsi      # 0x40fb
callq 0x2170
movq %rax, %rdi
movq %r14, %rsi
callq 0x2100
leaq 0x16f0(%rip), %rsi      # 0x4113
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20d0
movq 0x4596(%rip), %rdi      # 0x6fd0
leaq 0x16dc(%rip), %rsi      # 0x411d
callq 0x2170
movq %rax, %rdi
callq 0x20d0
movq 0x457b(%rip), %r14      # 0x6fd0
leaq 0x1730(%rip), %rsi      # 0x418c
movq %r14, %rdi
callq 0x2170
pushq $0x18
popq %rbx
xorl %r13d, %r13d
pushq $0x38
popq %rbp
movl $0x400, %r12d           # imm = 0x400
movq 0x472e(%rip), %rax      # 0x71a8
movq 0x471f(%rip), %rcx      # 0x71a0
subq %rcx, %rax
cqto
idivq %rbp
cmpq %rax, %r13
jae 0x2c13
movl -0x14(%rcx,%rbx), %eax
cmpl $0x100000, %eax         # imm = 0x100000
movl $0x80, %r15d
cmovael %r12d, %r15d
movq %rcx, 0x8(%rsp)
cmpl $0x1, -0x8(%rcx,%rbx)
jne 0x2c07
movq %r13, %r12
movq %r14, %rdi
movq %rbp, %r13
movq 0x8(%rsp), %rdx
movl -0x10(%rdx,%rbx), %ebp
movl %eax, 0x48(%rsp)
leaq 0x48(%rsp), %rsi
callq 0x24fb
cmpl %r15d, %ebp
movq %r13, %rbp
movq %r12, %r13
movl $0x400, %r12d           # imm = 0x400
jle 0x2aeb
callq 0x2463
movq %r14, %rdi
pushq $0x20
popq %rsi
callq 0x21b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
pushq $0x20
popq %rsi
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x6, 0x10(%rax,%rcx)
movq 0x8(%rsp), %rcx
movl -0x10(%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x2270
callq 0x2480
movq 0x8(%rsp), %rax
movl -0xc(%rax,%rbx), %eax
leaq 0x1691(%rip), %rsi      # 0x41dd
cmpq $0x4, %rax
ja 0x2b60
leaq 0x1993(%rip), %rcx      # 0x44ec
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq %r14, %rdi
callq 0x2170
movq 0x8(%rsp), %rax
movl -0x4(%rax,%rbx), %eax
testl %eax, %eax
je 0x2b93
leaq 0x166a(%rip), %rsi      # 0x41e6
cmpl $0xfff1, %eax           # imm = 0xFFF1
je 0x2b9a
cmpl $0xfff2, %eax           # imm = 0xFFF2
jne 0x2ba4
leaq 0x165a(%rip), %rsi      # 0x41eb
jmp 0x2b9a
leaq 0x1656(%rip), %rsi      # 0x41f0
movq %r14, %rdi
callq 0x2170
jmp 0x2be4
movq (%r14), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r14,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%r14,%rcx)
movq -0x18(%rax), %rax
movq $0x4, 0x10(%r14,%rax)
movq %r14, %rdi
pushq $0x20
popq %rsi
callq 0x2250
movq 0x8(%rsp), %rcx
movl -0x4(%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
pushq $0x20
popq %rsi
callq 0x21b0
movq 0x8(%rsp), %rsi
addq %rbx, %rsi
movq %rax, %rdi
callq 0x2160
movq %r14, %rdi
callq 0x20d0
incq %r13
addq $0x38, %rbx
jmp 0x2a73
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r14,%rax)
leaq 0x28(%rsp), %rdi
callq 0x20c0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c4b
jmp 0x2c4b
jmp 0x2c4b
jmp 0x2c4b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x22a0