#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *initialize();
int /*<<< orphan*/ insert(void *, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ test_dump(void *);
int main(int argc, char *argv[]) {
  char s[2 * 30];
  char key[2 * 30];
  int i;
  FILE *input;
  FILE *output;
  void *ds;
  if (argc < 2) {
    fprintf(stderr, "input file needed\n");
    exit(EXIT_FAILURE);
  }
  ds = initialize();
  input = fopen(argv[1], "r");
  if (argc == 3) {
    output = fopen(argv[2], "w");
    if (output == NULL) {
      fprintf(stderr,
              "Aborting, cannot open file: "
              " %s\n",
              argv[2]);
      exit(EXIT_FAILURE);
    }
  } else {
    output = NULL;
  }
  if (input == NULL) {
    fprintf(stderr, "Aborting, cannot open file: %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  for (i = 0; fgets(s, 30 + 1, input) != NULL; i++) {
    sscanf(s, "%s", key);
    insert(ds, key, i, output);
  }
  fclose(input);
  if (output != NULL)
    fclose(output);
  if (0) {
    printf("final tree:\n");
    test_dump(ds);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c8 <main+0x48>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1040 <initialize@plt>
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1256 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    1251 <main+0xd1>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1261 <main+0xe1>
movq   $0x0,-0xa8(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    129c <main+0x11c>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x94(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    $0x1f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1310 <main+0x190>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xd81(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0xb0(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edx
mov    -0xa8(%rbp),%rcx
call   1080 <insert@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    12a6 <main+0x126>
mov    -0xa0(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0xa8(%rbp)
je     1336 <main+0x1b6>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x1,%edi
jle    1273 <main+0xf3>
mov    %rsi,%r12
mov    %edi,%ebx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <initialize@plt>
mov    %rax,%r14
mov    0x8(%r12),%rdi
lea    0xe5b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r13
cmp    $0x3,%ebx
jne    11e2 <main+0x62>
mov    0x10(%r12),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     12a3 <main+0x123>
test   %r13,%r13
je     128c <main+0x10c>
mov    %rsp,%rdi
mov    $0x1f,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124a <main+0xca>
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0x40(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe3e(%rip),%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%rcx
call   1080 <insert@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1f,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1210 <main+0x90>
mov    %r13,%rdi
call   1030 <fclose@plt>
test   %r15,%r15
je     125f <main+0xdf>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12bf <main+0x13f>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
lea    0xd97(%rip),%rsi
jmp    12b8 <main+0x138>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r12),%rdx
lea    0xd5f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"input file needed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [33 x i8] c"Aborting, cannot open file: %s\0A\00"
@.str.4 = [32 x i8] c"Aborting, cannot open file: %s\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [60 x i8]
%7 = alloca [60 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i8* (...) @initialize()
store i8* %20, i8** %11
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %9
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %43
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %10
%32 = load i32*, i32** %10
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %42
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %27
br label %44
43: ; preds = %19
store i32* null, i32** %10
br label %44
44: ; preds = %43, %42
%45 = load i32*, i32** %9
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
store i32 0, i32* %8
br label %56
56: ; preds = %70, %55
%57 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%58 = load i32*, i32** %9
%59 = call i32* @fgets(i8* %57, i32 31, i32* %58)
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %73
61: ; preds = %56
%62 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%63 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%64 = call i32 @sscanf(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = load i8*, i8** %11
%66 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%67 = load i32, i32* %8
%68 = load i32*, i32** %10
%69 = call i32 @insert(i8* %65, i8* %66, i32 %67, i32* %68)
br label %70
70: ; preds = %61
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
store i32 %72, i32* %8
br label %56
73: ; preds = %56
%74 = load i32*, i32** %9
%75 = call i32 @fclose(i32* %74)
%76 = load i32*, i32** %10
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i32*, i32** %10
%80 = call i32 @fclose(i32* %79)
br label %81
81: ; preds = %78, %73
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"input file needed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [33 x i8] c"Aborting, cannot open file: %s\0A\00"
@.str.4 = [32 x i8] c"Aborting, cannot open file: %s\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [60 x i8]
%4 = alloca [60 x i8]
%5 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i8* (...) @initialize()
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %0, 3
br i1 %18, label %19, label %30
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %20
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %13, %19
%31 = phi i32* [ %22, %19 ], [ null, %13 ]
%32 = icmp eq i32* %17, null
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i32* @fgets(i8* %5, i32 31, i32* %17)
%35 = icmp eq i32* %34, null
br i1 %35, label %49, label %42
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %15
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %33, %42
%43 = phi i32 [ %46, %42 ], [ 0, %33 ]
%44 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%45 = call i32 @insert(i8* %14, i8* %6, i32 %43, i32* %31)
%46 = add nuw nsw i32 %43, 1
%47 = call i32* @fgets(i8* %5, i32 31, i32* %17)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %42
49: ; preds = %42, %33
%50 = call i32 @fclose(i32* %17)
%51 = icmp eq i32* %31, null
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @fclose(i32* %31)
br label %54
54: ; preds = %52, %49
ret i32 0
}