#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 */
typedef int uint64_t;

/* Variables and functions */
int fnv_hash(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int interactive = 0;
  if (!argv[1]) {
    return 1;
  } else if (argv[1][0] == '-') {
    if (!(strcmp(argv[1], "-i"))) {
      interactive = 1;
      argv = argv + 1;
    } else if (!strcmp(argv[1], "-h")) {
      puts("fnv_hash -ih [string]*\n-i = interactive, print extra information");
    }
  }
  char *data = argv[1];
  int i = 1, len;
  uint64_t hashv;
  while (data) {
    len = strlen(data);
    hashv = fnv_hash(data, len);
    printf("%#0lx ", hashv);
    if (interactive) {
      puts(data);
      printf("bucket number %d/128\n", hashv % 128);
    }
    data = argv[++i];
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1188 <main+0x38>
movl   $0x1,-0x4(%rbp)
jmp    12a1 <main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1204 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11d1 <main+0x81>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11ff <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe23(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11fa <main+0xaa>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
jmp    11ff <main+0xaf>
jmp    1204 <main+0xb4>
jmp    1209 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     129a <main+0x14a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1060 <fnv_hash@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     127d <main+0x12d>
mov    -0x20(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x2c(%rbp),%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xdd6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    121c <main+0xcc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rbx
test   %rbx,%rbx
je     11a3 <main+0x53>
mov    %rsi,%r13
mov    $0x1,%r14b
cmpb   $0x2d,(%rbx)
jne    11b1 <main+0x61>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11aa <main+0x5a>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11b1 <main+0x61>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
jmp    11b1 <main+0x61>
mov    $0x1,%eax
jmp    1223 <main+0xd3>
add    $0x8,%r13
xor    %r14d,%r14d
mov    0x8(%r13),%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     1223 <main+0xd3>
add    $0x10,%r13
lea    0xe80(%rip),%r12
lea    0xe80(%rip),%r15
jmp    11dd <main+0x8d>
mov    0x0(%r13),%rbp
add    $0x8,%r13
test   %rbp,%rbp
je     1221 <main+0xd1>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1060 <fnv_hash@plt>
mov    %eax,%ebx
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %r14b,%r14b
jne    11d0 <main+0x80>
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0x7f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffff80,%eax
sub    %eax,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
jmp    11d0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-i\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [65 x i8] c"fnv_hash -ih [string]*\0A-i = interactive, print extra information\00"
@.str.3 = [7 x i8] c"%lx \00"
@.str.4 = [22 x i8] c"bucket number %d/128\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 1, i32* %3
br label %75
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %43
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %24
store i32 1, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
store i8** %32, i8*** %5
br label %42
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %33
%40 = call i32 @puts(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %33
br label %42
42: ; preds = %41, %30
br label %43
43: ; preds = %42, %16
br label %44
44: ; preds = %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
store i8* %47, i8** %7
store i32 1, i32* %8
br label %48
48: ; preds = %67, %44
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %74
51: ; preds = %48
%52 = load i8*, i8** %7
%53 = call i32 @strlen(i8* %52)
store i32 %53, i32* %9
%54 = load i8*, i8** %7
%55 = load i32, i32* %9
%56 = call i32 @fnv_hash(i8* %54, i32 %55)
store i32 %56, i32* %10
%57 = load i32, i32* %10
%58 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %6
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %51
%62 = load i8*, i8** %7
%63 = call i32 @puts(i8* %62)
%64 = load i32, i32* %10
%65 = srem i32 %64, 128
%66 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %61, %51
%68 = load i8**, i8*** %5
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %68, i64 %71
%73 = load i8*, i8** %72
store i8* %73, i8** %7
br label %48
74: ; preds = %48
store i32 0, i32* %3
br label %75
75: ; preds = %74, %15
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [3 x i8] c"-i\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [65 x i8] c"fnv_hash -ih [string]*\0A-i = interactive, print extra information\00"
@.str.3 = [7 x i8] c"%lx \00"
@.str.4 = [22 x i8] c"bucket number %d/128\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %38, label %6
6: ; preds = %2
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 45
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %9, %6, %12, %15
%18 = phi i1 [ true, %6 ], [ true, %12 ], [ true, %15 ], [ false, %9 ]
%19 = phi i8** [ %1, %6 ], [ %1, %12 ], [ %1, %15 ], [ %3, %9 ]
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %38, label %23
23: ; preds = %17, %33
%24 = phi i64 [ %34, %33 ], [ 1, %17 ]
%25 = phi i8* [ %36, %33 ], [ %21, %17 ]
%26 = tail call i32 @strlen(i8* %25)
%27 = tail call i32 @fnv_hash(i8* %25, i32 %26)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br i1 %18, label %33, label %29
29: ; preds = %23
%30 = tail call i32 @puts(i8* %25)
%31 = srem i32 %27, 128
%32 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %23
%34 = add nuw i64 %24, 1
%35 = getelementptr inbounds i8*, i8** %19, i64 %34
%36 = load i8*, i8** %35
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %23
38: ; preds = %33, %17, %2
%39 = phi i32 [ 1, %2 ], [ 0, %17 ], [ 0, %33 ]
ret i32 %39
}