#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
unsigned int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *f1, *f2;
  unsigned char buf[12];
  unsigned int count, i, size = 0;
  if (argc != 4) {
    fprintf(stderr, "Syntax: bin2c <infile> <outfile> <variable name>\n");
    return -1;
  }
  f1 = fopen(argv[1], "rb");
  if (!f1) {
    fprintf(stderr, "Error opening %s\n", argv[1]);
    return -1;
  }
  f2 = fopen(argv[2], "w");
  if (!f2) {
    fprintf(stderr, "Error opening %s\n", argv[2]);
    return -1;
  }
  fprintf(f2, "/* Autogenerated by bin2c */\n\n");
  fprintf(f2, "uint8_t %s[] = {\n", argv[3]);
  while ((count = fread(buf, 1, sizeof(buf), f1)) > 0) {
    fprintf(f2, "\t");
    for (i = 0; i < count; i++) {
      fprintf(f2, "0x%.2x, ", (unsigned int)buf[i]);
      size++;
    }
    fprintf(f2, "\n");
  }
  fprintf(f2, "};\n\n");
  fprintf(f2, "uint32_t %s_size = %i;\n", argv[3], size);
  fclose(f1);
  fclose(f2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     118b <main+0x4b>
mov    0x2e72(%rip),%rax
movslq (%rax),%rdi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132d <main+0x1ed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11da <main+0x9a>
mov    0x2e2b(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132d <main+0x1ed>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1229 <main+0xe9>
mov    0x2ddc(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132d <main+0x1ed>
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc,%edx
call   1030 <fread@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jbe    12e5 <main+0x1a5>
mov    -0x20(%rbp),%rdi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    12ce <main+0x18e>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%eax
movzbl -0x2c(%rbp,%rax,1),%edx
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1291 <main+0x151>
mov    -0x20(%rbp),%rdi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1255 <main+0x115>
mov    -0x20(%rbp),%rdi
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x38(%rbp),%ecx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x4,%edi
jne    12d7 <main+0x177>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12f9 <main+0x199>
mov    0x10(%rbx),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1309 <main+0x1a9>
mov    %rax,%r15
lea    0xe8e(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,0x10(%rsp)
mov    0x18(%rbx),%rdx
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x1c(%rsp),%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
mov    $0x0,%r13d
test   %eax,%eax
je     128b <main+0x12b>
mov    %eax,%r14d
lea    0xe62(%rip),%r12
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    $0x9,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x1c(%rsp,%rbx,1),%edx
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1240 <main+0xe0>
add    %ebp,%r13d
mov    $0xa,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
lea    0x1c(%rsp),%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    1220 <main+0xc0>
lea    0xdf1(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    0x10(%rsp),%rax
mov    0x18(%rax),%rdx
lea    0xdd4(%rip),%rsi
mov    %r15,%rdi
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    132a <main+0x1ca>
mov    0x2d02(%rip),%rax
movslq (%rax),%rcx
lea    0xd18(%rip),%rdi
mov    $0x31,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
jmp    1325 <main+0x1c5>
mov    0x2ce0(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbx),%rdx
jmp    1317 <main+0x1b7>
mov    0x2cd0(%rip),%rax
movslq (%rax),%rdi
mov    0x10(%rbx),%rdx
lea    0xd17(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"Syntax: bin2c <infile> <outfile> <variable name>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Error opening %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"/* Autogenerated by bin2c */\0A\0A\00"
@.str.5 = [18 x i8] c"uint8_t %s[] = {\0A\00"
@.str.6 = [2 x i8] c"\09\00"
@.str.7 = [9 x i8] c"0x%.2x, \00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [5 x i8] c"};\0A\0A\00"
@.str.10 = [24 x i8] c"uint32_t %s_size = %i;\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 [12 x i8]
%9 = alloca i32
%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* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %98
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %34, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %3
br label %98
34: ; preds = %19
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %49, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %47)
store i32 -1, i32* %3
br label %98
49: ; preds = %34
%50 = load i32*, i32** %7
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32*, i32** %7
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i8*, i8** %54
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %82, %49
%58 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%59 = load i32*, i32** %6
%60 = call i32 @fread(i8* %58, i32 1, i32 12, i32* %59)
store i32 %60, i32* %9
%61 = icmp ugt i32 %60, 0
br i1 %61, label %62, label %85
62: ; preds = %57
%63 = load i32*, i32** %7
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %10
br label %65
65: ; preds = %79, %62
%66 = load i32, i32* %10
%67 = load i32, i32* %9
%68 = icmp ult i32 %66, %67
br i1 %68, label %69, label %82
69: ; preds = %65
%70 = load i32*, i32** %7
%71 = load i32, i32* %10
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %11
%78 = add i32 %77, 1
store i32 %78, i32* %11
br label %79
79: ; preds = %69
%80 = load i32, i32* %10
%81 = add i32 %80, 1
store i32 %81, i32* %10
br label %65
82: ; preds = %65
%83 = load i32*, i32** %7
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %57
85: ; preds = %57
%86 = load i32*, i32** %7
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%88 = load i32*, i32** %7
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 3
%91 = load i8*, i8** %90
%92 = load i32, i32* %11
%93 = call i32 (i32*, i8*, ...) @fprintf(i32* %88, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %91, i32 %92)
%94 = load i32*, i32** %6
%95 = call i32 @fclose(i32* %94)
%96 = load i32*, i32** %7
%97 = call i32 @fclose(i32* %96)
store i32 0, i32* %3
br label %98
98: ; preds = %85, %41, %26, %14
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"Syntax: bin2c <infile> <outfile> <variable name>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Error opening %s\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [31 x i8] c"/* Autogenerated by bin2c */\0A\0A\00"
@.str.5 = [18 x i8] c"uint8_t %s[] = {\0A\00"
@.str.7 = [9 x i8] c"0x%.2x, \00"
@.str.9 = [5 x i8] c"};\0A\0A\00"
@.str.10 = [24 x i8] c"uint32_t %s_size = %i;\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i64 49, i64 1, i32* %9)
br label %65
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load i8*, i8** %12
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %65
22: ; preds = %11
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load i8*, i8** %23
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %65
33: ; preds = %22
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 30, i64 1, i32* %25)
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = call i32 @fread(i8* %4, i32 1, i32 12, i32* %14)
%39 = icmp eq i32 %38, 0
br i1 %39, label %58, label %40
40: ; preds = %33, %53
%41 = phi i32 [ %56, %53 ], [ %38, %33 ]
%42 = phi i32 [ %54, %53 ], [ 0, %33 ]
%43 = tail call i32 @fputc(i32 9, i32* %25)
%44 = zext i32 %41 to i64
br label %45
45: ; preds = %40, %45
%46 = phi i64 [ 0, %40 ], [ %51, %45 ]
%47 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = add nuw nsw i64 %46, 1
%52 = icmp eq i64 %51, %44
br i1 %52, label %53, label %45
53: ; preds = %45
%54 = add i32 %42, %41
%55 = tail call i32 @fputc(i32 10, i32* %25)
%56 = call i32 @fread(i8* %4, i32 1, i32 12, i32* %14)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %40
58: ; preds = %53, %33
%59 = phi i32 [ 0, %33 ], [ %54, %53 ]
%60 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64 4, i64 1, i32* %25)
%61 = load i8*, i8** %35
%62 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %61, i32 %59)
%63 = tail call i32 @fclose(i32* %14)
%64 = tail call i32 @fclose(i32* %25)
br label %65
65: ; preds = %58, %27, %16, %6
%66 = phi i32 [ -1, %6 ], [ 0, %58 ], [ -1, %27 ], [ -1, %16 ]
ret i32 %66
}