#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 != 2) {
    printf("using: <file>\n");
    return 1;
  }
  char *fn = argv[1];
  FILE *f = fopen(fn, "r");
  printf("unsigned char a[] = {");
  unsigned long n = 0;
  while (!feof(f)) {
    unsigned char c;
    if (fread(&c, 1, 1, f) == 0)
      break;
    printf("0x%.2X,", (int)c);
    ++n;
  }
  fclose(f);
  printf("};\n");
  printf("unsigned long al=%d;\n", 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   $0x2,-0x8(%rbp)
je     118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe60(%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    11de <main+0x8e>
jmp    1224 <main+0xd4>
mov    -0x20(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    1201 <main+0xb1>
jmp    1224 <main+0xd4>
movzbl -0x29(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c0 <main+0x70>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xded(%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>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11a6 <main+0x46>
mov    0x8(%rsi),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe76(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11ba <main+0x5a>
xor    %ebx,%ebx
jmp    1209 <main+0xa9>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    122e <main+0xce>
lea    0xf(%rsp),%r12
lea    0xe52(%rip),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     1209 <main+0xa9>
movzbl 0xf(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d0 <main+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
lea    0xdfc(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"using: <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"unsigned char a[] = {\00"
@.str.3 = [8 x i8] c"0x%.2X,\00"
@.str.4 = [4 x i8] c"};\0A\00"
@.str.5 = [22 x i8] c"unsigned long al=%d;\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, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %43
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %8
br label %21
21: ; preds = %31, %14
%22 = load i32*, i32** %7
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %37
26: ; preds = %21
%27 = load i32*, i32** %7
%28 = call i64 @fread(i8* %9, i32 1, i32 1, i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
br label %37
31: ; preds = %26
%32 = load i8, i8* %9
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
br label %21
37: ; preds = %30, %21
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%41 = load i64, i64* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %37, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"unsigned char a[] = {\00"
@.str.3 = [8 x i8] c"0x%.2X,\00"
@.str.5 = [22 x i8] c"unsigned long al=%d;\0A\00"
@str = [3 x i8] c"};\00"
@str.6 = [14 x i8] c"using: <file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %31
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @feof(i32* %10)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %7, %19
%15 = phi i64 [ %23, %19 ], [ 0, %7 ]
%16 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %10)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %26
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 ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = add i64 %15, 1
%24 = tail call i32 @feof(i32* %10)
%25 = icmp eq i32 %24, 0
br i1 %25, label %14, label %26
26: ; preds = %19, %7, %18
%27 = phi i64 [ %15, %18 ], [ 0, %7 ], [ %23, %19 ]
%28 = tail call i32 @fclose(i32* %10)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 %27)
br label %31
31: ; preds = %26, %5
%32 = phi i32 [ 1, %5 ], [ 0, %26 ]
ret i32 %32
}