#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 build_file(int /*<<< orphan*/ *, int, char *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fixup_record_count(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *optarg;
int optind;
int output_header(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int main(int argc, char **argv) {
  char output_filename[65541];
  int file_format = 0;
  memset(output_filename, 0, 65541);
  int opt;
  while ((opt = getopt(argc, argv, "do:")) != -1) {
    switch ((char)opt) {
    case 'o':
      strncpy(output_filename, optarg, 65536);
      output_filename[65536] = 0;
      break;
    case 'd':
      file_format = 1;
      break;
    default:
      fprintf(stderr, "Usage: %s [-o <output_filename>] [-d] <filename>...\n",
              argv[0]);
      return 1;
    }
  }
  if (optind >= argc) {
    fprintf(stderr, "Expected at least one input file\n");
    fprintf(stderr, "Usage: %s [-o <output_filename>] [-d] <filename>...\n",
            argv[0]);
    return 1;
  }
  int i;
  if (strlen(output_filename) == 0) {
    for (i = optind; i < argc; i++) {
      if (argv[i]) {
        strncpy(output_filename, argv[i], 65536);
        output_filename[65536] = 0;
        break;
      }
    }
    char *p_dot, *p_slash;
    p_dot = strrchr(output_filename, '.');
    p_slash = strrchr(output_filename, '/');
    if (p_dot && (!p_slash || (p_dot > p_slash))) {
      strcpy(p_dot, ".bin");
    } else {
      strcat(output_filename, ".bin");
    }
  }
  FILE *f = NULL;
  int record_count = 0;
  int ret = 0, sts;
  for (i = optind; i < argc; i++) {
    if (argv[i]) {
      if (!f) {
        f = fopen(output_filename, "wb");
        if (!f) {
          int code = errno;
          char *errstr = strerror(code);
          fprintf(stderr, "main: Error opening %s for output: %s\n",
                  output_filename, errstr);
          return 1;
        }
        sts = output_header(f, file_format);
        if (sts != 0) {
          ret = 1;
          break;
        }
      }
      int cnt;
      cnt = build_file(f, file_format, argv[i]);
      if (cnt < 0)
        ret = 1;
      else
        record_count += cnt;
    }
  }
  if (f) {
    if (ret == 0) {
      sts = fixup_record_count(f, file_format, record_count);
      if (sts != 0) {
        fprintf(stderr, "main: Error updating final record count\n");
        ret = 1;
      }
    }
    fclose(f);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x10024(%rbp)
lea    -0x10020(%rbp),%rdi
xor    %esi,%esi
mov    $0x10005,%edx
call   1090 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xddc(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x10028(%rbp)
cmp    $0xffffffff,%eax
je     12c9 <main+0xe9>
movsbl -0x10028(%rbp),%eax
mov    %eax,-0x10068(%rbp)
sub    $0x64,%eax
je     128b <main+0xab>
jmp    1253 <main+0x73>
mov    -0x10068(%rbp),%eax
sub    $0x6f,%eax
jne    129a <main+0xba>
jmp    1267 <main+0x87>
lea    -0x10020(%rbp),%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%rsi
mov    $0x10000,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
jmp    12c4 <main+0xe4>
movl   $0x1,-0x10024(%rbp)
jmp    12c4 <main+0xe4>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1640 <main+0x460>
jmp    1216 <main+0x36>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     131c <main+0x13c>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1640 <main+0x460>
lea    -0x10020(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%rax
jne    1438 <main+0x258>
mov    0x2ca7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x1002c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13a8 <main+0x1c8>
mov    -0x10(%rbp),%rax
movslq -0x1002c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     138f <main+0x1af>
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1002c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x10000,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
jmp    13a8 <main+0x1c8>
jmp    1394 <main+0x1b4>
mov    -0x1002c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1002c(%rbp)
jmp    1341 <main+0x161>
lea    -0x10020(%rbp),%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x10038(%rbp)
lea    -0x10020(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x10040(%rbp)
cmpq   $0x0,-0x10038(%rbp)
je     1420 <main+0x240>
cmpq   $0x0,-0x10040(%rbp)
je     1408 <main+0x228>
mov    -0x10038(%rbp),%rax
cmp    -0x10040(%rbp),%rax
jbe    1420 <main+0x240>
mov    -0x10038(%rbp),%rdi
lea    0xc45(%rip),%rsi
call   1050 <strcpy@plt>
jmp    1433 <main+0x253>
lea    -0x10020(%rbp),%rdi
lea    0xc2d(%rip),%rsi
call   10e0 <strcat@plt>
jmp    1438 <main+0x258>
movq   $0x0,-0x10048(%rbp)
movl   $0x0,-0x1004c(%rbp)
movl   $0x0,-0x10050(%rbp)
mov    0x2b82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1002c(%rbp)
mov    -0x1002c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    15bf <main+0x3df>
mov    -0x10(%rbp),%rax
movslq -0x1002c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     15a6 <main+0x3c6>
cmpq   $0x0,-0x10048(%rbp)
jne    154c <main+0x36c>
lea    -0x10020(%rbp),%rdi
lea    0xbb9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10048(%rbp)
cmpq   $0x0,-0x10048(%rbp)
jne    1513 <main+0x333>
mov    0x2b00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10058(%rbp)
mov    -0x10058(%rbp),%edi
call   10f0 <strerror@plt>
mov    %rax,-0x10060(%rbp)
mov    0x2ae7(%rip),%rax
mov    (%rax),%edi
lea    -0x10020(%rbp),%rdx
mov    -0x10060(%rbp),%rcx
lea    0xb63(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1640 <main+0x460>
mov    -0x10048(%rbp),%rdi
mov    -0x10024(%rbp),%esi
call   1030 <output_header@plt>
mov    %eax,-0x10054(%rbp)
cmpl   $0x0,-0x10054(%rbp)
je     1547 <main+0x367>
movl   $0x1,-0x10050(%rbp)
jmp    15bf <main+0x3df>
jmp    154c <main+0x36c>
mov    -0x10048(%rbp),%rdi
mov    -0x10024(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1002c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   10a0 <build_file@plt>
mov    %eax,-0x10064(%rbp)
cmpl   $0x0,-0x10064(%rbp)
jge    158f <main+0x3af>
movl   $0x1,-0x10050(%rbp)
jmp    15a1 <main+0x3c1>
mov    -0x10064(%rbp),%eax
add    -0x1004c(%rbp),%eax
mov    %eax,-0x1004c(%rbp)
jmp    15a6 <main+0x3c6>
jmp    15ab <main+0x3cb>
mov    -0x1002c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1002c(%rbp)
jmp    1466 <main+0x286>
cmpq   $0x0,-0x10048(%rbp)
je     1637 <main+0x457>
cmpl   $0x0,-0x10050(%rbp)
jne    162b <main+0x44b>
mov    -0x10048(%rbp),%rdi
mov    -0x10024(%rbp),%esi
mov    -0x1004c(%rbp),%edx
call   1100 <fixup_record_count@plt>
mov    %eax,-0x10054(%rbp)
cmpl   $0x0,-0x10054(%rbp)
je     1626 <main+0x446>
mov    0x29c4(%rip),%rax
mov    (%rax),%edi
lea    0xa75(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x10050(%rbp)
jmp    162b <main+0x44b>
mov    -0x10048(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10050(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
lea    0x10(%rsp),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0x10005,%edx
call   1080 <memset@plt>
lea    0xdfe(%rip),%rdx
mov    %r14d,%edi
mov    %r12,%rsi
call   10c0 <getopt@plt>
cmp    $0xffffffff,%eax
je     127c <main+0xac>
xor    %ebp,%ebp
lea    0xde5(%rip),%rbx
lea    0x10(%rsp),%r13
jmp    1246 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10c0 <getopt@plt>
mov    %r15d,%ebp
cmp    $0xffffffff,%eax
je     127c <main+0xac>
mov    $0x1,%r15d
cmp    $0x64,%al
je     1230 <main+0x60>
movsbl %al,%eax
cmp    $0x6f,%eax
jne    12cf <main+0xff>
mov    0x2d99(%rip),%rax
mov    (%rax),%rsi
mov    %r13,%rdi
mov    $0x10000,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x10010(%rsp)
mov    %ebp,%r15d
jmp    1230 <main+0x60>
mov    0x2d5d(%rip),%rbx
movslq (%rbx),%rax
cmp    %r14d,%eax
jge    12b4 <main+0xe4>
cmpb   $0x0,0x10(%rsp)
jne    135e <main+0x18e>
movslq %r14d,%rcx
nopl   0x0(%rax)
mov    (%r12,%rax,8),%rsi
test   %rsi,%rsi
jne    12f4 <main+0x124>
add    $0x1,%rax
cmp    %rax,%rcx
jne    12a0 <main+0xd0>
jmp    130b <main+0x13b>
mov    0x2d15(%rip),%rbx
mov    (%rbx),%edi
lea    0xd75(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    (%rbx),%edi
jmp    12d8 <main+0x108>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xd21(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebp
jmp    1483 <main+0x2b3>
lea    0x10(%rsp),%rdi
mov    $0x10000,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x10010(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %r13,%r13
je     133c <main+0x16c>
test   %rax,%rax
je     134f <main+0x17f>
cmp    %rax,%r13
ja     134f <main+0x17f>
lea    0xd18(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10d0 <strcat@plt>
jmp    135e <main+0x18e>
lea    0xd05(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcpy@plt>
movslq (%rbx),%rax
xor    %ebp,%ebp
cmp    %r14d,%eax
jge    1483 <main+0x2b3>
lea    (%r12,%rax,8),%rcx
mov    %rcx,0x8(%rsp)
sub    %eax,%r14d
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    13b9 <main+0x1e9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15d,%esi
call   1090 <build_file@plt>
test   %eax,%eax
mov    $0x0,%ecx
cmovs  %ecx,%eax
mov    $0x1,%ecx
cmovs  %ecx,%ebp
add    %eax,%r12d
add    $0x1,%r13
cmp    %r13d,%r14d
je     13ff <main+0x22f>
mov    0x8(%rsp),%rax
mov    (%rax,%r13,8),%rdx
test   %rdx,%rdx
je     13b0 <main+0x1e0>
test   %rbx,%rbx
jne    1390 <main+0x1c0>
lea    0x10(%rsp),%rdi
lea    0xc88(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1439 <main+0x269>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15d,%esi
call   1030 <output_header@plt>
test   %eax,%eax
jne    146d <main+0x29d>
mov    0x8(%rsp),%rax
mov    (%rax,%r13,8),%rdx
jmp    1390 <main+0x1c0>
test   %rbx,%rbx
je     1483 <main+0x2b3>
mov    $0x1,%r14d
test   %ebp,%ebp
jne    1478 <main+0x2a8>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   10f0 <fixup_record_count@plt>
test   %eax,%eax
je     1475 <main+0x2a5>
mov    0x2ba9(%rip),%rax
mov    (%rax),%edi
lea    0xc5a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1478 <main+0x2a8>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    0x2b82(%rip),%rcx
mov    (%rcx),%edi
lea    0xc0c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebp
jmp    1483 <main+0x2b3>
mov    $0x1,%r14d
jmp    1478 <main+0x2a8>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"do:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [53 x i8] c"Usage: %s [-o <output_filename>] [-d] <filename>...\0A\00"
@optind = global i32 0
@.str.2 = [34 x i8] c"Expected at least one input file\0A\00"
@.str.3 = [5 x i8] c".bin\00"
@.str.4 = [3 x i8] c"wb\00"
@errno = global i32 0
@.str.5 = [39 x i8] c"main: Error opening %s for output: %s\0A\00"
@.str.6 = [41 x i8] c"main: Error updating final record count\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65541 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%19 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 65541)
br label %21
21: ; preds = %42, %2
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @getopt(i32 %22, i8** %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %8
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %43
26: ; preds = %21
%27 = load i32, i32* %8
%28 = trunc i32 %27 to i8
%29 = sext i8 %28 to i32
switch i32 %29, label %36 [
i32 111, label %30
i32 100, label %35
]
30: ; preds = %26
%31 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%32 = load i8*, i8** @optarg
%33 = call i32 @strncpy(i8* %31, i8* %32, i32 65536)
%34 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 65536
store i8 0, i8* %34
br label %42
35: ; preds = %26
store i32 1, i32* %7
br label %42
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %40)
store i32 1, i32* %3
br label %186
42: ; preds = %35, %30
br label %21
43: ; preds = %21
%44 = load i32, i32* @optind
%45 = load i32, i32* %4
%46 = icmp sge i32 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %53)
store i32 1, i32* %3
br label %186
55: ; preds = %43
%56 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%57 = call i64 @strlen(i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %106
59: ; preds = %55
%60 = load i32, i32* @optind
store i32 %60, i32* %9
br label %61
61: ; preds = %82, %59
%62 = load i32, i32* %9
%63 = load i32, i32* %4
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %85
65: ; preds = %61
%66 = load i8**, i8*** %5
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %81
72: ; preds = %65
%73 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%74 = load i8**, i8*** %5
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 @strncpy(i8* %73, i8* %78, i32 65536)
%80 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 65536
store i8 0, i8* %80
br label %85
81: ; preds = %65
br label %82
82: ; preds = %81
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 1
store i32 %84, i32* %9
br label %61
85: ; preds = %72, %61
%86 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%87 = call i8* @strrchr(i8* %86, i8 signext 46)
store i8* %87, i8** %10
%88 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%89 = call i8* @strrchr(i8* %88, i8 signext 47)
store i8* %89, i8** %11
%90 = load i8*, i8** %10
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %102
92: ; preds = %85
%93 = load i8*, i8** %11
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = load i8*, i8** %10
%97 = load i8*, i8** %11
%98 = icmp ugt i8* %96, %97
br i1 %98, label %99, label %102
99: ; preds = %95, %92
%100 = load i8*, i8** %10
%101 = call i32 @strcpy(i8* %100, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %105
102: ; preds = %95, %85
%103 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%104 = call i32 @strcat(i8* %103, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %105
105: ; preds = %102, %99
br label %106
106: ; preds = %105, %55
store i32* null, i32** %12
store i32 0, i32* %13
store i32 0, i32* %14
%107 = load i32, i32* @optind
store i32 %107, i32* %9
br label %108
108: ; preds = %161, %106
%109 = load i32, i32* %9
%110 = load i32, i32* %4
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %164
112: ; preds = %108
%113 = load i8**, i8*** %5
%114 = load i32, i32* %9
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8*, i8** %113, i64 %115
%117 = load i8*, i8** %116
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %160
119: ; preds = %112
%120 = load i32*, i32** %12
%121 = icmp ne i32* %120, null
br i1 %121, label %143, label %122
122: ; preds = %119
%123 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%124 = call i32* @fopen(i8* %123, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %124, i32** %12
%125 = load i32*, i32** %12
%126 = icmp ne i32* %125, null
br i1 %126, label %135, label %127
127: ; preds = %122
%128 = load i32, i32* @errno
store i32 %128, i32* %16
%129 = load i32, i32* %16
%130 = call i8* @strerror(i32 %129)
store i8* %130, i8** %17
%131 = load i32, i32* @stderr
%132 = getelementptr inbounds [65541 x i8], [65541 x i8]* %6, i64 0, i64 0
%133 = load i8*, i8** %17
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %132, i8* %133)
store i32 1, i32* %3
br label %186
135: ; preds = %122
%136 = load i32*, i32** %12
%137 = load i32, i32* %7
%138 = call i32 @output_header(i32* %136, i32 %137)
store i32 %138, i32* %15
%139 = load i32, i32* %15
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %135
store i32 1, i32* %14
br label %164
142: ; preds = %135
br label %143
143: ; preds = %142, %119
%144 = load i32*, i32** %12
%145 = load i32, i32* %7
%146 = load i8**, i8*** %5
%147 = load i32, i32* %9
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i8*, i8** %146, i64 %148
%150 = load i8*, i8** %149
%151 = call i32 @build_file(i32* %144, i32 %145, i8* %150)
store i32 %151, i32* %18
%152 = load i32, i32* %18
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %155
154: ; preds = %143
store i32 1, i32* %14
br label %159
155: ; preds = %143
%156 = load i32, i32* %18
%157 = load i32, i32* %13
%158 = add nsw i32 %157, %156
store i32 %158, i32* %13
br label %159
159: ; preds = %155, %154
br label %160
160: ; preds = %159, %112
br label %161
161: ; preds = %160
%162 = load i32, i32* %9
%163 = add nsw i32 %162, 1
store i32 %163, i32* %9
br label %108
164: ; preds = %141, %108
%165 = load i32*, i32** %12
%166 = icmp ne i32* %165, null
br i1 %166, label %167, label %184
167: ; preds = %164
%168 = load i32, i32* %14
%169 = icmp eq i32 %168, 0
br i1 %169, label %170, label %181
170: ; preds = %167
%171 = load i32*, i32** %12
%172 = load i32, i32* %7
%173 = load i32, i32* %13
%174 = call i32 @fixup_record_count(i32* %171, i32 %172, i32 %173)
store i32 %174, i32* %15
%175 = load i32, i32* %15
%176 = icmp ne i32 %175, 0
br i1 %176, label %177, label %180
177: ; preds = %170
%178 = load i32, i32* @stderr
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %178, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %14
br label %180
180: ; preds = %177, %170
br label %181
181: ; preds = %180, %167
%182 = load i32*, i32** %12
%183 = call i32 @fclose(i32* %182)
br label %184
184: ; preds = %181, %164
%185 = load i32, i32* %14
store i32 %185, i32* %3
br label %186
186: ; preds = %184, %127, %47, %36
%187 = load i32, i32* %3
ret i32 %187
}

LLVM IR (-O2):
@.str = [4 x i8] c"do:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [53 x i8] c"Usage: %s [-o <output_filename>] [-d] <filename>...\0A\00"
@optind = global i32 0
@.str.2 = [34 x i8] c"Expected at least one input file\0A\00"
@.str.3 = [5 x i8] c".bin\00"
@.str.4 = [3 x i8] c"wb\00"
@errno = global i32 0
@.str.5 = [39 x i8] c"main: Error opening %s for output: %s\0A\00"
@.str.6 = [41 x i8] c"main: Error updating final record count\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [65541 x i8]
%4 = getelementptr inbounds [65541 x i8], [65541 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 65541)
%6 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, -1
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = getelementptr inbounds [65541 x i8], [65541 x i8]* %3, i64 0, i64 65536
br label %10
10: ; preds = %8, %22
%11 = phi i32 [ %6, %8 ], [ %24, %22 ]
%12 = phi i32 [ 0, %8 ], [ %23, %22 ]
%13 = shl i32 %11, 24
%14 = ashr exact i32 %13, 24
switch i32 %14, label %18 [
i32 111, label %15
i32 100, label %22
]
15: ; preds = %10
%16 = load i8*, i8** @optarg
%17 = call i32 @strncpy(i8* %4, i8* %16, i32 65536)
store i8 0, i8* %9
br label %22
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %122
22: ; preds = %10, %15
%23 = phi i32 [ %12, %15 ], [ 1, %10 ]
%24 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %10
26: ; preds = %22, %2
%27 = phi i32 [ 0, %2 ], [ %23, %22 ]
%28 = load i32, i32* @optind
%29 = icmp slt i32 %28, %0
br i1 %29, label %36, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %1
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %122
36: ; preds = %26
%37 = load i8, i8* %4
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %65
39: ; preds = %36
%40 = sext i32 %28 to i64
%41 = sext i32 %0 to i64
br label %44
42: ; preds = %44
%43 = icmp eq i64 %49, %41
br i1 %43, label %53, label %44
44: ; preds = %39, %42
%45 = phi i64 [ %40, %39 ], [ %49, %42 ]
%46 = getelementptr inbounds i8*, i8** %1, i64 %45
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
%49 = add nsw i64 %45, 1
br i1 %48, label %42, label %50
50: ; preds = %44
%51 = call i32 @strncpy(i8* %4, i8* %47, i32 65536)
%52 = getelementptr inbounds [65541 x i8], [65541 x i8]* %3, i64 0, i64 65536
store i8 0, i8* %52
br label %53
53: ; preds = %42, %50
%54 = call i8* @strrchr(i8* %4, i8 signext 46)
%55 = call i8* @strrchr(i8* %4, i8 signext 47)
%56 = icmp eq i8* %54, null
br i1 %56, label %63, label %57
57: ; preds = %53
%58 = icmp eq i8* %55, null
%59 = icmp ugt i8* %54, %55
%60 = select i1 %58, i1 true, i1 %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @strcpy(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %65
63: ; preds = %57, %53
%64 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %61, %63, %36
%66 = load i32, i32* @optind
%67 = icmp slt i32 %66, %0
br i1 %67, label %68, label %122
68: ; preds = %65
%69 = sext i32 %66 to i64
br label %70
70: ; preds = %68, %101
%71 = phi i64 [ %69, %68 ], [ %105, %101 ]
%72 = phi i32 [ 0, %68 ], [ %104, %101 ]
%73 = phi i32 [ 0, %68 ], [ %103, %101 ]
%74 = phi i32* [ null, %68 ], [ %102, %101 ]
%75 = getelementptr inbounds i8*, i8** %1, i64 %71
%76 = load i8*, i8** %75
%77 = icmp eq i8* %76, null
br i1 %77, label %101, label %78
78: ; preds = %70
%79 = icmp eq i32* %74, null
br i1 %79, label %80, label %93
80: ; preds = %78
%81 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%82 = icmp eq i32* %81, null
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %4, i8* %85)
br label %122
88: ; preds = %80
%89 = call i32 @output_header(i32* %81, i32 %27)
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %118
91: ; preds = %88
%92 = load i8*, i8** %75
br label %93
93: ; preds = %91, %78
%94 = phi i8* [ %76, %78 ], [ %92, %91 ]
%95 = phi i32* [ %74, %78 ], [ %81, %91 ]
%96 = call i32 @build_file(i32* %95, i32 %27, i8* %94)
%97 = icmp slt i32 %96, 0
%98 = select i1 %97, i32 0, i32 %96
%99 = add nsw i32 %98, %73
%100 = select i1 %97, i32 1, i32 %72
br label %101
101: ; preds = %70, %93
%102 = phi i32* [ %95, %93 ], [ %74, %70 ]
%103 = phi i32 [ %99, %93 ], [ %73, %70 ]
%104 = phi i32 [ %100, %93 ], [ %72, %70 ]
%105 = add nsw i64 %71, 1
%106 = trunc i64 %105 to i32
%107 = icmp eq i32 %106, %0
br i1 %107, label %108, label %70
108: ; preds = %101
%109 = icmp eq i32* %102, null
br i1 %109, label %122, label %110
110: ; preds = %108
%111 = icmp eq i32 %104, 0
br i1 %111, label %112, label %118
112: ; preds = %110
%113 = call i32 @fixup_record_count(i32* %102, i32 %27, i32 %103)
%114 = icmp eq i32 %113, 0
br i1 %114, label %118, label %115
115: ; preds = %112
%116 = load i32, i32* @stderr
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
br label %118
118: ; preds = %88, %112, %115, %110
%119 = phi i32* [ %102, %115 ], [ %102, %112 ], [ %102, %110 ], [ %81, %88 ]
%120 = phi i32 [ 1, %115 ], [ 0, %112 ], [ 1, %110 ], [ 1, %88 ]
%121 = call i32 @fclose(i32* %119)
br label %122
122: ; preds = %65, %83, %118, %108, %30, %18
%123 = phi i32 [ 1, %18 ], [ 1, %30 ], [ 1, %83 ], [ %120, %118 ], [ %104, %108 ], [ 0, %65 ]
ret i32 %123
}