#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *, long long *);
long long get_key_hash(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stdout,
            "#######################################################\n");
    fprintf(stdout, "#\n");
    fprintf(stdout,
            "# Function: Compute the Redis hash for keyfile [keyfilename]\n");
    fprintf(stdout, "# keyfile format: KEYNAME INT(TTL)\n");
    fprintf(stdout, "#\n");
    fprintf(stdout,
            "#######################################################\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Usage: %s [keyfilename]\n", argv[0]);
    fprintf(stdout, "exit..\n");
  }
  char key[10240];
  FILE *kf;
  long long ttl;
  kf = fopen(argv[1], "r");
  if (kf == NULL) {
    fprintf(stdout, "key file not eixst.\n");
    return 1;
  }
  while (fscanf(kf, "%s %lld", key, &ttl) == 2) {
    long long hashval = get_key_hash(key, strlen(key));
    fprintf(stdout, "%s %lld\n", key, hashval);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1249 <main+0xf9>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x2818(%rbp)
cmpq   $0x0,-0x2818(%rbp)
jne    1295 <main+0x145>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1cd>
jmp    129a <main+0x14a>
mov    -0x2818(%rbp),%rdi
lea    -0x2810(%rbp),%rdx
lea    0xe24(%rip),%rsi
lea    -0x2820(%rbp),%rcx
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    131d <main+0x1cd>
lea    -0x2810(%rbp),%rax
mov    %rax,-0x2830(%rbp)
lea    -0x2810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2830(%rbp),%rdi
mov    %eax,%esi
call   1030 <get_key_hash@plt>
mov    %rax,-0x2828(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    -0x2810(%rbp),%rdx
mov    -0x2828(%rbp),%rcx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    129a <main+0x14a>
mov    -0x4(%rbp),%eax
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2818,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     120e <main+0xbe>
mov    0x2e6c(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe82(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xea4(%rip),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe93(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xec0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe55(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xea5(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xead(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rbx),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12b3 <main+0x163>
mov    %rax,%r14
lea    0xea2(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jne    12cf <main+0x17f>
lea    0x10(%rsp),%rbx
lea    0xe81(%rip),%r15
lea    0xe72(%rip),%r12
lea    0x8(%rsp),%r13
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <get_key_hash@plt>
mov    0x2d57(%rip),%rcx
mov    (%rcx),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1050 <fscanf@plt>
cmp    $0x2,%eax
je     1270 <main+0x120>
jmp    12cf <main+0x17f>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x2818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [57 x i8] c"#######################################################\0A\00"
@.str.1 = [3 x i8] c"#\0A\00"
@.str.2 = [62 x i8] c"# Function: Compute the Redis hash for keyfile [keyfilename]\0A\00"
@.str.3 = [36 x i8] c"# keyfile format: KEYNAME INT(TTL)\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [25 x i8] c"Usage: %s [keyfilename]\0A\00"
@.str.6 = [8 x i8] c"exit..\0A\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [21 x i8] c"key file not eixst.\0A\00"
@.str.9 = [8 x i8] c"%s %lld\00"
@.str.10 = [9 x i8] c"%s %lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10240 x i8]
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %34
12: ; preds = %2
%13 = load i32, i32* @stdout
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %12, %2
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %59
44: ; preds = %34
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %7
%47 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%48 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %47, i64* %8)
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %59
50: ; preds = %45
%51 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%52 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = call i64 @get_key_hash(i8* %51, i32 %53)
store i64 %54, i64* %9
%55 = load i32, i32* @stdout
%56 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%57 = load i64, i64* %9
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %56, i64 %57)
br label %45
59: ; preds = %41, %45
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [57 x i8] c"#######################################################\0A\00"
@.str.1 = [3 x i8] c"#\0A\00"
@.str.2 = [62 x i8] c"# Function: Compute the Redis hash for keyfile [keyfilename]\0A\00"
@.str.3 = [36 x i8] c"# keyfile format: KEYNAME INT(TTL)\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [25 x i8] c"Usage: %s [keyfilename]\0A\00"
@.str.6 = [8 x i8] c"exit..\0A\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [21 x i8] c"key file not eixst.\0A\00"
@.str.9 = [8 x i8] c"%s %lld\00"
@.str.10 = [9 x i8] c"%s %lld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10240 x i8]
%4 = alloca i64
%5 = icmp eq i32 %0, 2
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = load i32, i32* @stdout
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = load i8*, i8** %1
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @stdout
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %26
26: ; preds = %6, %2
%27 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%28 = bitcast i64* %4 to i8*
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %26
%34 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %27, i64* %4)
%35 = icmp eq i32 %34, 2
br i1 %35, label %39, label %46
36: ; preds = %26
%37 = load i32, i32* @stdout
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %46
39: ; preds = %33, %39
%40 = call i32 @strlen(i8* %27)
%41 = call i64 @get_key_hash(i8* %27, i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %27, i64 %41)
%44 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %27, i64* %4)
%45 = icmp eq i32 %44, 2
br i1 %45, label %39, label %46
46: ; preds = %39, %33, %36
%47 = phi i32 [ 1, %36 ], [ 0, %33 ], [ 0, %39 ]
ret i32 %47
}