#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int main(int argc, char **argv) {
  FILE *fp;
  size_t fsize;
  char *fname;
  char *name;
  uint8_t *buf;
  size_t i;
  size_t j;
  srand(0);
  if (argc != 3) {
    errx(1, "Usage: %s file name", argv[0]);
  }
  fname = argv[1];
  name = argv[2];
  fp = fopen(fname, "r");
  if (!fp) {
    err(1, "%s", fname);
  }
  fseek(fp, 0, SEEK_END);
  fsize = ftell(fp);
  rewind(fp);
  buf = malloc(fsize);
  fread(buf, fsize, 1, fp);
  fclose(fp);
  printf("uint8_t data_%s[] = {\n", name);
  for (i = 0; i < fsize;) {
    printf("\t\t");
    for (j = 0; j < 8 && i + j < fsize; ++j) {
      printf("0x%02x, ", buf[i + j]);
    }
    printf("\n");
    i += j;
  }
  printf("};\n");
  free(buf);
  return 0;
}


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)
xor    %edi,%edi
call   1090 <srand@plt>
cmpl   $0x3,-0x8(%rbp)
je     11ff <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xe06(%rip),%rsi
call   1060 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124b <main+0x8b>
mov    -0x28(%rbp),%rdx
mov    $0x1,%edi
lea    0xdd0(%rip),%rsi
call   10b0 <err@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    135e <main+0x19e>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x8,-0x48(%rbp)
mov    %al,-0x49(%rbp)
jae    1301 <main+0x141>
mov    -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
setb   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1311 <main+0x151>
jmp    133f <main+0x17f>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
add    -0x48(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    12df <main+0x11f>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12bb <main+0xfb>
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%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,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   10b0 <srand@plt>
cmp    $0x3,%ebp
je     1210 <main+0x30>
mov    (%rbx),%rdx
lea    0xdfa(%rip),%rsi
mov    $0x1,%edi
call   1080 <errx@plt>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%r15
lea    0xdf5(%rip),%rsi
mov    %r14,%rdi
call   1100 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1243 <main+0x63>
lea    0xde0(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   10d0 <err@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    %r12,%rdi
call   10c0 <ftell@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   10a0 <rewind@plt>
mov    %r13,%rdi
call   10e0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fread@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
lea    0xd83(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r13,%r13
je     13da <main+0x1fa>
lea    0xd80(%rip),%r15
lea    0xd7c(%rip),%r12
xor    %ebp,%ebp
jmp    12d8 <main+0xf8>
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    $0xa,%edi
call   1040 <putchar@plt>
add    %rbx,%rbp
cmp    %r13,%rbp
jae    13da <main+0x1fa>
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
cmp    %r13,%rbp
jae    12c0 <main+0xe0>
mov    (%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x1(%rbp),%rax
mov    $0x1,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x4(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x2(%rbp),%rax
mov    $0x2,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x8(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x3(%rbp),%rax
mov    $0x3,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0xc(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x4(%rbp),%rax
mov    $0x4,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x10(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x5(%rbp),%rax
mov    $0x5,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x14(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x6(%rbp),%rax
mov    $0x6,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x18(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x7(%rbp),%rax
mov    $0x7,%ebx
cmp    %r13,%rax
jae    12c2 <main+0xe2>
mov    0x1c(%r14,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x8,%ebx
jmp    12c2 <main+0xe2>
lea    0xc5b(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: %s file name\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@SEEK_END = global i32 0
@.str.3 = [23 x i8] c"uint8_t data_%s[] = {\0A\00"
@.str.4 = [3 x i8] c"\09\09\00"
@.str.5 = [9 x i8] c"0x%02x, \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @srand(i32 0)
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %16, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %9
%28 = load i8*, i8** %8
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %21
%33 = load i8*, i8** %8
%34 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %21
%36 = load i32*, i32** %6
%37 = load i32, i32* @SEEK_END
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i32*, i32** %6
%40 = call i64 @ftell(i32* %39)
store i64 %40, i64* %7
%41 = load i32*, i32** %6
%42 = call i32 @rewind(i32* %41)
%43 = load i64, i64* %7
%44 = call i32* @malloc(i64 %43)
store i32* %44, i32** %10
%45 = load i32*, i32** %10
%46 = load i64, i64* %7
%47 = load i32*, i32** %6
%48 = call i32 @fread(i32* %45, i64 %46, i32 1, i32* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %51)
store i64 0, i64* %11
br label %53
53: ; preds = %81, %35
%54 = load i64, i64* %11
%55 = load i64, i64* %7
%56 = icmp ult i64 %54, %55
br i1 %56, label %57, label %86
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %12
br label %59
59: ; preds = %78, %57
%60 = load i64, i64* %12
%61 = icmp ult i64 %60, 8
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i64, i64* %11
%64 = load i64, i64* %12
%65 = add i64 %63, %64
%66 = load i64, i64* %7
%67 = icmp ult i64 %65, %66
br label %68
68: ; preds = %62, %59
%69 = phi i1 [ false, %59 ], [ %67, %62 ]
br i1 %69, label %70, label %81
70: ; preds = %68
%71 = load i32*, i32** %10
%72 = load i64, i64* %11
%73 = load i64, i64* %12
%74 = add i64 %72, %73
%75 = getelementptr inbounds i32, i32* %71, i64 %74
%76 = load i32, i32* %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %70
%79 = load i64, i64* %12
%80 = add i64 %79, 1
store i64 %80, i64* %12
br label %59
81: ; preds = %68
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%83 = load i64, i64* %12
%84 = load i64, i64* %11
%85 = add i64 %84, %83
store i64 %85, i64* %11
br label %53
86: ; preds = %53
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%88 = load i32*, i32** %10
%89 = call i32 @free(i32* %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: %s file name\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@SEEK_END = global i32 0
@.str.3 = [23 x i8] c"uint8_t data_%s[] = {\0A\00"
@.str.4 = [3 x i8] c"\09\09\00"
@.str.5 = [9 x i8] c"0x%02x, \00"
@str = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @srand(i32 0)
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %8
8: ; preds = %5, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %17
17: ; preds = %15, %8
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %13, i32 0, i32 %18)
%20 = tail call i64 @ftell(i32* %13)
%21 = tail call i32 @rewind(i32* %13)
%22 = tail call i32* @malloc(i64 %20)
%23 = tail call i32 @fread(i32* %22, i64 %20, i32 1, i32* %13)
%24 = tail call i32 @fclose(i32* %13)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%26 = icmp eq i64 %20, 0
br i1 %26, label %82, label %27
27: ; preds = %17, %77
%28 = phi i64 [ %80, %77 ], [ 0, %17 ]
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp ult i64 %28, %20
br i1 %30, label %31, label %77
31: ; preds = %27
%32 = getelementptr inbounds i32, i32* %22, i64 %28
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = add nuw i64 %28, 1
%36 = icmp ult i64 %35, %20
br i1 %36, label %37, label %77
37: ; preds = %31
%38 = getelementptr inbounds i32, i32* %22, i64 %35
%39 = load i32, i32* %38
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = add nuw i64 %28, 2
%42 = icmp ult i64 %41, %20
br i1 %42, label %43, label %77
43: ; preds = %37
%44 = getelementptr inbounds i32, i32* %22, i64 %41
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = add nuw i64 %28, 3
%48 = icmp ult i64 %47, %20
br i1 %48, label %49, label %77
49: ; preds = %43
%50 = getelementptr inbounds i32, i32* %22, i64 %47
%51 = load i32, i32* %50
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = add nuw i64 %28, 4
%54 = icmp ult i64 %53, %20
br i1 %54, label %55, label %77
55: ; preds = %49
%56 = getelementptr inbounds i32, i32* %22, i64 %53
%57 = load i32, i32* %56
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = add nuw i64 %28, 5
%60 = icmp ult i64 %59, %20
br i1 %60, label %61, label %77
61: ; preds = %55
%62 = getelementptr inbounds i32, i32* %22, i64 %59
%63 = load i32, i32* %62
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = add nuw i64 %28, 6
%66 = icmp ult i64 %65, %20
br i1 %66, label %67, label %77
67: ; preds = %61
%68 = getelementptr inbounds i32, i32* %22, i64 %65
%69 = load i32, i32* %68
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = add nuw i64 %28, 7
%72 = icmp ult i64 %71, %20
br i1 %72, label %73, label %77
73: ; preds = %67
%74 = getelementptr inbounds i32, i32* %22, i64 %71
%75 = load i32, i32* %74
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %73, %67, %61, %55, %49, %43, %37, %31, %27
%78 = phi i64 [ 0, %27 ], [ 1, %31 ], [ 2, %37 ], [ 3, %43 ], [ 4, %49 ], [ 5, %55 ], [ 6, %61 ], [ 7, %67 ], [ 8, %73 ]
%79 = tail call i32 @putchar(i32 10)
%80 = add i64 %78, %28
%81 = icmp ult i64 %80, %20
br i1 %81, label %27, label %82
82: ; preds = %77, %17
%83 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%84 = tail call i32 @free(i32* %22)
ret i32 0
}