#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 3)
    return 0;
  char *fn = argv[1];
  FILE *f = fopen(fn, "rb");
  printf("unsigned char %s[] = {\n", argv[2]);
  unsigned long n = 0;
  while (!feof(f)) {
    unsigned char c;
    if (fread(&c, 1, 1, f) == 0)
      break;
    printf("0x%.2X, ", (int)c);
    ++n;
    if (n % 10 == 0)
      printf("\n");
  }
  fclose(f);
  printf("};\n");
  printf("int %s_size = %ld;\n", argv[2], n);
  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   $0x3,-0x8(%rbp)
je     117c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    127c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d8 <main+0x88>
jmp    1244 <main+0xf4>
mov    -0x20(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    11fb <main+0xab>
jmp    1244 <main+0xf4>
movzbl -0x29(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    123f <main+0xef>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ba <main+0x6a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x3,%edi
jne    11ff <main+0x8f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rsi
lea    0xe5b(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
test   %eax,%eax
mov    %rbx,0x10(%rsp)
je     1202 <main+0x92>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xe66(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%rax
mov    0x10(%rax),%rsi
lea    0xe3d(%rip),%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret
mov    $0x1,%ebx
lea    0xf(%rsp),%r13
xor    %r12d,%r12d
jmp    1234 <main+0xc4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <feof@plt>
add    $0x1,%rbx
add    $0x1,%r12
test   %eax,%eax
jne    11c3 <main+0x53>
mov    %rbx,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%r14
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11c3 <main+0x53>
shr    $0x3,%r14
lea    (%r14,%r14,4),%rax
lea    (%rax,%rax,1),%rbp
add    $0xffffffffffffffff,%rbp
movzbl 0xf(%rsp),%esi
lea    0xd9a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    %r12,%rbp
jne    1220 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xb0>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.2 = [9 x i8] c"0x%.2X, \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"};\0A\00"
@.str.5 = [20 x i8] c"int %s_size = %ld;\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%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 ne i32 %10, 3
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %54
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i64 0, i64* %8
br label %23
23: ; preds = %44, %13
%24 = load i32*, i32** %7
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %45
28: ; preds = %23
%29 = load i32*, i32** %7
%30 = call i64 @fread(i8* %9, i32 1, i32 1, i32* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
br label %45
33: ; preds = %28
%34 = load i8, i8* %9
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i64, i64* %8
%38 = add i64 %37, 1
store i64 %38, i64* %8
%39 = load i64, i64* %8
%40 = urem i64 %39, 10
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %33
br label %23
45: ; preds = %32, %23
%46 = load i32*, i32** %7
%47 = call i32 @fclose(i32* %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i64, i64* %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %51, i64 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %45, %12
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.2 = [9 x i8] c"0x%.2X, \00"
@.str.5 = [20 x i8] c"int %s_size = %ld;\0A\00"
@str = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %5, label %37
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @feof(i32* %8)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %5, %28
%15 = phi i64 [ %23, %28 ], [ 0, %5 ]
%16 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %31
19: ; preds = %14
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = add i64 %15, 1
%24 = urem i64 %23, 10
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = tail call i32 @putchar(i32 10)
br label %28
28: ; preds = %19, %26
%29 = tail call i32 @feof(i32* %8)
%30 = icmp eq i32 %29, 0
br i1 %30, label %14, label %31
31: ; preds = %28, %5, %18
%32 = phi i64 [ %15, %18 ], [ 0, %5 ], [ %23, %28 ]
%33 = tail call i32 @fclose(i32* %8)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%35 = load i8*, i8** %9
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %35, i64 %32)
br label %37
37: ; preds = %2, %31
ret i32 0
}