#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 *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *f;
  int i, c;
  char *arr_name;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s input_file [array_name] [> output_file]\n",
            argv[0]);
    return 1;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    fprintf(stderr, "%s: fopen(%s) failed", argv[0], argv[1]);
    return 1;
  }
  if (argc >= 3)
    arr_name = argv[2];
  else
    arr_name = "filedata";
  printf("const unsigned char %s[] = {", arr_name);
  for (i = 0;; i++) {
    if ((c = fgetc(f)) == EOF)
      break;
    if (i != 0)
      printf(",");
    if ((i % 12) == 0)
      printf("\n\t");
    printf("0x%.2X", (unsigned char)c);
  }
  printf("\n};\n");
  fclose(f);
  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   $0x2,-0x8(%rbp)
jge    119a <main+0x4a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ef <main+0x9f>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x178>
cmpl   $0x3,-0x8(%rbp)
jl     120a <main+0xba>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1215 <main+0xc5>
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%eax
jne    124e <main+0xfe>
jmp    12aa <main+0x15a>
cmpl   $0x0,-0x1c(%rbp)
je     1266 <main+0x116>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1288 <main+0x138>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
movzbl %al,%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122e <main+0xde>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%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
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     11a8 <main+0x38>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    1267 <main+0xf7>
mov    %edi,%ebx
mov    0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11cd <main+0x5d>
mov    %rax,%r13
cmp    $0x3,%ebx
jb     11f3 <main+0x83>
mov    0x10(%rbp),%rsi
jmp    11fa <main+0x8a>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
mov    0x8(%rbp),%rcx
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    1267 <main+0xf7>
lea    0xe51(%rip),%rsi
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebx
mov    0x2dcf(%rip),%rax
cmp    (%rax),%ebx
je     1251 <main+0xe1>
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl %bl,%esi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    0x2d9b(%rip),%rax
cmp    (%rax),%ebp
jne    1276 <main+0x106>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
mov    $0xffffffff,%r15d
lea    0xdec(%rip),%r12
jmp    12ba <main+0x14a>
nopw   0x0(%rax,%rax,1)
movzbl %bpl,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%ebx
mov    %r13,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
add    $0xffffffff,%r15d
mov    0x2d32(%rip),%rax
cmp    (%rax),%ebp
je     1251 <main+0xe1>
mov    %ebx,%eax
mov    $0xaaaaaaab,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,2),%r14d
shl    $0x2,%r14d
mov    $0x2c,%edi
call   1030 <putchar@plt>
add    %r15d,%r14d
jne    1290 <main+0x120>
lea    0xd8a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1290 <main+0x120>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s input_file [array_name] [> output_file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"%s: fopen(%s) failed\00"
@.str.3 = [9 x i8] c"filedata\00"
@.str.4 = [29 x i8] c"const unsigned char %s[] = {\00"
@EOF = global i32 0
@.str.5 = [2 x i8] c",\00"
@.str.6 = [3 x i8] c"\0A\09\00"
@.str.7 = [7 x i8] c"0x%.2X\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
%9 = alloca i8*
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, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %74
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %34
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %32)
store i32 1, i32* %3
br label %74
34: ; preds = %18
%35 = load i32, i32* %4
%36 = icmp sge i32 %35, 3
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
store i8* %40, i8** %9
br label %42
41: ; preds = %34
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %42
42: ; preds = %41, %37
%43 = load i8*, i8** %9
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %43)
store i32 0, i32* %7
br label %45
45: ; preds = %67, %42
%46 = load i32*, i32** %6
%47 = call i32 @fgetc(i32* %46)
store i32 %47, i32* %8
%48 = load i32, i32* @EOF
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %45
br label %70
51: ; preds = %45
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = load i32, i32* %7
%58 = srem i32 %57, 12
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = load i32, i32* %8
%64 = trunc i32 %63 to i8
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %62
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %45
70: ; preds = %50
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
store i32 0, i32* %3
br label %74
74: ; preds = %70, %25, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Usage: %s input_file [array_name] [> output_file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"%s: fopen(%s) failed\00"
@.str.3 = [9 x i8] c"filedata\00"
@.str.4 = [29 x i8] c"const unsigned char %s[] = {\00"
@EOF = global i32 0
@.str.6 = [3 x i8] c"\0A\09\00"
@.str.7 = [7 x i8] c"0x%.2X\00"
@str = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %54
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = load i8*, i8** %9
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %16)
br label %54
18: ; preds = %8
%19 = icmp ugt i32 %0, 2
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
br label %23
23: ; preds = %18, %20
%24 = phi i8* [ %22, %20 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %18 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = tail call i32 @fgetc(i32* %11)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %51, label %29
29: ; preds = %23
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%31 = and i32 %26, 255
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%33 = tail call i32 @fgetc(i32* %11)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %51, label %36
36: ; preds = %29, %44
%37 = phi i32 [ %48, %44 ], [ %33, %29 ]
%38 = phi i32 [ %47, %44 ], [ 1, %29 ]
%39 = tail call i32 @putchar(i32 44)
%40 = urem i32 %38, 12
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
%45 = and i32 %37, 255
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i32 %38, 1
%48 = tail call i32 @fgetc(i32* %11)
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %36
51: ; preds = %44, %29, %23
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%53 = tail call i32 @fclose(i32* %11)
br label %54
54: ; preds = %51, %13, %4
%55 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 0, %51 ]
ret i32 %55
}