#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int e_shoff;
  unsigned int e_shnum;
};
struct TYPE_5__ {
  unsigned int sh_size;
  scalar_t__ sh_type;
};
typedef TYPE_1__ Elf64_Shdr;
typedef TYPE_2__ Elf64_Ehdr;

/* Variables and functions */
unsigned int SHN_UNDEF;
scalar_t__ SHT_SYMTAB;
Elf64_Shdr *get_symbol_table(Elf64_Ehdr *hdr) {
  Elf64_Shdr *x;
  unsigned int i, num_sections;
  x = (void *)hdr + hdr->e_shoff;
  if (hdr->e_shnum == SHN_UNDEF)
    num_sections = x[0].sh_size;
  else
    num_sections = hdr->e_shnum;
  for (i = 1; i < num_sections; i++)
    if (x[i].sh_type == SHT_SYMTAB)
      return &x[i];
  return NULL;
}


x86 assembly (clang, -O0):
<get_symbol_table>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2eb0(%rip),%rcx
cmp    (%rcx),%eax
jne    113e <get_symbol_table+0x3e>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1148 <get_symbol_table+0x48>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    11a7 <get_symbol_table+0xa7>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <get_symbol_table+0x94>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <get_symbol_table+0xaf>
jmp    1199 <get_symbol_table+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <get_symbol_table+0x4f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_symbol_table>:
movslq (%rdi),%rax
mov    0x4(%rdi),%edx
mov    0x2ecb(%rip),%rcx
cmp    (%rcx),%edx
jne    1114 <get_symbol_table+0x14>
mov    (%rdi,%rax,1),%edx
cmp    $0x2,%edx
jb     1140 <get_symbol_table+0x40>
mov    0x2ec0(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,%edx
add    %rdi,%rax
add    $0x10,%rax
add    $0xffffffffffffffff,%rdx
cmp    %rcx,0x8(%rax)
je     1142 <get_symbol_table+0x42>
add    $0x10,%rax
add    $0xffffffffffffffff,%rdx
jne    1130 <get_symbol_table+0x30>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i64 }
%struct.TYPE_6__ = type { i32, i32 }
@SHN_UNDEF = global i32 0
@SHT_SYMTAB = global i64 0
define %struct.TYPE_5__* @get_symbol_table(%struct.TYPE_6__* %0) {
%2 = alloca %struct.TYPE_5__*
%3 = alloca %struct.TYPE_6__*
%4 = alloca %struct.TYPE_5__*
%5 = alloca i32
%6 = alloca i32
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %3
%7 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%8 = bitcast %struct.TYPE_6__* %7 to i8*
%9 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr i8, i8* %8, i64 %12
%14 = bitcast i8* %13 to %struct.TYPE_5__*
store %struct.TYPE_5__* %14, %struct.TYPE_5__** %4
%15 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i32, i32* @SHN_UNDEF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %21, i64 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %22, i32 0, i32 0
%24 = load i32, i32* %23
store i32 %24, i32* %6
br label %29
25: ; preds = %1
%26 = load %struct.TYPE_6__*, %struct.TYPE_6__** %3
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %26, i32 0, i32 1
%28 = load i32, i32* %27
store i32 %28, i32* %6
br label %29
29: ; preds = %25, %20
store i32 1, i32* %5
br label %30
30: ; preds = %49, %29
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = icmp ult i32 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%36 = load i32, i32* %5
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i64 %37
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %38, i32 0, i32 1
%40 = load i64, i64* %39
%41 = load i64, i64* @SHT_SYMTAB
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %34
%44 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%45 = load i32, i32* %5
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %44, i64 %46
store %struct.TYPE_5__* %47, %struct.TYPE_5__** %2
br label %53
48: ; preds = %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add i32 %50, 1
store i32 %51, i32* %5
br label %30
52: ; preds = %30
store %struct.TYPE_5__* null, %struct.TYPE_5__** %2
br label %53
53: ; preds = %52, %43
%54 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
ret %struct.TYPE_5__* %54
}

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