// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
testq %r8, %r8
movq %r8, 0x30(%rsp)
je 0x4222
movq %r8, %rdi
callq 0x20a0
movq %rax, %r13
jmp 0x4225
xorl %r13d, %r13d
testw %bp, %bp
je 0x433e
movzwl %bp, %eax
shll $0xc, %eax
movq 0x10(%rsp), %rbp
addq %rbp, %rax
movq %rax, 0x28(%rsp)
movl 0x4(%rbp), %eax
cmpl $0xb, %eax
je 0x4252
cmpl $0x2, %eax
jne 0x432f
movq 0x20(%rbp), %r14
movq 0x18(%rbp), %r15
movq 0x20(%rsp), %r12
addq %r12, %r15
movq %r14, %rdi
callq 0x21c0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x21b0
movl 0x28(%rbp), %eax
shlq $0x6, %rax
movq 0x10(%rsp), %rcx
movq 0x20(%rcx,%rax), %r15
movq 0x18(%rcx,%rax), %rbx
addq %r12, %rbx
movq %r15, %rdi
callq 0x21c0
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x21b0
movq %r14, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
cmpq $0x18, %r14
jb 0x431d
movq %rdx, %r15
shrq $0x4, %r15
movq 0x8(%rsp), %r14
xorl %ebx, %ebx
testq %r13, %r13
je 0x42fd
movl (%r14), %edi
addq %r12, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x2080
testl %eax, %eax
je 0x42ff
incq %rbx
addq $0x18, %r14
cmpq %rbx, %r15
jne 0x42d3
jmp 0x431d
xorl %ebx, %ebx
leaq (%rbx,%rbx,2), %rax
movq 0x8(%rsp), %rsi
movq 0x10(%rsi,%rax,8), %rcx
movq 0x18(%rsp), %rdx
movq %rcx, 0x10(%rdx)
movups (%rsi,%rax,8), %xmm0
movups %xmm0, (%rdx)
movq %r12, %rdi
callq 0x2040
movq 0x8(%rsp), %rdi
callq 0x2040
addq $0x40, %rbp
cmpq 0x28(%rsp), %rbp
jne 0x4241
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq