#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 append_to_buf(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int parse_record(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp;
  char c, buf[4096], line[1024];
  int html = 0;
  int err = 0;
  if (argc < 2) {
    fprintf(stderr, "Give the name of a .bbl file\n");
    exit(EXIT_FAILURE);
  }
  if (argc == 3 && !strcmp(argv[2], "--html")) {
    html = 1;
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    fprintf(stderr, "Couldn't open %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  if (html) {
    printf("<h1>References</h1>\n\n");
  } else {
    printf("<@hd1=\"References\">\n\n");
  }
  *buf = '\0';
  while (fgets(line, sizeof line, fp) && !err) {
    c = fgetc(fp);
    if (c == '\n' || c == '\r') {
      err = append_to_buf(buf, line);
      if (!err) {
        err = parse_record(buf, html);
      }
      *buf = '\0';
    } else {
      ungetc(c, fp);
      err = append_to_buf(buf, line);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1424(%rbp)
movl   $0x0,-0x1428(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    120c <main+0x5c>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    123d <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    123d <main+0x8d>
movl   $0x1,-0x1424(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    128d <main+0xdd>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x1424(%rbp)
je     12ab <main+0xfb>
lea    0xd98(%rip),%rdi
call   1050 <printf@plt>
jmp    12b7 <main+0x107>
lea    0xd9d(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,-0x1020(%rbp)
lea    -0x1420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1429(%rbp)
je     12fa <main+0x14a>
cmpl   $0x0,-0x1428(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x1429(%rbp)
mov    -0x1429(%rbp),%al
test   $0x1,%al
jne    130d <main+0x15d>
jmp    13aa <main+0x1fa>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     1333 <main+0x183>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
jne    137d <main+0x1cd>
lea    -0x1020(%rbp),%rdi
lea    -0x1420(%rbp),%rsi
call   1030 <append_to_buf@plt>
mov    %eax,-0x1428(%rbp)
cmpl   $0x0,-0x1428(%rbp)
jne    1371 <main+0x1c1>
lea    -0x1020(%rbp),%rdi
mov    -0x1424(%rbp),%esi
call   10b0 <parse_record@plt>
mov    %eax,-0x1428(%rbp)
movb   $0x0,-0x1020(%rbp)
jmp    13a5 <main+0x1f5>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   10a0 <ungetc@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1420(%rbp),%rsi
call   1030 <append_to_buf@plt>
mov    %eax,-0x1428(%rbp)
jmp    12be <main+0x10e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1400,%rsp
cmp    $0x1,%edi
jle    12fb <main+0x14b>
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    1213 <main+0x63>
mov    0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1080 <strcmp@plt>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1314 <main+0x164>
mov    %rax,%rbx
test   %r14d,%r14d
jne    122f <main+0x7f>
mov    $0x1,%r14d
lea    0xe3d(%rip),%rdi
jmp    1239 <main+0x89>
mov    0x8(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1314 <main+0x164>
xor    %r14d,%r14d
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,0x400(%rsp)
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e1 <main+0x131>
lea    0x400(%rsp),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0xd,%al
je     1280 <main+0xd0>
cmp    $0xa,%al
jne    12b0 <main+0x100>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <append_to_buf@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    129e <main+0xee>
mov    %r15,%rdi
mov    %r14d,%esi
call   10b0 <parse_record@plt>
mov    %eax,%ebp
movb   $0x0,0x400(%rsp)
jmp    12c8 <main+0x118>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   10a0 <ungetc@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <append_to_buf@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e1 <main+0x131>
test   %ebp,%ebp
je     1270 <main+0xc0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x1400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1333 <main+0x183>
add    $0x8,%rbp
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xcfb(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Give the name of a .bbl file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"--html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.4 = [22 x i8] c"<h1>References</h1>\0A\0A\00"
@.str.5 = [22 x i8] c"<@hd1=\22References\22>\0A\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 [4096 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
%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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 1, i32* %10
br label %29
29: ; preds = %28, %22, %19
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %44
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %29
%45 = load i32, i32* %10
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %51
49: ; preds = %44
%50 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
store i8 0, i8* %52
br label %53
53: ; preds = %93, %51
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%55 = load i32*, i32** %6
%56 = call i64 @fgets(i8* %54, i32 1024, i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32, i32* %11
%60 = icmp ne i32 %59, 0
%61 = xor i1 %60, true
br label %62
62: ; preds = %58, %53
%63 = phi i1 [ false, %53 ], [ %61, %58 ]
br i1 %63, label %64, label %94
64: ; preds = %62
%65 = load i32*, i32** %6
%66 = call signext i8 @fgetc(i32* %65)
store i8 %66, i8* %7
%67 = load i8, i8* %7
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 10
br i1 %69, label %74, label %70
70: ; preds = %64
%71 = load i8, i8* %7
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 13
br i1 %73, label %74, label %86
74: ; preds = %70, %64
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%77 = call i32 @append_to_buf(i8* %75, i8* %76)
store i32 %77, i32* %11
%78 = load i32, i32* %11
%79 = icmp ne i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %74
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%82 = load i32, i32* %10
%83 = call i32 @parse_record(i8* %81, i32 %82)
store i32 %83, i32* %11
br label %84
84: ; preds = %80, %74
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
store i8 0, i8* %85
br label %93
86: ; preds = %70
%87 = load i8, i8* %7
%88 = load i32*, i32** %6
%89 = call i32 @ungetc(i8 signext %87, i32* %88)
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%92 = call i32 @append_to_buf(i8* %90, i8* %91)
store i32 %92, i32* %11
br label %93
93: ; preds = %86, %84
br label %53
94: ; preds = %62
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Give the name of a .bbl file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"--html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"Couldn't open %s\0A\00"
@str = [21 x i8] c"<@hd1=\22References\22>\0A\00"
@str.6 = [21 x i8] c"<h1>References</h1>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 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 ([30 x i8], [30 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 = icmp eq i32 %0, 3
br i1 %14, label %15, label %23
15: ; preds = %13
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %17, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %28, label %35
23: ; preds = %13
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %37
28: ; preds = %23, %15
%29 = phi i8** [ %24, %23 ], [ %19, %15 ]
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %29
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %15
%36 = icmp eq i32 %18, 0
br i1 %36, label %39, label %37
37: ; preds = %23, %35
%38 = phi i32* [ %21, %35 ], [ %26, %23 ]
br label %39
39: ; preds = %35, %37
%40 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %37 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0), %35 ]
%41 = phi i32 [ 0, %37 ], [ 1, %35 ]
%42 = phi i32* [ %38, %37 ], [ %21, %35 ]
%43 = tail call i32 @puts(i8* dereferenceable(1) %40)
store i8 0, i8* %5
%44 = call i64 @fgets(i8* %6, i32 1024, i32* %42)
%45 = icmp eq i64 %44, 0
br i1 %45, label %64, label %46
46: ; preds = %39, %58
%47 = call signext i8 @fgetc(i32* %42)
switch i8 %47, label %55 [
i8 13, label %48
i8 10, label %48
]
48: ; preds = %46, %46
%49 = call i32 @append_to_buf(i8* %5, i8* %6)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @parse_record(i8* %5, i32 %41)
br label %53
53: ; preds = %51, %48
%54 = phi i32 [ %49, %48 ], [ %52, %51 ]
store i8 0, i8* %5
br label %58
55: ; preds = %46
%56 = call i32 @ungetc(i8 signext %47, i32* %42)
%57 = call i32 @append_to_buf(i8* %5, i8* %6)
br label %58
58: ; preds = %55, %53
%59 = phi i32 [ %54, %53 ], [ %57, %55 ]
%60 = call i64 @fgets(i8* %6, i32 1024, i32* %42)
%61 = icmp ne i64 %60, 0
%62 = icmp eq i32 %59, 0
%63 = select i1 %61, i1 %62, i1 false
br i1 %63, label %46, label %64
64: ; preds = %58, %39
%65 = call i32 @fclose(i32* %42)
ret i32 0
}