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

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ strcmp(char *, char const *);
char *strdup(char const *);
int findname(char **tab, const char *name) {
  int i;
  for (i = 0; i < 1024 && tab[i] != NULL; i++) {
    if (strcmp(tab[i], name) == 0) {
      return i;
    }
  }
  if (i == 1024)
    errx(1, "too many names");
  if ((tab[i] = strdup(name)) == NULL)
    err(1, "strdup");
  return i;
}


x86 assembly (clang, -O0):
<findname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jge    117c <findname+0x3c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118c <findname+0x4c>
jmp    11c9 <findname+0x89>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b6 <findname+0x76>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <findname+0xdd>
jmp    11bb <findname+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <findname+0x17>
cmpl   $0x400,-0x1c(%rbp)
jne    11e7 <findname+0xa7>
mov    $0x1,%edi
lea    0xe1e(%rip),%rsi
call   1030 <errx@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1217 <findname+0xd7>
mov    $0x1,%edi
lea    0xdfd(%rip),%rsi
call   1050 <err@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     1189 <findname+0x49>
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ad <findname+0x6d>
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1150 <findname+0x10>
lea    0xe86(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    $0x400,%ebx
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %ebx,%ecx
mov    %rax,(%r14,%rcx,8)
test   %rax,%rax
jne    11ad <findname+0x6d>
lea    0xe6c(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"too many names\00"
@.str.1 = [7 x i8] c"strdup\00"
define i32 @findname(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %31, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i8**, i8*** %4
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br label %17
17: ; preds = %10, %7
%18 = phi i1 [ false, %7 ], [ %16, %10 ]
br i1 %18, label %19, label %34
19: ; preds = %17
%20 = load i8**, i8*** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i8*, i8** %5
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %51
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %17
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 1024
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @errx(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = load i8*, i8** %5
%41 = call i8* @strdup(i8* %40)
%42 = load i8**, i8*** %4
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
store i8* %41, i8** %45
%46 = icmp eq i8* %41, null
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %39
%50 = load i32, i32* %6
store i32 %50, i32* %3
br label %51
51: ; preds = %49, %28
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [15 x i8] c"too many names\00"
@.str.1 = [7 x i8] c"strdup\00"
define i32 @findname(i8** nocapture %0, i8* %1) {
br label %3
3: ; preds = %2, %11
%4 = phi i64 [ 0, %2 ], [ %12, %11 ]
%5 = getelementptr inbounds i8*, i8** %0, i64 %4
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %3
%9 = tail call i64 @strcmp(i8* %6, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = add nuw nsw i64 %4, 1
%13 = icmp eq i64 %12, 1024
br i1 %13, label %14, label %3
14: ; preds = %11
%15 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %3
%17 = trunc i64 %4 to i32
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ 1024, %14 ], [ %17, %16 ]
%20 = tail call i8* @strdup(i8* %1)
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %0, i64 %21
store i8* %20, i8** %22
%23 = icmp eq i8* %20, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %28
26: ; preds = %8
%27 = trunc i64 %4 to i32
br label %28
28: ; preds = %26, %18, %24
%29 = phi i32 [ %19, %18 ], [ %19, %24 ], [ %27, %26 ]
ret i32 %29
}