#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i, num_to_read;
  unsigned char ch;
  unsigned char *chs;
  FILE *coldboot;
  coldboot = fopen(argv[1], "rb");
  if (coldboot == NULL) {
    fprintf(stderr, "Could not open %s\n", argv[1]);
    exit(1);
  }
  num_to_read = 0;
  while (1) {
    fread(&ch, 1, 1, coldboot);
    if (feof(coldboot))
      break;
    num_to_read++;
  }
  i = 0;
  fseek(coldboot, 0, SEEK_SET);
  chs = (char *)malloc(num_to_read);
  while (1) {
    fread(&chs[i], 1, 1, coldboot);
    if (feof(coldboot))
      break;
    i++;
  }
  printf("#ifndef __BOOTBYTES__H\n");
  printf("#define __BOOTBYTES__H\n\n");
  printf("static const int s_num_bytes = %d;\n", num_to_read);
  printf("static const unsigned char s_lodfile[] = {\n");
  for (i = 0; i < num_to_read; i++) {
    if (i % 16 == 0)
      printf("    ");
    printf("0x%.2x", chs[i]);
    if (i != num_to_read - 1) {
      printf(",");
    }
    if (i % 16 == 15 || i == num_to_read - 1) {
      printf("\n");
    } else {
      printf(" ");
    }
  }
  printf("};\n\n");
  printf("#endif\n");
  free(chs);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f0 <main+0x60>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x30(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1223 <main+0x93>
jmp    1231 <main+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f7 <main+0x67>
movl   $0x0,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     128b <main+0xfb>
jmp    1299 <main+0x109>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1258 <main+0xc8>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    139b <main+0x20b>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1309 <main+0x179>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1342 <main+0x1b2>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     1367 <main+0x1d7>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    137a <main+0x1ea>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1388 <main+0x1f8>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    138d <main+0x1fd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12db <main+0x14b>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%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,%rbx
mov    0x8(%rsi),%rdi
lea    0xe37(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     134d <main+0x19d>
mov    %rax,%r12
mov    $0x1,%ebp
mov    $0xfffffffe,%r13d
lea    0x7(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fread@plt>
mov    %r12,%rdi
call   1090 <feof@plt>
add    $0xffffffffffffffff,%rbp
add    $0x1,%r13d
test   %rax,%rax
je     11f0 <main+0x40>
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%r15
neg    %r15
mov    %r15d,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fread@plt>
mov    %r12,%rdi
call   1090 <feof@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1250 <main+0xa0>
lea    0xdc9(%rip),%rdi
call   1050 <puts@plt>
lea    0xdd4(%rip),%rdi
call   1050 <puts@plt>
lea    0xd81(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdcf(%rip),%rdi
call   1050 <puts@plt>
test   %ebp,%ebp
je     131c <main+0x16c>
mov    %r13d,%ebp
lea    0xd86(%rip),%rbx
xor    %r12d,%r12d
jmp    12cf <main+0x11f>
xchg   %ax,%ax
call   1040 <putchar@plt>
add    $0x1,%r12
add    $0xffffffffffffffff,%r15
je     131c <main+0x16c>
mov    %r12d,%r13d
and    $0xf,%r13d
jne    12e6 <main+0x136>
lea    0xd5b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl (%r14,%r12,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
cmp    %r12,%rbp
je     12c0 <main+0x110>
mov    $0x2c,%edi
call   1040 <putchar@plt>
cmp    $0xf,%r13d
mov    $0x20,%edi
mov    $0xa,%eax
cmove  %eax,%edi
jmp    12c0 <main+0x110>
lea    0xd7d(%rip),%rdi
call   1050 <puts@plt>
lea    0xd75(%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
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xca2(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [24 x i8] c"#ifndef __BOOTBYTES__H\0A\00"
@.str.3 = [25 x i8] c"#define __BOOTBYTES__H\0A\0A\00"
@.str.4 = [36 x i8] c"static const int s_num_bytes = %d;\0A\00"
@.str.5 = [44 x i8] c"static const unsigned char s_lodfile[] = {\0A\00"
@.str.6 = [5 x i8] c" \00"
@.str.7 = [7 x i8] c"0x%.2x\00"
@.str.8 = [2 x i8] c",\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [2 x i8] c" \00"
@.str.11 = [5 x i8] c"};\0A\0A\00"
@.str.12 = [8 x i8] c"#endif\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 i8
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
store i32 0, i32* %7
br label %25
25: ; preds = %24, %32
%26 = load i32*, i32** %10
%27 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %26)
%28 = load i32*, i32** %10
%29 = call i64 @feof(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
br label %35
32: ; preds = %25
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %25
35: ; preds = %31
store i32 0, i32* %6
%36 = load i32*, i32** %10
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i32, i32* %7
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %9
br label %42
42: ; preds = %35, %53
%43 = load i8*, i8** %9
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i32*, i32** %10
%48 = call i32 @fread(i8* %46, i32 1, i32 1, i32* %47)
%49 = load i32*, i32** %10
%50 = call i64 @feof(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %42
br label %56
53: ; preds = %42
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %42
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %62
62: ; preds = %100, %56
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %103
66: ; preds = %62
%67 = load i32, i32* %6
%68 = srem i32 %67, 16
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
%73 = load i8*, i8** %9
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = load i32, i32* %6
%81 = load i32, i32* %7
%82 = sub nsw i32 %81, 1
%83 = icmp ne i32 %80, %82
br i1 %83, label %84, label %86
84: ; preds = %72
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %86
86: ; preds = %84, %72
%87 = load i32, i32* %6
%88 = srem i32 %87, 16
%89 = icmp eq i32 %88, 15
br i1 %89, label %95, label %90
90: ; preds = %86
%91 = load i32, i32* %6
%92 = load i32, i32* %7
%93 = sub nsw i32 %92, 1
%94 = icmp eq i32 %91, %93
br i1 %94, label %95, label %97
95: ; preds = %90, %86
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %99
97: ; preds = %90
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %99
99: ; preds = %97, %95
br label %100
100: ; preds = %99
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %62
103: ; preds = %62
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%106 = load i8*, i8** %9
%107 = call i32 @free(i8* %106)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [36 x i8] c"static const int s_num_bytes = %d;\0A\00"
@.str.6 = [5 x i8] c" \00"
@.str.7 = [7 x i8] c"0x%.2x\00"
@str = [23 x i8] c"#ifndef __BOOTBYTES__H\00"
@str.13 = [24 x i8] c"#define __BOOTBYTES__H\0A\00"
@str.14 = [43 x i8] c"static const unsigned char s_lodfile[] = {\00"
@str.15 = [4 x i8] c"};\0A\00"
@str.16 = [7 x i8] c"#endif\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %4
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2, %13
%14 = phi i32 [ %18, %13 ], [ 0, %2 ]
%15 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %6)
%16 = tail call i64 @feof(i32* %6)
%17 = icmp eq i64 %16, 0
%18 = add nuw nsw i32 %14, 1
br i1 %17, label %13, label %19
19: ; preds = %13
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %6, i32 0, i32 %20)
%22 = tail call i64 @malloc(i32 %14)
%23 = inttoptr i64 %22 to i8*
br label %24
24: ; preds = %24, %19
%25 = phi i64 [ %30, %24 ], [ 0, %19 ]
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = tail call i32 @fread(i8* %26, i32 1, i32 1, i32* %6)
%28 = tail call i64 @feof(i32* %6)
%29 = icmp eq i64 %28, 0
%30 = add nuw i64 %25, 1
br i1 %29, label %24, label %31
31: ; preds = %24
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.14, i64 0, i64 0))
%36 = icmp eq i32 %14, 0
br i1 %36, label %63, label %37
37: ; preds = %31
%38 = add nsw i32 %14, -1
%39 = zext i32 %38 to i64
%40 = zext i32 %14 to i64
br label %41
41: ; preds = %37, %58
%42 = phi i64 [ 0, %37 ], [ %61, %58 ]
%43 = trunc i64 %42 to i32
%44 = and i32 %43, 15
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = getelementptr inbounds i8, i8* %23, i64 %42
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = icmp eq i64 %42, %39
br i1 %53, label %58, label %54
54: ; preds = %48
%55 = tail call i32 @putchar(i32 44)
%56 = icmp eq i32 %44, 15
%57 = select i1 %56, i32 10, i32 32
br label %58
58: ; preds = %54, %48
%59 = phi i32 [ 10, %48 ], [ %57, %54 ]
%60 = tail call i32 @putchar(i32 %59)
%61 = add nuw nsw i64 %42, 1
%62 = icmp eq i64 %61, %40
br i1 %62, label %63, label %41
63: ; preds = %58, %31
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.15, i64 0, i64 0))
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.16, i64 0, i64 0))
%66 = tail call i32 @free(i8* %23)
ret i32 0
}