#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int e_shoff;
  size_t e_shstrndx;
  int e_shnum;
};
struct TYPE_3__ {
  int sh_offset;
  scalar_t__ sh_type;
  int sh_name;
};
typedef scalar_t__ Elf32_Word;
typedef TYPE_1__ Elf32_Shdr;
typedef TYPE_2__ Elf32_Ehdr;

/* Variables and functions */
scalar_t__ memcmp(char *, char *, int);
char *findElfSection(void *objImage, Elf32_Word sh_type) {
  char *ehdrC = (char *)objImage;
  Elf32_Ehdr *ehdr = (Elf32_Ehdr *)ehdrC;
  Elf32_Shdr *shdr = (Elf32_Shdr *)(ehdrC + ehdr->e_shoff);
  char *sh_strtab = ehdrC + shdr[ehdr->e_shstrndx].sh_offset;
  char *ptr = NULL;
  int i;
  for (i = 0; i < ehdr->e_shnum; i++) {
    if (shdr[i].sh_type == sh_type && i != ehdr->e_shstrndx &&
        0 != memcmp(".stabstr", sh_strtab + shdr[i].sh_name, 8)) {
      ptr = ehdrC + shdr[i].sh_offset;
      break;
    }
  }
  return ptr;
}


x86 assembly (clang, -O0):
<findElfSection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
imul   $0x18,0x8(%rdx),%rdx
add    %rdx,%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    0x10(%rcx),%eax
jge    121c <findElfSection+0x10c>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
cmp    -0x10(%rbp),%rax
jne    1209 <findElfSection+0xf9>
movslq -0x3c(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     1209 <findElfSection+0xf9>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq 0x10(%rax),%rax
add    %rax,%rsi
lea    0xe31(%rip),%rdi
mov    $0x8,%edx
call   1030 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1209 <findElfSection+0xf9>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
imul   $0x18,%rdx,%rdx
add    %rdx,%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    121c <findElfSection+0x10c>
jmp    120e <findElfSection+0xfe>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116f <findElfSection+0x5f>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findElfSection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x10(%rdi),%eax
test   %eax,%eax
jle    119a <findElfSection+0x8a>
mov    %rsi,%r13
mov    %rdi,%r14
movslq (%rdi),%rcx
lea    (%rdi,%rcx,1),%rdx
mov    0x8(%rdi),%rsi
lea    (%rsi,%rsi,2),%rsi
movslq (%rdx,%rsi,8),%r12
add    %rdi,%r12
lea    (%rcx,%rdi,1),%rbx
add    $0x10,%rbx
lea    0xeb3(%rip),%r15
xor    %ebp,%ebp
jmp    1170 <findElfSection+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
movslq %eax,%rcx
add    $0x18,%rbx
cmp    %rcx,%rbp
jge    119a <findElfSection+0x8a>
cmp    %r13,-0x8(%rbx)
jne    1160 <findElfSection+0x50>
cmp    0x8(%r14),%rbp
je     1160 <findElfSection+0x50>
movslq (%rbx),%rsi
add    %r12,%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    11af <findElfSection+0x9f>
mov    0x10(%r14),%eax
jmp    1160 <findElfSection+0x50>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq -0x10(%rbx),%rax
add    %rax,%r14
jmp    119d <findElfSection+0x8d>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i64, i32 }
%struct.TYPE_3__ = type { i32, i64, i32 }
@.str = [9 x i8] c".stabstr\00"
define i8* @findElfSection(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca %struct.TYPE_4__*
%7 = alloca %struct.TYPE_3__*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%11 = load i8*, i8** %3
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = bitcast i8* %12 to %struct.TYPE_4__*
store %struct.TYPE_4__* %13, %struct.TYPE_4__** %6
%14 = load i8*, i8** %5
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = bitcast i8* %19 to %struct.TYPE_3__*
store %struct.TYPE_3__* %20, %struct.TYPE_3__** %7
%21 = load i8*, i8** %5
%22 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%23 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 %25
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %21, i64 %29
store i8* %30, i8** %8
store i8* null, i8** %9
store i32 0, i32* %10
br label %31
31: ; preds = %76, %2
%32 = load i32, i32* %10
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %79
37: ; preds = %31
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i64 %40
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = load i64, i64* %4
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %75
46: ; preds = %37
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%50 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %49, i32 0, i32 1
%51 = load i64, i64* %50
%52 = icmp ne i64 %48, %51
br i1 %52, label %53, label %75
53: ; preds = %46
%54 = load i8*, i8** %8
%55 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i64 %57
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 2
%60 = load i32, i32* %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %54, i64 %61
%63 = call i64 @memcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %62, i32 8)
%64 = icmp ne i64 0, %63
br i1 %64, label %65, label %75
65: ; preds = %53
%66 = load i8*, i8** %5
%67 = load %struct.TYPE_3__*, %struct.TYPE_3__** %7
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i64 %69
%71 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %66, i64 %73
store i8* %74, i8** %9
br label %79
75: ; preds = %53, %46, %37
br label %76
76: ; preds = %75
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %31
79: ; preds = %65, %31
%80 = load i8*, i8** %9
ret i8* %80
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64, i32 }
@.str = [9 x i8] c".stabstr\00"
define i8* @findElfSection(i8* %0, i64 %1) {
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = bitcast i8* %6 to %struct.TYPE_3__*
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = bitcast i8* %8 to i64*
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i64 %10, i32 0
%12 = load i32, i32* %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds 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 %48
19: ; preds = %2, %43
%20 = phi i32 [ %44, %43 ], [ %17, %2 ]
%21 = phi i64 [ %45, %43 ], [ 0, %2 ]
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i64 %21, i32 1
%23 = load i64, i64* %22
%24 = icmp eq i64 %23, %1
br i1 %24, label %25, label %43
25: ; preds = %19
%26 = load i64, i64* %9
%27 = icmp eq i64 %26, %21
br i1 %27, label %43, label %28
28: ; preds = %25
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i64 %21, i32 2
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %14, i64 %31
%33 = tail call i64 @memcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %32, i32 8)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = load i32, i32* %16
br label %43
37: ; preds = %28
%38 = and i64 %21, 4294967295
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i64 %38, i32 0
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %0, i64 %41
br label %48
43: ; preds = %35, %19, %25
%44 = phi i32 [ %36, %35 ], [ %20, %19 ], [ %20, %25 ]
%45 = add nuw nsw i64 %21, 1
%46 = sext i32 %44 to i64
%47 = icmp slt i64 %45, %46
br i1 %47, label %19, label %48
48: ; preds = %43, %2, %37
%49 = phi i8* [ %42, %37 ], [ null, %2 ], [ null, %43 ]
ret i8* %49
}