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

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char **argv) {
  FILE *f;
  struct stat s;
  unsigned char *buf, *ptr;
  const char *output;
  long i, j;
  if (argc != 2 && argc != 3) {
    printf("Usage: mk_header <input> [output]\n"
           "Default output file is \"output.h\"\n");
    return 1;
  }
  if (stat(argv[1], &s) == -1 || !S_ISREG(s.st_mode)) {
    printf("Couldn't stat %s\n", argv[1]);
    return 1;
  }
  if (s.st_size == 0) {
    printf("%s is an empty file\n", argv[1]);
    return 1;
  }
  buf = (unsigned char *)malloc(s.st_size);
  if (buf == NULL) {
    printf("Couldn't malloc %ld bytes\n", (long)s.st_size);
    return 1;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    free(buf);
    printf("Couldn't open %s\n", argv[1]);
    return 1;
  }
  if (fread(buf, 1, s.st_size, f) != (size_t)s.st_size) {
    fclose(f);
    free(buf);
    printf("Error reading %s\n", argv[1]);
    return 1;
  }
  fclose(f);
  output = (argc == 3) ? argv[2] : "output.h";
  f = fopen(output, "wb");
  if (!f) {
    free(buf);
    printf("Couldn't open %s\n", output);
    return 1;
  }
  for (i = 0, j = 0, ptr = buf; i < s.st_size; ++i) {
    fprintf(f, "0x%02x", *ptr++);
    if (i == s.st_size - 1)
      break;
    fprintf(f, ",");
    if (++j < 16)
      fprintf(f, " ");
    else {
      j = 0;
      fprintf(f, "\n");
    }
  }
  fprintf(f, "\n");
  fclose(f);
  free(buf);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11d4 <main+0x44>
cmpl   $0x3,-0x8(%rbp)
je     11d4 <main+0x44>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     11ff <main+0x6f>
mov    -0x20(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1221 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
cmpq   $0x0,-0x28(%rbp)
jne    124e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
mov    -0x28(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1284 <main+0xf4>
mov    -0x28(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d2 <main+0x142>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x28(%rbp),%rax
je     1326 <main+0x196>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x3,-0x8(%rbp)
jne    134a <main+0x1ba>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    135a <main+0x1ca>
lea    0xd5d(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    135a <main+0x1ca>
mov    -0x58(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    13a8 <main+0x218>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rsi
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a6 <main+0x316>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    147b <main+0x2eb>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movzbl (%rax),%edx
lea    0xccf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    140c <main+0x27c>
jmp    147b <main+0x2eb>
mov    -0x18(%rbp),%rdi
lea    0xcaa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
cmp    $0x10,%rax
jge    144b <main+0x2bb>
mov    -0x18(%rbp),%rdi
lea    0xc84(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1465 <main+0x2d5>
movq   $0x0,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    146a <main+0x2da>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    13c0 <main+0x230>
mov    -0x18(%rbp),%rdi
lea    0xbbd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1275 <main+0xc5>
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     1283 <main+0xd3>
mov    0x10(%rsp),%edi
call   10b0 <S_ISREG@plt>
test   %eax,%eax
je     1283 <main+0xd3>
mov    0x8(%rsp),%r15
test   %r15,%r15
je     12ac <main+0xfc>
mov    %r15,%rdi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12ba <main+0x10a>
mov    %rax,%r14
mov    0x8(%r12),%rdi
lea    0xe1b(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12c6 <main+0x116>
mov    %rax,%r13
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rax,(%rsp)
mov    %r13,%rdi
call   1060 <fclose@plt>
cmp    %r15,(%rsp)
jne    12dc <main+0x12c>
cmp    $0x3,%ebx
jne    12f5 <main+0x145>
mov    0x10(%r12),%r12
jmp    12fc <main+0x14c>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
jmp    1296 <main+0xe6>
mov    0x8(%r12),%rsi
lea    0xd71(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r12),%rsi
lea    0xd5a(%rip),%rdi
jmp    128f <main+0xdf>
lea    0xd66(%rip),%rdi
mov    %r15,%rsi
jmp    128f <main+0xdf>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%r12),%rsi
lea    0xd6b(%rip),%rdi
jmp    128f <main+0xdf>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%r12),%rsi
lea    0xd67(%rip),%rdi
jmp    13ca <main+0x21a>
lea    0xd6d(%rip),%r12
lea    0xd6f(%rip),%rsi
mov    %r12,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13b8 <main+0x208>
mov    %rax,%rbx
test   %r15,%r15
jle    1394 <main+0x1e4>
movzbl (%r14),%edx
lea    0xd4e(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <fprintf@plt>
cmp    $0x1,%r15
je     1394 <main+0x1e4>
mov    $0x1,%ebp
xor    %r13d,%r13d
mov    $0x2c,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
lea    0x1(%r13),%r12
cmp    $0xf,%r13
mov    $0xa,%edi
mov    $0x20,%eax
cmovl  %eax,%edi
mov    $0x0,%eax
cmovge %rax,%r12
mov    %rbx,%rsi
call   1080 <fputc@plt>
movzbl (%r14,%rbp,1),%edx
mov    %rbx,%rdi
lea    0xcf4(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%rbp
mov    %r12,%r13
cmp    %rbp,%r15
jne    133f <main+0x18f>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    129b <main+0xeb>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xc7e(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    129b <main+0xeb>

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@.str = [69 x i8] c"Usage: mk_header <input> [output]\0ADefault output file is \22output.h\22\0A\00"
@.str.1 = [18 x i8] c"Couldn't stat %s\0A\00"
@.str.2 = [21 x i8] c"%s is an empty file\0A\00"
@.str.3 = [27 x i8] c"Couldn't malloc %ld bytes\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.6 = [18 x i8] c"Error reading %s\0A\00"
@.str.7 = [9 x i8] c"output.h\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [7 x i8] c"0x%02x\00"
@.str.10 = [2 x i8] c",\00"
@.str.11 = [2 x i8] c" \00"
@.str.12 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %152
20: ; preds = %15, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @stat(i8* %23, %struct.stat* %7)
%25 = icmp eq i32 %24, -1
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%28 = load i32, i32* %27
%29 = call i32 @S_ISREG(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %26, %20
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %152
36: ; preds = %26
%37 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %152
45: ; preds = %36
%46 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i64 @malloc(i64 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %8
%50 = load i8*, i8** %8
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%54 = load i64, i64* %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 %54)
store i32 1, i32* %3
br label %152
56: ; preds = %45
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %60, i32** %6
%61 = load i32*, i32** %6
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %70
63: ; preds = %56
%64 = load i8*, i8** %8
%65 = call i32 @free(i8* %64)
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %68)
store i32 1, i32* %3
br label %152
70: ; preds = %56
%71 = load i8*, i8** %8
%72 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%73 = load i64, i64* %72
%74 = load i32*, i32** %6
%75 = call i64 @fread(i8* %71, i32 1, i64 %73, i32* %74)
%76 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%77 = load i64, i64* %76
%78 = icmp ne i64 %75, %77
br i1 %78, label %79, label %88
79: ; preds = %70
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
%82 = load i8*, i8** %8
%83 = call i32 @free(i8* %82)
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %86)
store i32 1, i32* %3
br label %152
88: ; preds = %70
%89 = load i32*, i32** %6
%90 = call i32 @fclose(i32* %89)
%91 = load i32, i32* %4
%92 = icmp eq i32 %91, 3
br i1 %92, label %93, label %97
93: ; preds = %88
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 2
%96 = load i8*, i8** %95
br label %98
97: ; preds = %88
br label %98
98: ; preds = %97, %93
%99 = phi i8* [ %96, %93 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %97 ]
store i8* %99, i8** %10
%100 = load i8*, i8** %10
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %101, i32** %6
%102 = load i32*, i32** %6
%103 = icmp ne i32* %102, null
br i1 %103, label %109, label %104
104: ; preds = %98
%105 = load i8*, i8** %8
%106 = call i32 @free(i8* %105)
%107 = load i8*, i8** %10
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %107)
store i32 1, i32* %3
br label %152
109: ; preds = %98
store i64 0, i64* %11
store i64 0, i64* %12
%110 = load i8*, i8** %8
store i8* %110, i8** %9
br label %111
111: ; preds = %142, %109
%112 = load i64, i64* %11
%113 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%114 = load i64, i64* %113
%115 = icmp slt i64 %112, %114
br i1 %115, label %116, label %145
116: ; preds = %111
%117 = load i32*, i32** %6
%118 = load i8*, i8** %9
%119 = getelementptr inbounds i8, i8* %118, i32 1
store i8* %119, i8** %9
%120 = load i8, i8* %118
%121 = zext i8 %120 to i32
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %121)
%123 = load i64, i64* %11
%124 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%125 = load i64, i64* %124
%126 = sub nsw i64 %125, 1
%127 = icmp eq i64 %123, %126
br i1 %127, label %128, label %129
128: ; preds = %116
br label %145
129: ; preds = %116
%130 = load i32*, i32** %6
%131 = call i32 (i32*, i8*, ...) @fprintf(i32* %130, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%132 = load i64, i64* %12
%133 = add nsw i64 %132, 1
store i64 %133, i64* %12
%134 = icmp slt i64 %133, 16
br i1 %134, label %135, label %138
135: ; preds = %129
%136 = load i32*, i32** %6
%137 = call i32 (i32*, i8*, ...) @fprintf(i32* %136, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %141
138: ; preds = %129
store i64 0, i64* %12
%139 = load i32*, i32** %6
%140 = call i32 (i32*, i8*, ...) @fprintf(i32* %139, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
br label %141
141: ; preds = %138, %135
br label %142
142: ; preds = %141
%143 = load i64, i64* %11
%144 = add nsw i64 %143, 1
store i64 %144, i64* %11
br label %111
145: ; preds = %128, %111
%146 = load i32*, i32** %6
%147 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%148 = load i32*, i32** %6
%149 = call i32 @fclose(i32* %148)
%150 = load i8*, i8** %8
%151 = call i32 @free(i8* %150)
store i32 0, i32* %3
br label %152
152: ; preds = %145, %104, %79, %63, %52, %40, %31, %18
%153 = load i32, i32* %3
ret i32 %153
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@.str.1 = [18 x i8] c"Couldn't stat %s\0A\00"
@.str.2 = [21 x i8] c"%s is an empty file\0A\00"
@.str.3 = [27 x i8] c"Couldn't malloc %ld bytes\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [18 x i8] c"Couldn't open %s\0A\00"
@.str.6 = [18 x i8] c"Error reading %s\0A\00"
@.str.7 = [9 x i8] c"output.h\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [7 x i8] c"0x%02x\00"
@str = [68 x i8] c"Usage: mk_header <input> [output]\0ADefault output file is \22output.h\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
br label %91
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @stat(i8* %11, %struct.stat* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = tail call i32 @S_ISREG(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14, %9
%20 = load i8*, i8** %10
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %91
22: ; preds = %14
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %91
29: ; preds = %22
%30 = tail call i64 @malloc(i64 %24)
%31 = inttoptr i64 %30 to i8*
%32 = icmp eq i64 %30, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i64 %24)
br label %91
35: ; preds = %29
%36 = load i8*, i8** %10
%37 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = tail call i32 @free(i8* %31)
%41 = load i8*, i8** %10
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %91
43: ; preds = %35
%44 = tail call i64 @fread(i8* %31, i32 1, i64 %24, i32* %37)
%45 = icmp eq i64 %44, %24
%46 = tail call i32 @fclose(i32* %37)
br i1 %45, label %51, label %47
47: ; preds = %43
%48 = tail call i32 @free(i8* %31)
%49 = load i8*, i8** %10
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %49)
br label %91
51: ; preds = %43
%52 = icmp eq i32 %0, 3
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = getelementptr inbounds i8*, i8** %1, i64 2
%55 = load i8*, i8** %54
br label %56
56: ; preds = %51, %53
%57 = phi i8* [ %55, %53 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %51 ]
%58 = tail call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%59 = icmp eq i32* %58, null
br i1 %59, label %68, label %60
60: ; preds = %56
%61 = icmp sgt i64 %24, 0
br i1 %61, label %62, label %87
62: ; preds = %60
%63 = add nsw i64 %24, -1
%64 = load i8, i8* %31
%65 = zext i8 %64 to i32
%66 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %65)
%67 = icmp eq i64 %63, 0
br i1 %67, label %87, label %71
68: ; preds = %56
%69 = tail call i32 @free(i8* %31)
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %91
71: ; preds = %62, %71
%72 = phi i8* [ %75, %71 ], [ %31, %62 ]
%73 = phi i64 [ %82, %71 ], [ 0, %62 ]
%74 = phi i64 [ %80, %71 ], [ 0, %62 ]
%75 = getelementptr inbounds i8, i8* %72, i64 1
%76 = tail call i32 @fputc(i32 44, i32* %58)
%77 = icmp slt i64 %74, 15
%78 = add nsw i64 %74, 1
%79 = select i1 %77, i32 32, i32 10
%80 = select i1 %77, i64 %78, i64 0
%81 = tail call i32 @fputc(i32 %79, i32* %58)
%82 = add nuw nsw i64 %73, 1
%83 = load i8, i8* %75
%84 = zext i8 %83 to i32
%85 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %84)
%86 = icmp eq i64 %82, %63
br i1 %86, label %87, label %71
87: ; preds = %71, %62, %60
%88 = tail call i32 @fputc(i32 10, i32* %58)
%89 = tail call i32 @fclose(i32* %58)
%90 = tail call i32 @free(i8* %31)
br label %91
91: ; preds = %87, %68, %47, %39, %33, %26, %19, %7
%92 = phi i32 [ 1, %7 ], [ 1, %19 ], [ 1, %26 ], [ 1, %33 ], [ 1, %39 ], [ 1, %47 ], [ 0, %87 ], [ 1, %68 ]
ret i32 %92
}