#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 */

/* Type definitions */
struct Elf32_Header {
  int dummy;
};

/* Variables and functions */
int elf32_getNumSections(struct Elf32_Header *);
void *elf32_getSection(struct Elf32_Header *, int);
int /*<<< orphan*/ elf32_getSectionName(struct Elf32_Header *, int);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
void *elf32_getSectionNamed(struct Elf32_Header *elfFile, char *str) {
  int numSections = elf32_getNumSections(elfFile);
  int i;
  for (i = 0; i < numSections; i++) {
    if (strcmp(str, elf32_getSectionName(elfFile, i)) == 0) {
      return elf32_getSection(elfFile, i);
    }
  }
  return ((void *)0);
}


x86 assembly (clang, -O0):
<elf32_getSectionNamed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <elf32_getNumSections@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c0 <elf32_getSectionNamed+0x80>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <elf32_getSectionName@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ad <elf32_getSectionNamed+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <elf32_getSection@plt>
mov    %rax,-0x8(%rbp)
jmp    11c8 <elf32_getSectionNamed+0x88>
jmp    11b2 <elf32_getSectionNamed+0x72>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1163 <elf32_getSectionNamed+0x23>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elf32_getSectionNamed>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <elf32_getNumSections@plt>
test   %eax,%eax
jle    1180 <elf32_getSectionNamed+0x40>
mov    %eax,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <elf32_getSectionName@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <strcmp@plt>
test   %rax,%rax
je     118d <elf32_getSectionNamed+0x4d>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1160 <elf32_getSectionNamed+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <elf32_getSection@plt>

LLVM IR (-O0):
%struct.Elf32_Header = type { i32 }
define i8* @elf32_getSectionNamed(%struct.Elf32_Header* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.Elf32_Header*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store %struct.Elf32_Header* %0, %struct.Elf32_Header** %4
store i8* %1, i8** %5
%8 = load %struct.Elf32_Header*, %struct.Elf32_Header** %4
%9 = call i32 @elf32_getNumSections(%struct.Elf32_Header* %8)
store i32 %9, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load %struct.Elf32_Header*, %struct.Elf32_Header** %4
%17 = load i32, i32* %7
%18 = call i32 @elf32_getSectionName(%struct.Elf32_Header* %16, i32 %17)
%19 = call i64 @strcmp(i8* %15, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load %struct.Elf32_Header*, %struct.Elf32_Header** %4
%23 = load i32, i32* %7
%24 = call i8* @elf32_getSection(%struct.Elf32_Header* %22, i32 %23)
store i8* %24, i8** %3
br label %30
25: ; preds = %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %10
29: ; preds = %10
store i8* null, i8** %3
br label %30
30: ; preds = %29, %21
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
%struct.Elf32_Header = type { i32 }
define i8* @elf32_getSectionNamed(%struct.Elf32_Header* %0, i8* %1) {
%3 = tail call i32 @elf32_getNumSections(%struct.Elf32_Header* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %2, %12
%6 = phi i32 [ %13, %12 ], [ 0, %2 ]
%7 = tail call i32 @elf32_getSectionName(%struct.Elf32_Header* %0, i32 %6)
%8 = tail call i64 @strcmp(i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i8* @elf32_getSection(%struct.Elf32_Header* %0, i32 %6)
br label %15
12: ; preds = %5
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, %3
br i1 %14, label %15, label %5
15: ; preds = %12, %2, %10
%16 = phi i8* [ %11, %10 ], [ null, %2 ], [ null, %12 ]
ret i8* %16
}