#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
char *id(char *);
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  assert(argc >= 2);
  char *fn = argv[1];
  char *outfn = NULL;
  if (argc > 2)
    outfn = argv[2];
  char *varname = id(fn);
  FILE *f = fopen(fn, "r");
  FILE *fout;
  if (!outfn)
    fout = stdout;
  else
    fout = fopen(outfn, "w");
  fprintf(fout, "const char %s[] = {\n", varname);
  unsigned long n = 0;
  while (!feof(f)) {
    unsigned char c;
    if (fread(&c, 1, 1, f) == 0)
      break;
    fprintf(fout, "%s0x%.2X", (n > 0) ? "," : "", (int)c);
    ++n;
    if (n % 10 == 0)
      fprintf(fout, "\n");
  }
  fprintf(fout, ",0x00};\n");
  fprintf(fout, "const unsigned long %s_size = %lu;\n", varname, n);
  fclose(fout);
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11c1 <main+0x51>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <id@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1200 <main+0x90>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1214 <main+0xa4>
mov    -0x20(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1250 <main+0xe0>
jmp    12de <main+0x16e>
mov    -0x30(%rbp),%rcx
lea    -0x41(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    1273 <main+0x103>
jmp    12de <main+0x16e>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rcx
lea    0xdce(%rip),%rdx
lea    0xd99(%rip),%rax
cmp    $0x0,%rcx
cmova  %rax,%rdx
movzbl -0x41(%rbp),%ecx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    12d9 <main+0x169>
mov    -0x38(%rbp),%rdi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1232 <main+0xc2>
mov    -0x38(%rbp),%rdi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%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    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0x2,%ebx
setge  %dil
call   1060 <assert@plt>
mov    0x8(%r14),%rbp
cmp    $0x3,%ebx
jl     11c0 <main+0x30>
mov    0x10(%r14),%rbx
jmp    11c2 <main+0x32>
xor    %ebx,%ebx
mov    %rbp,%rdi
call   10b0 <id@plt>
mov    %rax,%r14
lea    0xe2c(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     11f8 <main+0x68>
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r12
jmp    1202 <main+0x72>
mov    0x2de1(%rip),%rax
mov    (%rax),%r12
lea    0xdfb(%rip),%rsi
xor    %r13d,%r13d
mov    %r12,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
mov    %r14,0x10(%rsp)
je     127d <main+0xed>
lea    0xdf3(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
lea    0xde3(%rip),%rsi
mov    %r12,%rdi
mov    0x10(%rsp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xd90(%rip),%r14
xor    %r13d,%r13d
jmp    12a4 <main+0x114>
xchg   %ax,%ax
mov    %r15,%rdi
call   1080 <feof@plt>
add    $0x1,%rbx
add    $0x1,%r13
test   %eax,%eax
jne    122a <main+0x9a>
mov    %rbx,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%rbp
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     122a <main+0x9a>
shr    $0x3,%rbp
lea    0x0(,%rbp,4),%rax
add    %rbp,%rax
lea    (%rax,%rax,1),%rbp
add    $0xffffffffffffffff,%rbp
test   %r13,%r13
lea    0xd2a(%rip),%rdx
lea    0xd51(%rip),%rax
cmove  %rax,%rdx
movzbl 0xf(%rsp),%ecx
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmp    %r13,%rbp
jne    1290 <main+0x100>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
jmp    1290 <main+0x100>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.3 = [9 x i8] c"%s0x%.2X\00"
@.str.4 = [2 x i8] c",\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [9 x i8] c",0x00};\0A\00"
@.str.8 = [36 x i8] c"const unsigned long %s_size = %lu;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 2
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
store i8* null, i8** %7
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %7
br label %26
26: ; preds = %22, %2
%27 = load i8*, i8** %6
%28 = call i8* @id(i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %6
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %9
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = load i32*, i32** @stdout
store i32* %34, i32** %10
br label %38
35: ; preds = %26
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %10
br label %38
38: ; preds = %35, %33
%39 = load i32*, i32** %10
%40 = load i8*, i8** %8
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i64 0, i64* %11
br label %42
42: ; preds = %69, %38
%43 = load i32*, i32** %9
%44 = call i32 @feof(i32* %43)
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
br i1 %46, label %47, label %70
47: ; preds = %42
%48 = load i32*, i32** %9
%49 = call i64 @fread(i8* %12, i32 1, i32 1, i32* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %70
52: ; preds = %47
%53 = load i32*, i32** %10
%54 = load i64, i64* %11
%55 = icmp ugt i64 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%58 = load i8, i8* %12
%59 = zext i8 %58 to i32
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %57, i32 %59)
%61 = load i64, i64* %11
%62 = add i64 %61, 1
store i64 %62, i64* %11
%63 = load i64, i64* %11
%64 = urem i64 %63, 10
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %52
%67 = load i32*, i32** %10
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %66, %52
br label %42
70: ; preds = %51, %42
%71 = load i32*, i32** %10
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%73 = load i32*, i32** %10
%74 = load i8*, i8** %8
%75 = load i64, i64* %11
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %74, i64 %75)
%77 = load i32*, i32** %10
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %9
%80 = call i32 @fclose(i32* %79)
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.3 = [9 x i8] c"%s0x%.2X\00"
@.str.4 = [2 x i8] c",\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.7 = [9 x i8] c",0x00};\0A\00"
@.str.8 = [36 x i8] c"const unsigned long %s_size = %lu;\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp sgt i32 %0, 1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp sgt i32 %0, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
br label %13
13: ; preds = %10, %2
%14 = phi i8* [ %12, %10 ], [ null, %2 ]
%15 = tail call i8* @id(i8* %8)
%16 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %14, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32*, i32** @stdout
br label %22
20: ; preds = %13
%21 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = phi i32* [ %21, %20 ], [ %19, %18 ]
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%25 = tail call i32 @feof(i32* %16)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %22, %43
%28 = phi i64 [ %38, %43 ], [ 0, %22 ]
%29 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %16)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %46
32: ; preds = %27
%33 = icmp eq i64 %28, 0
%34 = select i1 %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32 %36)
%38 = add i64 %28, 1
%39 = urem i64 %38, 10
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = tail call i32 @fputc(i32 10, i32* %23)
br label %43
43: ; preds = %32, %41
%44 = tail call i32 @feof(i32* %16)
%45 = icmp eq i32 %44, 0
br i1 %45, label %27, label %46
46: ; preds = %43, %22, %31
%47 = phi i64 [ %28, %31 ], [ 0, %22 ], [ %38, %43 ]
%48 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 8, i64 1, i32* %23)
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %15, i64 %47)
%50 = tail call i32 @fclose(i32* %23)
%51 = tail call i32 @fclose(i32* %16)
ret i32 0
}