#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_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  int e_shoff;
  unsigned long e_shnum;
};
struct TYPE_6__ {
  scalar_t__ sh_type;
  int sh_offset;
  int sh_size;
  size_t sh_link;
};
struct TYPE_5__ {
  int st_name;
  int /*<<< orphan*/ st_info;
};
typedef TYPE_1__ Elf32_Sym;
typedef TYPE_2__ Elf32_Shdr;
typedef TYPE_3__ Elf32_Ehdr;

/* Variables and functions */
int ELF32_ST_BIND(int /*<<< orphan*/);
char ELF32_ST_TYPE(int /*<<< orphan*/);
scalar_t__ SHT_SYMTAB;
int STB_WEAK;
char STT_FUNC;
char STT_OBJECT;
int /*<<< orphan*/ add_sym(TYPE_1__ *, char *);
void build_symbol_list(void *base) {
  Elf32_Ehdr *ehdr = (Elf32_Ehdr *)base;
  Elf32_Shdr *shdr = (Elf32_Shdr *)(base + ehdr->e_shoff), *bshdr = shdr;
  unsigned long l;
  for (l = 0; l < ehdr->e_shnum; l++, shdr++) {
    if (shdr->sh_type == SHT_SYMTAB) {
      Elf32_Sym *esym = (Elf32_Sym *)(base + shdr->sh_offset);
      char *str;
      unsigned long ul = shdr->sh_size / sizeof(*esym), uf;
      for (uf = 0; uf < ul; uf++, esym++) {
        char type = ELF32_ST_TYPE(esym->st_info);
        if (!esym->st_name)
          continue;
        if (!((type & STT_FUNC) || (type & STT_OBJECT)))
          continue;
        if (ELF32_ST_BIND(esym->st_info) & STB_WEAK)
          continue;
        str = (char *)(base + bshdr[shdr->sh_link].sh_offset + esym->st_name);
        add_sym(esym, str);
      }
    }
  }
}


