#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_8__ TYPE_2__;
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  int e_shnum;
};
struct TYPE_7__ {
  scalar_t__ sh_type;
};
typedef TYPE_1__ Elf32_Shdr;
typedef TYPE_2__ Elf32_Ehdr;

/* Variables and functions */
scalar_t__ SHT_DYNSYM;
int do_dyn_symtab(int, TYPE_1__ *, TYPE_1__ *, char const *);
int get_sym_number(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr,
                   const char *sh_function) {
  Elf32_Shdr *shdrp = shdr;
  int i;
  for (i = 0; i < ehdr->e_shnum; i++) {
    if (shdrp->sh_type == SHT_DYNSYM) {
      return do_dyn_symtab(fd, shdr, shdrp, sh_function);
    }
    ++shdrp;
  }
}


x86 assembly (clang, -O0):
<get_sym_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1192 <get_sym_number+0x82>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <get_sym_number+0x68>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <do_dyn_symtab@plt>
mov    %eax,-0x4(%rbp)
jmp    1192 <get_sym_number+0x82>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1136 <get_sym_number+0x26>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sym_number>:
mov    (%rsi),%esi
test   %esi,%esi
jle    113e <get_sym_number+0x2e>
mov    0x2ecb(%rip),%rax
mov    (%rax),%r8
mov    %rdx,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r8,(%rax)
je     113f <get_sym_number+0x2f>
add    $0x8,%rax
add    $0xffffffff,%esi
jne    1130 <get_sym_number+0x20>
ret
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1030 <do_dyn_symtab@plt>

LLVM IR (-O0):
%struct.TYPE_8__ = type { i32 }
%struct.TYPE_7__ = type { i64 }
@SHT_DYNSYM = global i64 0
define i32 @get_sym_number(i32 %0, %struct.TYPE_8__* %1, %struct.TYPE_7__* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.TYPE_8__*
%8 = alloca %struct.TYPE_7__*
%9 = alloca i8*
%10 = alloca %struct.TYPE_7__*
%11 = alloca i32
store i32 %0, i32* %6
store %struct.TYPE_8__* %1, %struct.TYPE_8__** %7
store %struct.TYPE_7__* %2, %struct.TYPE_7__** %8
store i8* %3, i8** %9
%12 = load %struct.TYPE_7__*, %struct.TYPE_7__** %8
store %struct.TYPE_7__* %12, %struct.TYPE_7__** %10
store i32 0, i32* %11
br label %13
13: ; preds = %34, %4
%14 = load i32, i32* %11
%15 = load %struct.TYPE_8__*, %struct.TYPE_8__** %7
%16 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp slt i32 %14, %17
br i1 %18, label %19, label %37
19: ; preds = %13
%20 = load %struct.TYPE_7__*, %struct.TYPE_7__** %10
%21 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @SHT_DYNSYM
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load %struct.TYPE_7__*, %struct.TYPE_7__** %8
%28 = load %struct.TYPE_7__*, %struct.TYPE_7__** %10
%29 = load i8*, i8** %9
%30 = call i32 @do_dyn_symtab(i32 %26, %struct.TYPE_7__* %27, %struct.TYPE_7__* %28, i8* %29)
store i32 %30, i32* %5
br label %37
31: ; preds = %19
%32 = load %struct.TYPE_7__*, %struct.TYPE_7__** %10
%33 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %32, i32 1
store %struct.TYPE_7__* %33, %struct.TYPE_7__** %10
br label %34
34: ; preds = %31
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %13
37: ; preds = %25, %13
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
%struct.TYPE_8__ = type { i32 }
%struct.TYPE_7__ = type { i64 }
@SHT_DYNSYM = global i64 0
define i32 @get_sym_number(i32 %0, %struct.TYPE_8__* nocapture %1, %struct.TYPE_7__* %2, i8* %3) {
%5 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i64, i64* @SHT_DYNSYM
br label %10
10: ; preds = %8, %18
%11 = phi i32 [ 0, %8 ], [ %20, %18 ]
%12 = phi %struct.TYPE_7__* [ %2, %8 ], [ %19, %18 ]
%13 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %12, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %9
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @do_dyn_symtab(i32 %0, %struct.TYPE_7__* %2, %struct.TYPE_7__* %12, i8* %3)
br label %22
18: ; preds = %10
%19 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %12, i64 1
%20 = add nuw nsw i32 %11, 1
%21 = icmp eq i32 %20, %6
br i1 %21, label %22, label %10
22: ; preds = %18, %4, %16
%23 = phi i32 [ %17, %16 ], [ undef, %4 ], [ undef, %18 ]
ret i32 %23
}