#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*/ O_RDONLY;
int STDIN_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ create_entries(int);
scalar_t__ dump_proto(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
void *optarg;
scalar_t__ optind;
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int ch, fh_in;
  FILE *out;
  const char *base_path;
  char *input_file, *output_file;
  input_file = NULL;
  output_file = NULL;
  base_path = ".";
  fh_in = STDIN_FILENO;
  out = stdout;
  while ((ch = getopt(argc, argv, "i:b:o:h")) != -1) {
    switch (ch) {
    case 'i':
      input_file = optarg;
      break;
    case 'b':
      base_path = optarg;
      break;
    case 'o':
      output_file = optarg;
      break;
    case 'h':
      print_usage();
      exit(0);
      break;
    default:
      print_usage();
      exit(1);
    }
  }
  argc -= optind;
  argv += optind;
  if (input_file) {
    fh_in = open(input_file, O_RDONLY);
    if (fh_in == -1) {
      fprintf(stderr, "Failed to open input file (%s):%s\n", input_file,
              strerror(errno));
      exit(1);
    }
  }
  if (output_file) {
    out = fopen(output_file, "w+");
    if (!out) {
      fprintf(stderr, "Failed to open input file (%s):%s\n", input_file,
              strerror(errno));
      exit(1);
    }
  }
  if (create_entries(fh_in)) {
    fprintf(stderr, "Failed to create entries\n");
    exit(1);
  }
  if (input_file)
    close(fh_in);
  if (dump_proto(out, base_path)) {
    fprintf(stderr, "Failed to create entries\n");
    exit(1);
  }
  if (output_file)
    fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe31(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12a0 <main+0xf0>
mov    -0x14(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0xd,%eax
ja     128a <main+0xda>
mov    -0x40(%rbp),%rax
lea    0xdc6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dae(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    129b <main+0xeb>
mov    0x2d9b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    129b <main+0xeb>
mov    0x2d88(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    129b <main+0xeb>
mov    $0x0,%al
call   10a0 <print_usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10a0 <print_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11fb <main+0x4b>
mov    0x2d31(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     133d <main+0x18d>
mov    -0x30(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1338 <main+0x188>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    133d <main+0x18d>
cmpq   $0x0,-0x38(%rbp)
je     13b0 <main+0x200>
mov    -0x38(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13ab <main+0x1fb>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    13b0 <main+0x200>
mov    -0x18(%rbp),%edi
call   10d0 <create_entries@plt>
cmp    $0x0,%rax
je     13e3 <main+0x233>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
lea    0xc96(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
je     13f6 <main+0x246>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <dump_proto@plt>
cmp    $0x0,%rax
je     142e <main+0x27e>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
je     1442 <main+0x292>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%r12d
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
lea    0xe19(%rip),%rax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
lea    0xe0c(%rip),%r14
mov    0x2dfb(%rip),%r15
xor    %ebx,%ebx
jmp    1213 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rbx
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x6f,%eax
je     1210 <main+0x60>
cmp    $0x67,%eax
jg     1243 <main+0x93>
cmp    $0xffffffff,%eax
je     1251 <main+0xa1>
cmp    $0x62,%eax
jne    12f6 <main+0x146>
mov    (%r15),%rax
mov    %rax,0x8(%rsp)
jmp    1213 <main+0x63>
cmp    $0x69,%eax
jne    12e3 <main+0x133>
mov    (%r15),%r13
jmp    1213 <main+0x63>
test   %r13,%r13
mov    0x4(%rsp),%ebp
je     1276 <main+0xc6>
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1328 <main+0x178>
test   %rbx,%rbx
mov    0x10(%rsp),%r14
je     129b <main+0xeb>
lea    0xda6(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1328 <main+0x178>
mov    %ebp,%edi
call   10d0 <create_entries@plt>
test   %rax,%rax
jne    1307 <main+0x157>
test   %r13,%r13
je     12b3 <main+0x103>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %r14,%rdi
mov    0x8(%rsp),%rsi
call   10b0 <dump_proto@plt>
test   %rax,%rax
jne    1307 <main+0x157>
test   %rbx,%rbx
je     12d2 <main+0x122>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    12f6 <main+0x146>
xor    %eax,%eax
call   10a0 <print_usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   10a0 <print_usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%ebx
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcc4(%rip),%rsi
mov    %ebx,%edi
mov    %r13,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@STDIN_FILENO = global i32 0
@stdout = global i32* null
@.str.1 = [8 x i8] c"i:b:o:h\00"
@optarg = global i8* null
@optind = global i64 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [35 x i8] c"Failed to open input file (%s):%s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [26 x i8] c"Failed to create entries\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %11
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9
%12 = load i32, i32* @STDIN_FILENO
store i32 %12, i32* %7
%13 = load i32*, i32** @stdout
store i32* %13, i32** %8
br label %14
14: ; preds = %33, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = load i32, i32* %6
switch i32 %20, label %30 [
i32 105, label %21
i32 98, label %23
i32 111, label %25
i32 104, label %27
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
store i8* %22, i8** %10
br label %33
23: ; preds = %19
%24 = load i8*, i8** @optarg
store i8* %24, i8** %9
br label %33
25: ; preds = %19
%26 = load i8*, i8** @optarg
store i8* %26, i8** %11
br label %33
27: ; preds = %19
%28 = call i32 (...) @print_usage()
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %19
%31 = call i32 (...) @print_usage()
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25, %23, %21
br label %14
34: ; preds = %14
%35 = load i64, i64* @optind
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %4
%40 = load i64, i64* @optind
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 %40
store i8** %42, i8*** %5
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %59
45: ; preds = %34
%46 = load i8*, i8** %10
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* %46, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %58
51: ; preds = %45
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %10
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %53, i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %45
br label %59
59: ; preds = %58, %34
%60 = load i8*, i8** %11
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %75
62: ; preds = %59
%63 = load i8*, i8** %11
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %64, i32** %8
%65 = load i32*, i32** %8
%66 = icmp ne i32* %65, null
br i1 %66, label %74, label %67
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %10
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %69, i8* %71)
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %62
br label %75
75: ; preds = %74, %59
%76 = load i32, i32* %7
%77 = call i64 @create_entries(i32 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %75
%84 = load i8*, i8** %10
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
br label %89
89: ; preds = %86, %83
%90 = load i32*, i32** %8
%91 = load i8*, i8** %9
%92 = call i64 @dump_proto(i32* %90, i8* %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %89
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %89
%99 = load i8*, i8** %11
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32*, i32** %8
%103 = call i32 @fclose(i32* %102)
br label %104
104: ; preds = %101, %98
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@STDIN_FILENO = global i32 0
@stdout = global i32* null
@.str.1 = [8 x i8] c"i:b:o:h\00"
@optarg = global i8* null
@optind = global i64 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [35 x i8] c"Failed to open input file (%s):%s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [26 x i8] c"Failed to create entries\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @STDIN_FILENO
%4 = load i32*, i32** @stdout
br label %5
5: ; preds = %17, %2
%6 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%7 = phi i8* [ %10, %17 ], [ null, %2 ]
%8 = phi i8* [ %13, %17 ], [ null, %2 ]
br label %9
9: ; preds = %5, %15
%10 = phi i8* [ %7, %5 ], [ %16, %15 ]
%11 = phi i8* [ %8, %5 ], [ %13, %15 ]
br label %12
12: ; preds = %9, %19
%13 = phi i8* [ %20, %19 ], [ %11, %9 ]
%14 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
switch i32 %14, label %24 [
i32 -1, label %27
i32 105, label %15
i32 98, label %17
i32 111, label %19
i32 104, label %21
]
15: ; preds = %12
%16 = load i8*, i8** @optarg
br label %9
17: ; preds = %12
%18 = load i8*, i8** @optarg
br label %5
19: ; preds = %12
%20 = load i8*, i8** @optarg
br label %12
21: ; preds = %12
%22 = tail call i32 (...) @print_usage()
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %12
%25 = tail call i32 (...) @print_usage()
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %12
%28 = icmp eq i8* %10, null
br i1 %28, label %39, label %29
29: ; preds = %27
%30 = load i32, i32* @O_RDONLY
%31 = tail call i32 @open(i8* %10, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %29, %27
%40 = phi i32 [ %31, %29 ], [ %3, %27 ]
%41 = icmp eq i8* %13, null
br i1 %41, label %51, label %42
42: ; preds = %39
%43 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = tail call i8* @strerror(i32 %47)
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %48)
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %42, %39
%52 = phi i32* [ %43, %42 ], [ %4, %39 ]
%53 = tail call i64 @create_entries(i32 %40)
%54 = icmp eq i64 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %51
br i1 %28, label %62, label %60
60: ; preds = %59
%61 = tail call i32 @close(i32 %40)
br label %62
62: ; preds = %60, %59
%63 = tail call i64 @dump_proto(i32* %52, i8* %6)
%64 = icmp eq i64 %63, 0
br i1 %64, label %69, label %65
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%68 = tail call i32 @exit(i32 1)
unreachable
69: ; preds = %62
br i1 %41, label %72, label %70
70: ; preds = %69
%71 = tail call i32 @fclose(i32* %52)
br label %72
72: ; preds = %70, %69
ret i32 0
}