// File: /workspace/github_c_makefile_star2_O1/0xADE1A1DE[P]MeasureSuite/lib/src/io/elf_file.c
// Function: find_symbol_in_table
void find_symbol_in_table(int32_t file, Elf64_Ehdr hdr, Elf64_Shdr sh_table[],
                          const char *symbol, Elf64_Sym *dest) {

  size_t symbol_len = symbol != NULL ? strlen(symbol) : 0;

  for (int i = 0; i < hdr.e_shnum; i++) {
    if ((sh_table[i].sh_type != SHT_SYMTAB) &&
        (sh_table[i].sh_type != SHT_DYNSYM)) {
      continue;
    }

    Elf64_Sym *sym_tbl = {0};

    read_section(file, sh_table[i], (void *)&sym_tbl);

    /* Read linked string-table
     * Section containing the string table having names of
     * symbols of this section
     */
    Elf64_Word str_tbl_ndx = sh_table[i].sh_link;
    char *string_tbl = NULL;
    read_section(file, sh_table[str_tbl_ndx], (void *)&string_tbl);

    unsigned long symbol_count = sh_table[i].sh_size / sizeof(Elf64_Sym);

    for (unsigned long j = 0; j < symbol_count; j++) {

      Elf64_Sym cur_sym = sym_tbl[j];
      // st_name is the index in the string_table
      Elf64_Word index = cur_sym.st_name;

      // get the address of the string to compare
      const char *name = &(string_tbl[index]);
      // if we don't have a symbol(i.e. symbol len == 0),
      // or the current symbol is the required one
      if (symbol_len == 0 || strncmp(name, symbol, symbol_len) == 0) {
        memcpy(dest, &sym_tbl[j], sizeof(Elf64_Sym));
        break;
      }
    }
    free(string_tbl);
    free(sym_tbl);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, 0x58(%rsp)
movq %rsi, %r14
movl %edi, 0x54(%rsp)
leaq 0xb0(%rsp), %rbx
testq %rdx, %rdx
movq %rdx, 0x70(%rsp)
je 0x4793
movq %rdx, %rdi
callq 0x20a0
movq %rax, %r12
jmp 0x4796
xorl %r12d, %r12d
movzwl 0x3c(%rbx), %eax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x48f3
xorl %ebx, %ebx
movq %r14, 0x60(%rsp)
movq %rbx, %r13
shlq $0x6, %r13
movl 0x4(%r14,%r13), %eax
cmpl $0xb, %eax
je 0x47c9
cmpl $0x2, %eax
jne 0x48e5
addq %r14, %r13
xorl %r15d, %r15d
movq %r15, 0x40(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups 0x30(%r13), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl 0x54(%rsp), %ebp
movl %ebp, %edi
leaq 0x40(%rsp), %rsi
callq 0x4706
movl 0x28(%r13), %eax
movq %r15, 0x48(%rsp)
shlq $0x6, %rax
movups (%r14,%rax), %xmm0
movups 0x10(%r14,%rax), %xmm1
movups 0x20(%r14,%rax), %xmm2
movups 0x30(%r14,%rax), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
leaq 0x48(%rsp), %rsi
callq 0x4706
movq 0x20(%r13), %rcx
movq %rcx, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rdx
cmpq $0x18, %rcx
jb 0x48cc
movq %rdx, %r13
shrq $0x4, %r13
movq 0x48(%rsp), %r14
movq 0x40(%rsp), %r15
xorl %ebp, %ebp
testq %r12, %r12
je 0x48a5
movl (%r15), %edi
addq %r14, %rdi
movq 0x70(%rsp), %rsi
movq %r12, %rdx
callq 0x2080
testl %eax, %eax
je 0x48a7
incq %rbp
addq $0x18, %r15
cmpq %rbp, %r13
jne 0x487b
jmp 0x48cc
xorl %ebp, %ebp
movq 0x40(%rsp), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq 0x58(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movups (%rax,%rcx,8), %xmm0
movups %xmm0, (%rsi)
movq 0x48(%rsp), %rdi
callq 0x2040
movq 0x40(%rsp), %rdi
callq 0x2040
movq 0x60(%rsp), %r14
incq %rbx
cmpq 0x68(%rsp), %rbx
jne 0x47af
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq