#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int e_shoff;
  size_t e_shstrndx;
  int e_shnum;
};
struct TYPE_4__ {
  int sh_offset;
  int sh_name;
};
typedef TYPE_1__ Elf64_Shdr;
typedef TYPE_2__ Elf64_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ strcmp(char *, char *);
Elf64_Shdr *elfi_find_section(void *data, char *name) {
  char *sname;
  int i;
  Elf64_Ehdr *elf_hdr = (Elf64_Ehdr *)data;
  Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff);
  Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx];
  const char *const sh_strtab_p = data + sh_strtab->sh_offset;
  for (i = 0; i < elf_hdr->e_shnum; i++) {
    sname = (char *)(sh_strtab_p + shdr[i].sh_name);
    if (!strcmp(sname, name))
      return &shdr[i];
  }
  return NULL;
}


x86 assembly (clang, -O0):
<elfi_find_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    0x8(%rcx),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    0x10(%rcx),%eax
jge    11d3 <elfi_find_section+0xc3>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq 0x4(%rcx,%rdx,8),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c0 <elfi_find_section+0xb0>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11db <elfi_find_section+0xcb>
jmp    11c5 <elfi_find_section+0xb5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116a <elfi_find_section+0x5a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elfi_find_section>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x10(%rdi),%r15d
test   %r15d,%r15d
jle    115d <elfi_find_section+0x4d>
mov    %rsi,%r14
movslq (%rdi),%rbx
add    %rdi,%rbx
mov    0x8(%rdi),%rax
movslq (%rbx,%rax,8),%r12
add    %rdi,%r12
cs nopw 0x0(%rax,%rax,1)
nop
movslq 0x4(%rbx),%rdi
add    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     115f <elfi_find_section+0x4f>
add    $0x8,%rbx
add    $0xffffffffffffffff,%r15
jne    1140 <elfi_find_section+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i64, i32 }
define %struct.TYPE_4__* @elfi_find_section(i8* %0, i8* %1) {
%3 = alloca %struct.TYPE_4__*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.TYPE_5__*
%9 = alloca %struct.TYPE_4__*
%10 = alloca %struct.TYPE_4__*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to %struct.TYPE_5__*
store %struct.TYPE_5__* %13, %struct.TYPE_5__** %8
%14 = load i8*, i8** %4
%15 = load %struct.TYPE_5__*, %struct.TYPE_5__** %8
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = getelementptr i8, i8* %14, i64 %18
%20 = bitcast i8* %19 to %struct.TYPE_4__*
store %struct.TYPE_4__* %20, %struct.TYPE_4__** %9
%21 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%22 = load %struct.TYPE_5__*, %struct.TYPE_5__** %8
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %21, i64 %24
store %struct.TYPE_4__* %25, %struct.TYPE_4__** %10
%26 = load i8*, i8** %4
%27 = load %struct.TYPE_4__*, %struct.TYPE_4__** %10
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr i8, i8* %26, i64 %30
store i8* %31, i8** %11
store i32 0, i32* %7
br label %32
32: ; preds = %58, %2
%33 = load i32, i32* %7
%34 = load %struct.TYPE_5__*, %struct.TYPE_5__** %8
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %61
38: ; preds = %32
%39 = load i8*, i8** %11
%40 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %40, i64 %42
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %39, i64 %46
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = load i8*, i8** %5
%50 = call i32 @strcmp(i8* %48, i8* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %38
%53 = load %struct.TYPE_4__*, %struct.TYPE_4__** %9
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %53, i64 %55
store %struct.TYPE_4__* %56, %struct.TYPE_4__** %3
br label %62
57: ; preds = %38
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %32
61: ; preds = %32
store %struct.TYPE_4__* null, %struct.TYPE_4__** %3
br label %62
62: ; preds = %61, %52
%63 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
ret %struct.TYPE_4__* %63
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
define %struct.TYPE_4__* @elfi_find_section(i8* %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = sext i32 %4 to i64
%6 = getelementptr i8, i8* %0, i64 %5
%7 = bitcast i8* %6 to %struct.TYPE_4__*
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = bitcast i8* %8 to i64*
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i64 %10, i32 0
%12 = load i32, i32* %11
%13 = sext i32 %12 to i64
%14 = getelementptr i8, i8* %0, i64 %13
%15 = getelementptr inbounds i8, i8* %0, i64 16
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %2
%20 = zext i32 %17 to i64
br label %21
21: ; preds = %19, %32
%22 = phi i64 [ 0, %19 ], [ %33, %32 ]
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i64 %22, i32 1
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %14, i64 %25
%27 = tail call i32 @strcmp(i8* dereferenceable(1) %26, i8* dereferenceable(1) %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = and i64 %22, 4294967295
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i64 %30
br label %35
32: ; preds = %21
%33 = add nuw nsw i64 %22, 1
%34 = icmp eq i64 %33, %20
br i1 %34, label %35, label %21
35: ; preds = %32, %2, %29
%36 = phi %struct.TYPE_4__* [ %31, %29 ], [ null, %2 ], [ null, %32 ]
ret %struct.TYPE_4__* %36
}