#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *stderr;
int main(int argc, char **argv) {
  FILE *in, *out;
  int col;
  int c;
  if (argc < 4) {
    fprintf(stderr,
            "Usage: bin2c <input bin file> <output h file> <array name>\n");
    return 1;
  }
  if ((in = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Cannot open input file (%s).\n", argv[1]);
    return 1;
  }
  if ((out = fopen(argv[2], "wt")) == NULL) {
    fprintf(stderr, "Cannot open output file (%s).\n", argv[2]);
    return 1;
  }
  col = 0;
  fprintf(out, "/* File generated by bin2c. Do not edit this [%s] file. */\n",
          argv[2]);
  fprintf(out, "/* Instead, update the [%s] file and run bin2c again. */\n\n",
          argv[1]);
  fprintf(out, "unsigned char %s[] = {\n  ", argv[3]);
  while ((c = fgetc(in)) != EOF) {
    if (col) {
      fprintf(out, ", ");
    }
    if (col >= 8) {
      fprintf(out, "\n  ");
      col = 0;
    }
    fprintf(out, "0x%02X", c);
    col++;
  }
  fprintf(out, "\n};\n");
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1184 <main+0x44>
mov    0x2e71(%rip),%rax
mov    (%rax),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1dd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d2 <main+0x92>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1dd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1220 <main+0xe0>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131d <main+0x1dd>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d60(%rip),%rcx
cmp    (%rcx),%eax
je     12f2 <main+0x1b2>
cmpl   $0x0,-0x24(%rbp)
je     12ac <main+0x16c>
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x8,-0x24(%rbp)
jl     12cf <main+0x18f>
mov    -0x20(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1275 <main+0x135>
mov    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jg     1185 <main+0x35>
mov    0x2e71(%rip),%rax
mov    (%rax),%rcx
lea    0xe8f(%rip),%rdi
mov    $0x3b,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
jmp    1274 <main+0x124>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1241 <main+0xf1>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1258 <main+0x108>
mov    %rax,%rbx
mov    0x10(%r15),%rdx
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%r15),%rdx
lea    0xedb(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%r15),%rdx
lea    0xf01(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2dda(%rip),%r13
cmp    0x0(%r13),%eax
jne    1288 <main+0x138>
lea    0xeff(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1279 <main+0x129>
mov    0x2d90(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%r15),%rdx
lea    0xde9(%rip),%rsi
jmp    126d <main+0x11d>
mov    0x2d79(%rip),%rax
mov    (%rax),%rdi
mov    0x10(%r15),%rdx
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe82(%rip),%r15
xor    %r12d,%r12d
jmp    12ca <main+0x17a>
cs nopw 0x0(%rax,%rax,1)
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r12d
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     1214 <main+0xc4>
test   %r12d,%r12d
je     12a0 <main+0x150>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe30(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x8,%r12d
jl     12a3 <main+0x153>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe0d(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
jmp    12a0 <main+0x150>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [60 x i8] c"Usage: bin2c <input bin file> <output h file> <array name>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Cannot open input file (%s).\0A\00"
@.str.3 = [3 x i8] c"wt\00"
@.str.4 = [31 x i8] c"Cannot open output file (%s).\0A\00"
@.str.5 = [60 x i8] c"/* File generated by bin2c. Do not edit this [%s] file. */\0A\00"
@.str.6 = [59 x i8] c"/* Instead, update the [%s] file and run bin2c again. */\0A\0A\00"
@.str.7 = [26 x i8] c"unsigned char %s[] = {\0A \00"
@EOF = global i32 0
@.str.8 = [3 x i8] c", \00"
@.str.9 = [4 x i8] c"\0A \00"
@.str.10 = [7 x i8] c"0x%02X\00"
@.str.11 = [5 x i8] c"\0A};\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32*, i32** @stderr
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %85
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i32*, i32** @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %85
27: ; preds = %15
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %7
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i32*, i32** @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %37)
store i32 1, i32* %3
br label %85
39: ; preds = %27
store i32 0, i32* %8
%40 = load i32*, i32** %7
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %7
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = load i32*, i32** %7
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 3
%53 = load i8*, i8** %52
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %72, %39
%56 = load i32*, i32** %6
%57 = call i32 @fgetc(i32* %56)
store i32 %57, i32* %9
%58 = load i32, i32* @EOF
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %78
60: ; preds = %55
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32*, i32** %7
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %66
66: ; preds = %63, %60
%67 = load i32, i32* %8
%68 = icmp sge i32 %67, 8
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32*, i32** %7
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %8
br label %72
72: ; preds = %69, %66
%73 = load i32*, i32** %7
%74 = load i32, i32* %9
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %55
78: ; preds = %55
%79 = load i32*, i32** %7
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%81 = load i32*, i32** %6
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %78, %33, %21, %12
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [60 x i8] c"Usage: bin2c <input bin file> <output h file> <array name>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [30 x i8] c"Cannot open input file (%s).\0A\00"
@.str.3 = [3 x i8] c"wt\00"
@.str.4 = [31 x i8] c"Cannot open output file (%s).\0A\00"
@.str.5 = [60 x i8] c"/* File generated by bin2c. Do not edit this [%s] file. */\0A\00"
@.str.6 = [59 x i8] c"/* Instead, update the [%s] file and run bin2c again. */\0A\0A\00"
@.str.7 = [26 x i8] c"unsigned char %s[] = {\0A \00"
@EOF = global i32 0
@.str.8 = [3 x i8] c", \00"
@.str.9 = [4 x i8] c"\0A \00"
@.str.10 = [7 x i8] c"0x%02X\00"
@.str.11 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i64 59, i64 1, i32* %5)
br label %56
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32*, i32** @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %56
16: ; preds = %7
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32*, i32** @stderr
%23 = load i8*, i8** %17
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %56
25: ; preds = %16
%26 = load i8*, i8** %17
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %8
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%33 = tail call i32 @fgetc(i32* %10)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %52, label %36
36: ; preds = %25, %45
%37 = phi i32 [ %49, %45 ], [ %33, %25 ]
%38 = phi i32 [ %48, %45 ], [ 0, %25 ]
%39 = icmp eq i32 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %19)
%42 = icmp sgt i32 %38, 7
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 3, i64 1, i32* %19)
br label %45
45: ; preds = %36, %43, %40
%46 = phi i32 [ 0, %43 ], [ %38, %40 ], [ 0, %36 ]
%47 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %37)
%48 = add nsw i32 %46, 1
%49 = tail call i32 @fgetc(i32* %10)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %36
52: ; preds = %45, %25
%53 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64 4, i64 1, i32* %19)
%54 = tail call i32 @fclose(i32* %10)
%55 = tail call i32 @fclose(i32* %19)
br label %56
56: ; preds = %52, %21, %12, %4
%57 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %21 ], [ 0, %52 ]
ret i32 %57
}