// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x5bae
movq -0x18(%rbp), %rdi
callq 0x2080
movq %rax, -0x90(%rbp)
jmp 0x5bb9
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0x5bb9
movq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x88(%rbp), %rcx
movl -0x2c(%rbp), %eax
movzwl 0x3c(%rcx), %ecx
cmpl %ecx, %eax
jge 0x5d92
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
je 0x5c10
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0xb, 0x4(%rax)
je 0x5c10
jmp 0x5d84
movq $0x0, -0x38(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups 0x30(%rax), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x38(%rbp), %rsi
callq 0x5a90
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
movl %eax, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups 0x30(%rax), %xmm3
movq %rsp, %rax
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x48(%rbp), %rsi
callq 0x5a90
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movl $0x18, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x5d72
movq -0x38(%rbp), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x68(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x48(%rbp), %rax
movl -0x74(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x5d37
movq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x2070
cmpl $0x0, %eax
jne 0x5d5f
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
imulq $0x18, -0x58(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
jmp 0x5d72
jmp 0x5d61
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5cd5
movq -0x48(%rbp), %rdi
callq 0x2040
movq -0x38(%rbp), %rdi
callq 0x2040
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5bcb
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)