#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ process_msgs(char *, int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int i;
  int num_read;
  int num_left;
  char *input_filename = NULL;
  char *output_filename = NULL;
  struct stat stbuf;
  char *buf;
  char *p;
  FILE *in_file;
  FILE *out_file;
  for (i = 1; i < argc; i++) {
    if (argv[i][0] != '-')
      usage();
    if (argv[i][1] == 'i') {
      if (argv[i][2] != '\0')
        input_filename = &argv[i][2];
      else
        input_filename = argv[++i];
    } else if (argv[i][1] == 'o') {
      if (argv[i][2] != '\0')
        output_filename = &argv[i][2];
      else
        output_filename = argv[++i];
    }
  }
  if (input_filename == NULL || output_filename == NULL)
    usage();
  if (stat(input_filename, &stbuf) != 0) {
    fprintf(stderr, "mkmsghdr: Unable to stat %s: %s\n", input_filename,
            strerror(errno));
    exit(1);
  }
  if ((buf = (char *)malloc(stbuf.st_size + 1)) == NULL) {
    fprintf(stderr, "mkmsghdr: Unable to allocate %d bytes\n", stbuf.st_size);
    exit(1);
  }
  if ((in_file = fopen(input_filename, "r")) == NULL) {
    fprintf(stderr, "mkmsghdr: Unable to open %s for reading: %s\n",
            input_filename, strerror(errno));
    exit(1);
  }
  p = buf;
  num_left = stbuf.st_size;
  while (num_left > 0) {
    num_read = fread(buf, 1, num_left, in_file);
    if (num_read == 0)
      break;
    p += num_read;
    num_left -= num_read;
  }
  fclose(in_file);
  buf[stbuf.st_size] = '\0';
  if ((out_file = fopen(output_filename, "wb")) == NULL) {
    fprintf(stderr, "mkmsghdr: Unable to open %s for writing: %s\n",
            output_filename, strerror(errno));
    exit(1);
  }
  process_msgs(buf, out_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e3 <main+0x143>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11fb <main+0x5b>
mov    $0x0,%al
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x69,%eax
jne    1263 <main+0xc3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     1246 <main+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    125e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
jmp    12d0 <main+0x130>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6f,%eax
jne    12cb <main+0x12b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     12ae <main+0x10e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    12c6 <main+0x126>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    12cb <main+0x12b>
jmp    12d0 <main+0x130>
jmp    12d5 <main+0x135>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <main+0x30>
cmpq   $0x0,-0x28(%rbp)
je     12f9 <main+0x159>
cmpq   $0x0,-0x30(%rbp)
jne    1300 <main+0x160>
mov    $0x0,%al
call   1090 <usage@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     135b <main+0x1bb>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xcb6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1398 <main+0x1f8>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
lea    0xc9a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xca5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    13fa <main+0x25a>
mov    0x2c23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    145a <main+0x2ba>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1439 <main+0x299>
jmp    145a <main+0x2ba>
mov    -0x18(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1408 <main+0x268>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rax
movslq -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
lea    0xbfd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    14d7 <main+0x337>
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2b2d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xbb4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1040 <process_msgs@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1229 <main+0x89>
mov    %rsi,%r13
mov    %edi,%r12d
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    11d8 <main+0x38>
lea    0x1(%rbx),%ebp
mov    0x8(%r13,%rbx,8),%r14
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r12d,%ebp
jge    1231 <main+0x91>
movslq %ebp,%rbx
mov    0x0(%r13,%rbx,8),%rax
cmpb   $0x2d,(%rax)
je     11f1 <main+0x51>
xor    %eax,%eax
call   1090 <usage@plt>
mov    0x0(%r13,%rbx,8),%rax
movzbl 0x1(%rax),%ecx
cmp    $0x6f,%cl
je     1210 <main+0x70>
cmp    $0x69,%cl
jne    11d0 <main+0x30>
cmpb   $0x0,0x2(%rax)
je     121f <main+0x7f>
add    $0x2,%rax
mov    %rax,%r15
jmp    11d0 <main+0x30>
xchg   %ax,%ax
cmpb   $0x0,0x2(%rax)
je     11c3 <main+0x23>
add    $0x2,%rax
mov    %rax,%r14
jmp    11d0 <main+0x30>
lea    0x1(%rbx),%ebp
mov    0x8(%r13,%rbx,8),%r15
jmp    11d0 <main+0x30>
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    123b <main+0x9b>
test   %r15,%r15
je     123b <main+0x9b>
test   %r14,%r14
jne    1242 <main+0xa2>
xor    %eax,%eax
call   1090 <usage@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1070 <stat@plt>
test   %rax,%rax
jne    12f1 <main+0x151>
mov    (%rsp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1311 <main+0x171>
mov    %rax,%r12
lea    0xdd4(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1335 <main+0x195>
mov    %rax,%rbp
mov    (%rsp),%ebx
test   %ebx,%ebx
jle    12ac <main+0x10c>
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     12ac <main+0x10c>
sub    %eax,%ebx
test   %ebx,%ebx
jg     1290 <main+0xf0>
mov    %rbp,%rdi
call   1050 <fclose@plt>
movslq (%rsp),%rax
movb   $0x0,(%r12,%rax,1)
lea    0xdb3(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     135a <main+0x1ba>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <process_msgs@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcf1(%rip),%rsi
jmp    1353 <main+0x1b3>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%edx
lea    0xcfd(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%ebx
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcf7(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
jmp    137d <main+0x1dd>
mov    0x2c7f(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd02(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"mkmsghdr: Unable to stat %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [39 x i8] c"mkmsghdr: Unable to allocate %d bytes\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [45 x i8] c"mkmsghdr: Unable to open %s for reading: %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [45 x i8] c"mkmsghdr: Unable to open %s for writing: %s\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 %struct.stat
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
store i8* null, i8** %10
store i32 1, i32* %6
br label %16
16: ; preds = %104, %2
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %107
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 45
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 (...) @usage()
br label %32
32: ; preds = %30, %20
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 105
br i1 %41, label %42, label %67
42: ; preds = %32
%43 = load i8**, i8*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 2
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %42
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = getelementptr inbounds i8, i8* %57, i64 2
store i8* %58, i8** %9
br label %66
59: ; preds = %42
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %60, i64 %63
%65 = load i8*, i8** %64
store i8* %65, i8** %9
br label %66
66: ; preds = %59, %52
br label %103
67: ; preds = %32
%68 = load i8**, i8*** %5
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 111
br i1 %76, label %77, label %102
77: ; preds = %67
%78 = load i8**, i8*** %5
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %78, i64 %80
%82 = load i8*, i8** %81
%83 = getelementptr inbounds i8, i8* %82, i64 2
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %77
%88 = load i8**, i8*** %5
%89 = load i32, i32* %6
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8*, i8** %88, i64 %90
%92 = load i8*, i8** %91
%93 = getelementptr inbounds i8, i8* %92, i64 2
store i8* %93, i8** %10
br label %101
94: ; preds = %77
%95 = load i8**, i8*** %5
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
store i32 %97, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %95, i64 %98
%100 = load i8*, i8** %99
store i8* %100, i8** %10
br label %101
101: ; preds = %94, %87
br label %102
102: ; preds = %101, %67
br label %103
103: ; preds = %102, %66
br label %104
104: ; preds = %103
%105 = load i32, i32* %6
%106 = add nsw i32 %105, 1
store i32 %106, i32* %6
br label %16
107: ; preds = %16
%108 = load i8*, i8** %9
%109 = icmp eq i8* %108, null
br i1 %109, label %113, label %110
110: ; preds = %107
%111 = load i8*, i8** %10
%112 = icmp eq i8* %111, null
br i1 %112, label %113, label %115
113: ; preds = %110, %107
%114 = call i32 (...) @usage()
br label %115
115: ; preds = %113, %110
%116 = load i8*, i8** %9
%117 = call i64 @stat(i8* %116, %struct.stat* %11)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %126
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = load i8*, i8** %9
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %121, i8* %123)
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %115
%127 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%128 = load i32, i32* %127
%129 = add nsw i32 %128, 1
%130 = call i64 @malloc(i32 %129)
%131 = inttoptr i64 %130 to i8*
store i8* %131, i8** %12
%132 = icmp eq i8* %131, null
br i1 %132, label %133, label %139
133: ; preds = %126
%134 = load i32, i32* @stderr
%135 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%136 = load i32, i32* %135
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %136)
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %126
%140 = load i8*, i8** %9
%141 = call i32* @fopen(i8* %140, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %141, i32** %14
%142 = icmp eq i32* %141, null
br i1 %142, label %143, label %150
143: ; preds = %139
%144 = load i32, i32* @stderr
%145 = load i8*, i8** %9
%146 = load i32, i32* @errno
%147 = call i8* @strerror(i32 %146)
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %145, i8* %147)
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %139
%151 = load i8*, i8** %12
store i8* %151, i8** %13
%152 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%153 = load i32, i32* %152
store i32 %153, i32* %8
br label %154
154: ; preds = %165, %150
%155 = load i32, i32* %8
%156 = icmp sgt i32 %155, 0
br i1 %156, label %157, label %173
157: ; preds = %154
%158 = load i8*, i8** %12
%159 = load i32, i32* %8
%160 = load i32*, i32** %14
%161 = call i32 @fread(i8* %158, i32 1, i32 %159, i32* %160)
store i32 %161, i32* %7
%162 = load i32, i32* %7
%163 = icmp eq i32 %162, 0
br i1 %163, label %164, label %165
164: ; preds = %157
br label %173
165: ; preds = %157
%166 = load i32, i32* %7
%167 = load i8*, i8** %13
%168 = sext i32 %166 to i64
%169 = getelementptr inbounds i8, i8* %167, i64 %168
store i8* %169, i8** %13
%170 = load i32, i32* %7
%171 = load i32, i32* %8
%172 = sub nsw i32 %171, %170
store i32 %172, i32* %8
br label %154
173: ; preds = %164, %154
%174 = load i32*, i32** %14
%175 = call i32 @fclose(i32* %174)
%176 = load i8*, i8** %12
%177 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%178 = load i32, i32* %177
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i8, i8* %176, i64 %179
store i8 0, i8* %180
%181 = load i8*, i8** %10
%182 = call i32* @fopen(i8* %181, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %182, i32** %15
%183 = icmp eq i32* %182, null
br i1 %183, label %184, label %191
184: ; preds = %173
%185 = load i32, i32* @stderr
%186 = load i8*, i8** %10
%187 = load i32, i32* @errno
%188 = call i8* @strerror(i32 %187)
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %185, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %186, i8* %188)
%190 = call i32 @exit(i32 1)
unreachable
191: ; preds = %173
%192 = load i8*, i8** %12
%193 = load i32*, i32** %15
%194 = call i32 @process_msgs(i8* %192, i32* %193)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"mkmsghdr: Unable to stat %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [39 x i8] c"mkmsghdr: Unable to allocate %d bytes\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [45 x i8] c"mkmsghdr: Unable to open %s for reading: %s\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [45 x i8] c"mkmsghdr: Unable to open %s for writing: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %50
6: ; preds = %2, %40
%7 = phi i32 [ %44, %40 ], [ 1, %2 ]
%8 = phi i8* [ %42, %40 ], [ null, %2 ]
%9 = phi i8* [ %41, %40 ], [ null, %2 ]
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 45
br i1 %14, label %18, label %15
15: ; preds = %6
%16 = tail call i32 (...) @usage()
%17 = load i8*, i8** %11
br label %18
18: ; preds = %15, %6
%19 = phi i8* [ %17, %15 ], [ %12, %6 ]
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
switch i8 %21, label %40 [
i8 105, label %22
i8 111, label %31
]
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %19, i64 2
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = add nsw i32 %7, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
br label %40
31: ; preds = %18
%32 = getelementptr inbounds i8, i8* %19, i64 2
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = add nsw i32 %7, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
br label %40
40: ; preds = %31, %18, %22, %26, %35
%41 = phi i8* [ %9, %26 ], [ %39, %35 ], [ %9, %22 ], [ %9, %18 ], [ %32, %31 ]
%42 = phi i8* [ %30, %26 ], [ %8, %35 ], [ %23, %22 ], [ %8, %18 ], [ %8, %31 ]
%43 = phi i32 [ %27, %26 ], [ %36, %35 ], [ %7, %22 ], [ %7, %18 ], [ %7, %31 ]
%44 = add nsw i32 %43, 1
%45 = icmp slt i32 %44, %0
br i1 %45, label %6, label %46
46: ; preds = %40
%47 = icmp eq i8* %42, null
%48 = icmp eq i8* %41, null
%49 = select i1 %47, i1 true, i1 %48
br i1 %49, label %50, label %54
50: ; preds = %2, %46
%51 = phi i8* [ %42, %46 ], [ null, %2 ]
%52 = phi i8* [ %41, %46 ], [ null, %2 ]
%53 = tail call i32 (...) @usage()
br label %54
54: ; preds = %46, %50
%55 = phi i8* [ %42, %46 ], [ %51, %50 ]
%56 = phi i8* [ %41, %46 ], [ %52, %50 ]
%57 = call i64 @stat(i8* %55, %struct.stat* %3)
%58 = icmp eq i64 %57, 0
br i1 %58, label %65, label %59
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %55, i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %54
%66 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%67 = load i32, i32* %66
%68 = add nsw i32 %67, 1
%69 = call i64 @malloc(i32 %68)
%70 = inttoptr i64 %69 to i8*
%71 = icmp eq i64 %69, 0
br i1 %71, label %72, label %77
72: ; preds = %65
%73 = load i32, i32* @stderr
%74 = load i32, i32* %66
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %65
%78 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%79 = icmp eq i32* %78, null
br i1 %79, label %80, label %86
80: ; preds = %77
%81 = load i32, i32* @stderr
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %55, i8* %83)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %77
%87 = load i32, i32* %66
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %96
89: ; preds = %86, %89
%90 = phi i32 [ %93, %89 ], [ %87, %86 ]
%91 = call i32 @fread(i8* %70, i32 1, i32 %90, i32* %78)
%92 = icmp ne i32 %91, 0
%93 = sub nsw i32 %90, %91
%94 = icmp sgt i32 %93, 0
%95 = select i1 %92, i1 %94, i1 false
br i1 %95, label %89, label %96
96: ; preds = %89, %86
%97 = call i32 @fclose(i32* %78)
%98 = load i32, i32* %66
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %70, i64 %99
store i8 0, i8* %100
%101 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %109
103: ; preds = %96
%104 = load i32, i32* @stderr
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %106)
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %96
%110 = call i32 @process_msgs(i8* %70, i32* %101)
ret i32 0
}