#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i, j = 0;
  FILE *f;
  if (argc > 1) {
    if (!(f = fopen(argv[1], "r"))) {
      perror(argv[1]);
      return 1;
    }
  } else {
    fprintf(stderr, "usage: bin2c file\n");
    return 2;
  }
  printf("unsigned char %s_data[] = {\n", argv[1]);
  while ((i = fgetc(f)) != EOF) {
    i = i & 0xff;
    if (!j++) {
      printf(" ");
    } else {
      printf(",%s", (j & 7) != 1 ? "" : "\n ");
    }
    printf(" 0x%02x", i);
  }
  printf("\n};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128f <main+0x13f>
jmp    11d8 <main+0x88>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    128f <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
je     127a <main+0x12a>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
jne    123b <main+0xeb>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1264 <main+0x114>
mov    -0x18(%rbp),%ecx
and    $0x7,%ecx
lea    0xdee(%rip),%rsi
lea    0xdf6(%rip),%rax
cmp    $0x1,%ecx
cmovne %rax,%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ee <main+0x9e>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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     1277 <main+0x107>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    0x8(%rbp),%rsi
test   %rax,%rax
je     12a0 <main+0x130>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
je     1267 <main+0xf7>
movzbl %al,%ebp
mov    $0x20,%edi
call   1030 <putchar@plt>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     1267 <main+0xf7>
mov    $0x2,%r14d
lea    0xe0b(%rip),%r13
lea    0xe22(%rip),%r15
lea    0xe22(%rip),%r12
nopw   0x0(%rax,%rax,1)
movzbl %al,%ebp
mov    %r14d,%eax
and    $0x7,%eax
cmp    $0x1,%eax
mov    %r13,%rsi
lea    0xe00(%rip),%rax
cmove  %rax,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
add    $0x1,%r14d
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
jne    1220 <main+0xb0>
lea    0xdd3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1291 <main+0x121>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    1291 <main+0x121>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"usage: bin2c file\0A\00"
@.str.2 = [29 x i8] c"unsigned char %s_data[] = {\0A\00"
@EOF = global i32 0
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c",%s\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"\0A \00"
@.str.7 = [8 x i8] c" 0x%02x\00"
@.str.8 = [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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @perror(i8* %20)
store i32 1, i32* %3
br label %56
22: ; preds = %11
br label %26
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %56
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %51, %26
%32 = load i32*, i32** %8
%33 = call i32 @fgetc(i32* %32)
store i32 %33, i32* %6
%34 = load i32, i32* @EOF
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %31
%37 = load i32, i32* %6
%38 = and i32 %37, 255
store i32 %38, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
%41 = icmp ne i32 %39, 0
br i1 %41, label %44, label %42
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %51
44: ; preds = %36
%45 = load i32, i32* %7
%46 = and i32 %45, 7
%47 = icmp ne i32 %46, 1
%48 = zext i1 %47 to i64
%49 = select i1 %47, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %44, %42
%52 = load i32, i32* %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %52)
br label %31
54: ; preds = %31
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %56
56: ; preds = %54, %23, %17
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"usage: bin2c file\0A\00"
@.str.2 = [29 x i8] c"unsigned char %s_data[] = {\0A\00"
@EOF = global i32 0
@.str.4 = [4 x i8] c",%s\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"\0A \00"
@.str.7 = [8 x i8] c" 0x%02x\00"
@str = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
%9 = load i8*, i8** %5
br i1 %8, label %10, label %15
10: ; preds = %4
%11 = tail call i32 @perror(i8* %9)
br label %42
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %42
15: ; preds = %4
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%17 = tail call i32 @fgetc(i32* %7)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %40, label %20
20: ; preds = %15
%21 = and i32 %17, 255
%22 = tail call i32 @putchar(i32 32)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%24 = tail call i32 @fgetc(i32* %7)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %40, label %27
27: ; preds = %20, %27
%28 = phi i32 [ %37, %27 ], [ %24, %20 ]
%29 = phi i32 [ %31, %27 ], [ 1, %20 ]
%30 = and i32 %28, 255
%31 = add nuw nsw i32 %29, 1
%32 = and i32 %31, 7
%33 = icmp eq i32 %32, 1
%34 = select i1 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %30)
%37 = tail call i32 @fgetc(i32* %7)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %27
40: ; preds = %27, %20, %15
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %40, %12, %10
%43 = phi i32 [ 0, %40 ], [ 1, %10 ], [ 2, %12 ]
ret i32 %43
}