#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*/ *const);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *const);
int /*<<< orphan*/ *fopen(char *const, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *const);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  assert(argc == 2);
  if (argc != 2) {
    printf("UtilBinToH <bin>\n");
    return -1;
  }
  char *const fn = argv[1];
  FILE *const f = fopen(fn, "rb");
  if (!f) {
    printf("Failed to open %s\n", fn);
    return -2;
  }
  printf("char a[] = {\n");
  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");
  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)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ab <main+0x4b>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f4 <main+0x94>
mov    -0x18(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b2 <main+0x152>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1228 <main+0xc8>
jmp    1294 <main+0x134>
mov    -0x20(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    124b <main+0xeb>
jmp    1294 <main+0x134>
movzbl -0x29(%rbp),%esi
lea    0xde0(%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    128f <main+0x12f>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120a <main+0xaa>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd9a(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
cmp    $0x2,%ebp
sete   %dil
call   1080 <assert@plt>
cmp    $0x2,%ebp
jne    11ee <main+0x6e>
mov    0x8(%rbx),%rbx
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1201 <main+0x81>
mov    %rax,%r14
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1226 <main+0xa6>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1217 <main+0x97>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    1217 <main+0x97>
lea    0xdfb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffffffffffff,%rbp
mov    $0x1,%r13d
lea    0x7(%rsp),%r15
lea    0xdd7(%rip),%r12
jmp    1268 <main+0xe8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <feof@plt>
add    $0xffffffffffffffff,%rbp
add    $0x1,%r13
test   %eax,%eax
jne    11d6 <main+0x56>
mov    %r13,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     11d6 <main+0x56>
shr    $0x3,%rbx
lea    (%rbx,%rbx,4),%rax
lea    0x0(,%rax,2),%rbx
add    %rbp,%rbx
movzbl 0x7(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %rbx,%rbx
jne    1250 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1250 <main+0xd0>

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

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