x86 assembly (clang, -O0):
<build_symbol_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jae    12bd <build_symbol_list+0x18d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
jne    129b <build_symbol_list+0x16b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq 0x8(%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq 0xc(%rax),%rax
shr    $0x3,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    1296 <build_symbol_list+0x166>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <ELF32_ST_TYPE@plt>
mov    %al,-0x49(%rbp)
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11e9 <build_symbol_list+0xb9>
jmp    1279 <build_symbol_list+0x149>
movsbl -0x49(%rbp),%eax
mov    0x2ddc(%rip),%rcx
movsbl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1220 <build_symbol_list+0xf0>
movsbl -0x49(%rbp),%eax
mov    0x2dbb(%rip),%rcx
movsbl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1220 <build_symbol_list+0xf0>
jmp    1279 <build_symbol_list+0x149>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ELF32_ST_BIND@plt>
mov    0x2db5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1243 <build_symbol_list+0x113>
jmp    1279 <build_symbol_list+0x149>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
imul   $0x18,0x10(%rdx),%rdx
add    %rdx,%rcx
movslq 0x8(%rcx),%rcx
add    %rcx,%rax
mov    -0x30(%rbp),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <add_sym@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    11ba <build_symbol_list+0x8a>
jmp    129b <build_symbol_list+0x16b>
jmp    12a0 <build_symbol_list+0x170>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <build_symbol_list+0x36>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_symbol_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    0x8(%rdi),%rax
test   %rax,%rax
je     122c <build_symbol_list+0xfc>
mov    0x8(%rsp),%rcx
movslq (%rcx),%r15
add    %rcx,%r15
xor    %r12d,%r12d
mov    0x2e73(%rip),%rdx
mov    0x2e64(%rip),%rbp
mov    0x2e75(%rip),%r13
mov    %r15,0x10(%rsp)
jmp    11a1 <build_symbol_list+0x71>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rax
mov    0x2e48(%rip),%rdx
add    $0x1,%r12
add    $0x18,%r15
cmp    %rax,%r12
jae    122c <build_symbol_list+0xfc>
mov    (%r15),%rcx
cmp    (%rdx),%rcx
jne    1190 <build_symbol_list+0x60>
movslq 0xc(%r15),%r14
cmp    $0x8,%r14
jb     1190 <build_symbol_list+0x60>
shr    $0x3,%r14
movslq 0x8(%r15),%rbx
add    0x8(%rsp),%rbx
cmp    $0x2,%r14
mov    $0x1,%eax
cmovb  %rax,%r14
jmp    11da <build_symbol_list+0xaa>
nop
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
je     1180 <build_symbol_list+0x50>
mov    0x4(%rbx),%edi
call   1050 <ELF32_ST_TYPE@plt>
cmpl   $0x0,(%rbx)
je     11d0 <build_symbol_list+0xa0>
test   %al,0x0(%rbp)
jne    11f7 <build_symbol_list+0xc7>
mov    0x2dd5(%rip),%rcx
test   %al,(%rcx)
je     11d0 <build_symbol_list+0xa0>
mov    0x4(%rbx),%edi
call   1040 <ELF32_ST_BIND@plt>
test   %eax,0x0(%r13)
jne    11d0 <build_symbol_list+0xa0>
mov    0x10(%r15),%rax
lea    (%rax,%rax,2),%rax
mov    0x10(%rsp),%rcx
movslq 0x8(%rcx,%rax,8),%rax
add    0x8(%rsp),%rax
movslq (%rbx),%rsi
add    %rax,%rsi
mov    %rbx,%rdi
call   1030 <add_sym@plt>
jmp    11d0 <build_symbol_list+0xa0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { i32, i64 }
%struct.TYPE_6__ = type { i64, i32, i32, i64 }
%struct.TYPE_5__ = type { i32, i32 }
@SHT_SYMTAB = global i64 0
@STT_FUNC = global i8 0
@STT_OBJECT = global i8 0
@STB_WEAK = global i32 0
define void @build_symbol_list(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_7__*
%4 = alloca %struct.TYPE_6__*
%5 = alloca %struct.TYPE_6__*
%6 = alloca i64
%7 = alloca %struct.TYPE_5__*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = bitcast i8* %12 to %struct.TYPE_7__*
store %struct.TYPE_7__* %13, %struct.TYPE_7__** %3
%14 = load i8*, i8** %2
%15 = load %struct.TYPE_7__*, %struct.TYPE_7__** %3
%16 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %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_6__*
store %struct.TYPE_6__* %20, %struct.TYPE_6__** %4
%21 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
store %struct.TYPE_6__* %21, %struct.TYPE_6__** %5
store i64 0, i64* %6
br label %22
22: ; preds = %111, %1
%23 = load i64, i64* %6
%24 = load %struct.TYPE_7__*, %struct.TYPE_7__** %3
%25 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = icmp ult i64 %23, %26
br i1 %27, label %28, label %116
28: ; preds = %22
%29 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%30 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = load i64, i64* @SHT_SYMTAB
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %110
34: ; preds = %28
%35 = load i8*, i8** %2
%36 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr i8, i8* %35, i64 %39
%41 = bitcast i8* %40 to %struct.TYPE_5__*
store %struct.TYPE_5__* %41, %struct.TYPE_5__** %7
%42 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%43 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %42, i32 0, i32 2
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = udiv i64 %45, 8
store i64 %46, i64* %9
store i64 0, i64* %10
br label %47
47: ; preds = %104, %34
%48 = load i64, i64* %10
%49 = load i64, i64* %9
%50 = icmp ult i64 %48, %49
br i1 %50, label %51, label %109
51: ; preds = %47
%52 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = call signext i8 @ELF32_ST_TYPE(i32 %54)
store i8 %55, i8* %11
%56 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%57 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %51
br label %104
61: ; preds = %51
%62 = load i8, i8* %11
%63 = sext i8 %62 to i32
%64 = load i8, i8* @STT_FUNC
%65 = sext i8 %64 to i32
%66 = and i32 %63, %65
%67 = icmp ne i32 %66, 0
br i1 %67, label %76, label %68
68: ; preds = %61
%69 = load i8, i8* %11
%70 = sext i8 %69 to i32
%71 = load i8, i8* @STT_OBJECT
%72 = sext i8 %71 to i32
%73 = and i32 %70, %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %76, label %75
75: ; preds = %68
br label %104
76: ; preds = %68, %61
%77 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%78 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = call i32 @ELF32_ST_BIND(i32 %79)
%81 = load i32, i32* @STB_WEAK
%82 = and i32 %80, %81
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %76
br label %104
85: ; preds = %76
%86 = load i8*, i8** %2
%87 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%88 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%89 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %88, i32 0, i32 3
%90 = load i64, i64* %89
%91 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %87, i64 %90
%92 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %91, i32 0, i32 1
%93 = load i32, i32* %92
%94 = sext i32 %93 to i64
%95 = getelementptr i8, i8* %86, i64 %94
%96 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%97 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %96, i32 0, i32 0
%98 = load i32, i32* %97
%99 = sext i32 %98 to i64
%100 = getelementptr i8, i8* %95, i64 %99
store i8* %100, i8** %8
%101 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%102 = load i8*, i8** %8
%103 = call i32 @add_sym(%struct.TYPE_5__* %101, i8* %102)
br label %104
104: ; preds = %85, %84, %75, %60
%105 = load i64, i64* %10
%106 = add i64 %105, 1
store i64 %106, i64* %10
%107 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%108 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %107, i32 1
store %struct.TYPE_5__* %108, %struct.TYPE_5__** %7
br label %47
109: ; preds = %47
br label %110
110: ; preds = %109, %28
br label %111
111: ; preds = %110
%112 = load i64, i64* %6
%113 = add i64 %112, 1
store i64 %113, i64* %6
%114 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%115 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %114, i32 1
store %struct.TYPE_6__* %115, %struct.TYPE_6__** %4
br label %22
116: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64, i32, i32, i64 }
%struct.TYPE_5__ = type { i32, i32 }
@SHT_SYMTAB = global i64 0
@STT_FUNC = global i8 0
@STT_OBJECT = global i8 0
@STB_WEAK = global i32 0
define void @build_symbol_list(i8* %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = sext i32 %3 to i64
%5 = getelementptr i8, i8* %0, i64 %4
%6 = bitcast i8* %5 to %struct.TYPE_6__*
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = bitcast i8* %7 to i64*
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %77, label %11
11: ; preds = %1, %72
%12 = phi i64 [ %73, %72 ], [ %9, %1 ]
%13 = phi %struct.TYPE_6__* [ %75, %72 ], [ %6, %1 ]
%14 = phi i64 [ %74, %72 ], [ 0, %1 ]
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @SHT_SYMTAB
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %72
19: ; preds = %11
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 2
%21 = load i32, i32* %20
%22 = icmp ult i32 %21, 8
br i1 %22, label %72, label %23
23: ; preds = %19
%24 = sext i32 %21 to i64
%25 = lshr i64 %24, 3
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 1
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr i8, i8* %0, i64 %28
%30 = bitcast i8* %29 to %struct.TYPE_5__*
%31 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 0, i32 3
%32 = call i64 @llvm.umax.i64(i64 %25, i64 1)
br label %33
33: ; preds = %23, %66
%34 = phi i64 [ 0, %23 ], [ %67, %66 ]
%35 = phi %struct.TYPE_5__* [ %30, %23 ], [ %68, %66 ]
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i64 0, i32 1
%37 = load i32, i32* %36
%38 = tail call signext i8 @ELF32_ST_TYPE(i32 %37)
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i64 0, i32 0
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %66, label %42
42: ; preds = %33
%43 = load i8, i8* @STT_FUNC
%44 = and i8 %43, %38
%45 = icmp eq i8 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8, i8* @STT_OBJECT
%48 = and i8 %47, %38
%49 = icmp eq i8 %48, 0
br i1 %49, label %66, label %50
50: ; preds = %46, %42
%51 = load i32, i32* %36
%52 = tail call i32 @ELF32_ST_BIND(i32 %51)
%53 = load i32, i32* @STB_WEAK
%54 = and i32 %53, %52
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %50
%57 = load i64, i64* %31
%58 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %6, i64 %57, i32 1
%59 = load i32, i32* %58
%60 = sext i32 %59 to i64
%61 = getelementptr i8, i8* %0, i64 %60
%62 = load i32, i32* %39
%63 = sext i32 %62 to i64
%64 = getelementptr i8, i8* %61, i64 %63
%65 = tail call i32 @add_sym(%struct.TYPE_5__* %35, i8* %64)
br label %66
66: ; preds = %50, %46, %33, %56
%67 = add nuw nsw i64 %34, 1
%68 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i64 1
%69 = icmp eq i64 %67, %32
br i1 %69, label %70, label %33
70: ; preds = %66
%71 = load i64, i64* %8
br label %72
72: ; preds = %70, %19, %11
%73 = phi i64 [ %71, %70 ], [ %12, %19 ], [ %12, %11 ]
%74 = add nuw i64 %14, 1
%75 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i64 1
%76 = icmp ult i64 %74, %73
br i1 %76, label %11, label %77
77: ; preds = %72, %1
ret void
}