// File: /workspace/github_c_makefile_star2_O2/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 $0x88, %rsp
movq %rcx, 0x68(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movl %edi, 0x4c(%rsp)
leaq 0xc0(%rsp), %rbx
testq %rdx, %rdx
je 0x4454
movq %r14, %rdi
callq 0x20a0
movq %rax, %r12
jmp 0x4457
xorl %r12d, %r12d
movzwl 0x3c(%rbx), %eax
movq %rax, 0x78(%rsp)
xorl %ecx, %ecx
movq %r15, 0x70(%rsp)
cmpq 0x78(%rsp), %rcx
je 0x45a4
movq %rcx, %rbx
shlq $0x6, %rbx
movl 0x4(%r15,%rbx), %eax
cmpl $0xb, %eax
je 0x448c
cmpl $0x2, %eax
jne 0x459c
movq %rcx, 0x80(%rsp)
addq %r15, %rbx
andq $0x0, 0x60(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups 0x30(%rbx), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl 0x4c(%rsp), %ebp
movl %ebp, %edi
leaq 0x60(%rsp), %rsi
callq 0x43c6
movl 0x28(%rbx), %eax
andq $0x0, 0x58(%rsp)
shlq $0x6, %rax
movups (%r15,%rax), %xmm0
movups 0x10(%r15,%rax), %xmm1
movups 0x20(%r15,%rax), %xmm2
movups 0x30(%r15,%rax), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
leaq 0x58(%rsp), %rsi
callq 0x43c6
movq 0x20(%rbx), %rax
xorl %edx, %edx
pushq $0x18
popq %rcx
divq %rcx
movq %rax, %rbp
movq 0x58(%rsp), %rbx
movq 0x60(%rsp), %r13
movq %r13, 0x50(%rsp)
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x457d
testq %r12, %r12
je 0x455c
movl (%r13), %edi
addq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2080
testl %eax, %eax
je 0x455f
incq %r15
addq $0x18, %r13
jmp 0x4533
xorl %r15d, %r15d
imulq $0x18, %r15, %rax
movq 0x50(%rsp), %rsi
movq 0x10(%rsi,%rax), %rcx
movq 0x68(%rsp), %rdx
movq %rcx, 0x10(%rdx)
movups (%rsi,%rax), %xmm0
movups %xmm0, (%rdx)
movq %rbx, %rdi
callq 0x2040
movq 0x50(%rsp), %rdi
callq 0x2040
movq 0x70(%rsp), %r15
movq 0x80(%rsp), %rcx
incq %rcx
jmp 0x4467
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq