#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_3__ TYPE_1__;

/* Type definitions */
typedef int uint32_t;
struct TYPE_3__ {
  int st_name;
};
typedef TYPE_1__ Elf32_Sym;

/* Variables and functions */
int elf_hash(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int lookup(char *name, uint32_t *hash, Elf32_Sym *sym, char *str) {
  uint32_t nbuckets, nchains, *buckets, *chains, h, idx;
  nbuckets = hash[0];
  nchains = hash[1];
  buckets = hash + 2;
  chains = buckets + nbuckets;
  h = elf_hash(name) % nbuckets;
  for (idx = buckets[h]; idx != 0; idx = chains[idx]) {
    if (!strcmp(name, sym[idx].st_name + str))
      return idx;
  }
  return -1;
}


x86 assembly (clang, -O0):
<lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <elf_hash@plt>
cltd
idivl  -0x2c(%rbp)
mov    %edx,-0x44(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     11db <lookup+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x28(%rbp),%rsi
cltq
add    %rax,%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c3 <lookup+0xa3>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <lookup+0xc2>
jmp    11c8 <lookup+0xa8>
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x48(%rbp)
jmp    1188 <lookup+0x68>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movslq (%rsi),%rbx
call   1040 <elf_hash@plt>
cltd
idiv   %ebx
movslq %edx,%rax
mov    0x8(%r12,%rax,4),%ebp
test   %ebp,%ebp
je     117e <lookup+0x5e>
lea    (%r12,%rbx,4),%r12
add    $0x8,%r12
cs nopw 0x0(%rax,%rax,1)
movslq %ebp,%rbx
movslq (%r15,%rbx,4),%rsi
add    %r14,%rsi
mov    %r13,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1183 <lookup+0x63>
mov    (%r12,%rbx,4),%ebp
test   %ebp,%ebp
jne    1160 <lookup+0x40>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
define i32 @lookup(i8* %0, i32* %1, %struct.TYPE_3__* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.TYPE_3__*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store %struct.TYPE_3__* %2, %struct.TYPE_3__** %8
store i8* %3, i8** %9
%16 = load i32*, i32** %7
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
store i32 %18, i32* %10
%19 = load i32*, i32** %7
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
store i32 %21, i32* %11
%22 = load i32*, i32** %7
%23 = getelementptr inbounds i32, i32* %22, i64 2
store i32* %23, i32** %12
%24 = load i32*, i32** %12
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32* %27, i32** %13
%28 = load i8*, i8** %6
%29 = call i32 @elf_hash(i8* %28)
%30 = load i32, i32* %10
%31 = srem i32 %29, %30
store i32 %31, i32* %14
%32 = load i32*, i32** %12
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
store i32 %36, i32* %15
br label %37
37: ; preds = %56, %4
%38 = load i32, i32* %15
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %62
40: ; preds = %37
%41 = load i8*, i8** %6
%42 = load %struct.TYPE_3__*, %struct.TYPE_3__** %8
%43 = load i32, i32* %15
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i64 %44
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = load i8*, i8** %9
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
%51 = call i32 @strcmp(i8* %41, i8* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %40
%54 = load i32, i32* %15
store i32 %54, i32* %5
br label %63
55: ; preds = %40
br label %56
56: ; preds = %55
%57 = load i32*, i32** %13
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
store i32 %61, i32* %15
br label %37
62: ; preds = %37
store i32 -1, i32* %5
br label %63
63: ; preds = %62, %53
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
define i32 @lookup(i8* %0, i32* nocapture %1, %struct.TYPE_3__* nocapture %2, i8* nocapture %3) {
%5 = load i32, i32* %1
%6 = getelementptr inbounds i32, i32* %1, i64 2
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i32, i32* %6, i64 %7
%9 = tail call i32 @elf_hash(i8* %0)
%10 = srem i32 %9, %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %6, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %4, %24
%16 = phi i32 [ %26, %24 ], [ %13, %4 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 %17, i32 0
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %3, i64 %20
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = getelementptr inbounds i32, i32* %8, i64 %17
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %15, %24, %4
%29 = phi i32 [ -1, %4 ], [ -1, %24 ], [ %16, %15 ]
ret i32 %29
}