// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
testq %r8, %r8
movq %r8, 0x30(%rsp)
je 0x4241
movq %r8, %rdi
callq 0x20a0
movq %rax, %r13
jmp 0x4244
xorl %r13d, %r13d
testw %bp, %bp
je 0x435e
movzwl %bp, %eax
shll $0xc, %eax
movq 0x8(%rsp), %rbx
addq %rbx, %rax
movq %rax, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movl 0x4(%rbx), %eax
cmpl $0xb, %eax
je 0x4276
cmpl $0x2, %eax
jne 0x434f
movq 0x20(%rbx), %r14
movq %r14, %rdi
callq 0x21c0
movq 0x18(%rbx), %rsi
addq 0x10(%rsp), %rsi
movq %rax, (%rsp)
movq %rax, %rdi
movq %r14, %rdx
callq 0x21b0
movl 0x28(%rbx), %ebp
shlq $0x6, %rbp
movq 0x8(%rsp), %r13
movq 0x20(%r13,%rbp), %r15
movq %r15, %rdi
callq 0x21c0
movq %rax, %r12
movq 0x18(%r13,%rbp), %rsi
movq 0x20(%rsp), %r13
addq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x21b0
movq %r14, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
cmpq $0x18, %r14
jb 0x433e
movq %rdx, %r15
shrq $0x4, %r15
movq (%rsp), %rbp
xorl %r14d, %r14d
testq %r13, %r13
je 0x431e
movl (%rbp), %edi
addq %r12, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x2080
testl %eax, %eax
je 0x4321
incq %r14
addq $0x18, %rbp
cmpq %r14, %r15
jne 0x42f4
jmp 0x433e
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
movq (%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 (%rsp), %rdi
callq 0x2040
addq $0x40, %rbx
cmpq 0x28(%rsp), %rbx
jne 0x4265
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq