// File: /workspace/github_c_makefile_star2_O0/0xADE1A1DE[P]MeasureSuite/lib/src/io/elf_memory.c
// Function: find_symbol_in_table_mem
void find_symbol_in_table_mem(Elf64_Sym *dest, const uint8_t *src,
                              Elf64_Shdr sh_table[], Elf64_Half sh_table_len,
                              const char *symbol) {

  size_t symbol_len = symbol != NULL ? strlen(symbol) : 0;
  Elf64_Shdr *last = NULL;
  Elf64_Shdr *entry = NULL;

  for (last = sh_table + sh_table_len * sizeof(Elf64_Shdr), // find end
       entry = sh_table;                                    // set first end
       entry != last;                                       // check not last
       entry++                                              // next
  ) {

    if ((entry->sh_type != SHT_SYMTAB) && (entry->sh_type != SHT_DYNSYM)) {
      continue;
    }

    Elf64_Sym *sym_tbl = {0};

    read_section_mem(src, entry, (void *)&sym_tbl);

    /* Read linked string-table
     * Section containing the string table having names of
     * symbols of this section
     */
    Elf64_Word str_tbl_ndx = entry->sh_link;
    char *str_tbl = NULL;
    read_section_mem(src, &sh_table[str_tbl_ndx], (void *)&str_tbl);

    unsigned long symbol_count = entry->sh_size / sizeof(Elf64_Sym);

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

      const char *name = str_tbl + sym_tbl[j].st_name;
      // 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(str_tbl);
    free(sym_tbl);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movw %cx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x53f8
movq -0x28(%rbp), %rdi
callq 0x2080
movq %rax, -0x78(%rbp)
jmp 0x5400
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x5400
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
shlq $0x6, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x555d
movq -0x40(%rbp), %rax
cmpl $0x2, 0x4(%rax)
je 0x545e
movq -0x40(%rbp), %rax
cmpl $0xb, 0x4(%rax)
je 0x545e
jmp 0x554c
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x5320
movq -0x40(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x4c(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rsi
leaq -0x58(%rbp), %rdx
callq 0x5320
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x18, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x553a
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
imulq $0x18, -0x68(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5502
movq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x2070
cmpl $0x0, %eax
jne 0x552a
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
imulq $0x18, -0x68(%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 0x553a
jmp 0x552c
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x54c2
movq -0x58(%rbp), %rdi
callq 0x2040
movq -0x48(%rbp), %rdi
callq 0x2040
movq -0x40(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x40(%rbp)
jmp 0x5437
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)