#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 BUFSIZ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/ *, char *);
void convert(char *ifn, char *ofn, char *prefix) {
  FILE *i, *o;
  unsigned char buffer[2048];
  int red, left, lc, q;
  char buf[BUFSIZ];
  i = fopen(ifn, "rb");
  o = fopen(ofn, "w");
  if (!i || !o) {
    printf("error: can't open input or output file\n");
    return;
  }
  fseek(i, 0, SEEK_END);
  left = ftell(i);
  fseek(i, 0, SEEK_SET);
  setbuf(o, buf);
  fprintf(o, "const int %s_size = %d;\n", prefix, left);
  fprintf(o, "const unsigned char %s_data[%d] =", prefix, left);
  fprintf(o, "{\n\t");
  lc = 0;
  while (left > 0) {
    red = fread(buffer, 1, 2048, i);
    left -= red;
    for (q = 0; q < red; q++) {
      fprintf(o, "0x%02x, ", buffer[q]);
      if ((++lc) >= 8) {
        lc = 0;
        fprintf(o, "\n\t");
      }
    }
  }
  fprintf(o, "\n};\n");
  fclose(i);
  fclose(o);
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x848(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x860(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x850(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120a <convert+0x8a>
cmpq   $0x0,-0x28(%rbp)
jne    1225 <convert+0xa5>
lea    0xdf4(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x854(%rbp)
jmp    13be <convert+0x23e>
mov    -0x20(%rbp),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x838(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x860(%rbp),%rsi
mov    -0x28(%rbp),%rdi
call   1050 <setbuf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x838(%rbp),%ecx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x838(%rbp),%ecx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x83c(%rbp)
cmpl   $0x0,-0x838(%rbp)
jle    1390 <convert+0x210>
lea    -0x830(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %eax,-0x834(%rbp)
mov    -0x834(%rbp),%ecx
mov    -0x838(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x838(%rbp)
movl   $0x0,-0x840(%rbp)
mov    -0x840(%rbp),%eax
cmp    -0x834(%rbp),%eax
jge    138b <convert+0x20b>
mov    -0x28(%rbp),%rdi
movslq -0x840(%rbp),%rax
movzbl -0x830(%rbp,%rax,1),%edx
ff
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
cmp    $0x8,%eax
jl     1372 <convert+0x1f2>
movl   $0x0,-0x83c(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1377 <convert+0x1f7>
mov    -0x840(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x840(%rbp)
jmp    130b <convert+0x18b>
jmp    12c0 <convert+0x140>
mov    -0x28(%rbp),%rdi
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x854(%rbp)
mov    -0x848(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rsp,%r14
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe32(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %r15,-0x30(%rbp)
test   %r15,%r15
je     1327 <convert+0x197>
mov    %rax,%rbx
test   %rax,%rax
je     1327 <convert+0x197>
mov    %r14,-0x40(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
mov    %eax,%r15d
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <setbuf@plt>
lea    0xdbc(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdbe(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdc9(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
test   %r15d,%r15d
jle    1335 <convert+0x1a5>
lea    0xdab(%rip),%r13
xor    %r14d,%r14d
jmp    12ad <convert+0x11d>
xchg   %ax,%ax
mov    -0x34(%rbp),%r15d
test   %r15d,%r15d
jle    1335 <convert+0x1a5>
lea    -0x840(%rbp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    -0x30(%rbp),%rcx
call   1040 <fread@plt>
sub    %eax,%r15d
test   %eax,%eax
mov    %r15d,-0x34(%rbp)
jle    12a0 <convert+0x110>
mov    %eax,%r15d
xor    %r12d,%r12d
jmp    12ed <convert+0x15d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14d
add    $0x1,%r12
cmp    %r12,%r15
je     12a0 <convert+0x110>
movzbl -0x840(%rbp,%r12,1),%edx
ff ff
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmp    $0x7,%r14d
jl     12e0 <convert+0x150>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xd27(%rip),%rdi
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
xor    %r14d,%r14d
jmp    12e4 <convert+0x154>
lea    0xd24(%rip),%rdi
call   1030 <puts@plt>
jmp    1363 <convert+0x1d3>
lea    0xd11(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%r14
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [40 x i8] c"error: can't open input or output file\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"const int %s_size = %d;\0A\00"
@.str.4 = [34 x i8] c"const unsigned char %s_data[%d] =\00"
@.str.5 = [4 x i8] c"{\0A\09\00"
@.str.6 = [9 x i8] c"0x%02x, \00"
@.str.7 = [3 x i8] c"\0A\09\00"
@.str.8 = [5 x i8] c"\0A};\0A\00"
define void @convert(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [2048 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %14
%20 = alloca i8, i64 %18
store i64 %18, i64* %15
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i8*, i8** %5
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %8
%25 = load i32*, i32** %7
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %3
%28 = load i32*, i32** %8
%29 = icmp ne i32* %28, null
br i1 %29, label %32, label %30
30: ; preds = %27, %3
%31 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %16
br label %93
32: ; preds = %27
%33 = load i32*, i32** %7
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %7
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %11
%38 = load i32*, i32** %7
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32*, i32** %8
%42 = call i32 @setbuf(i32* %41, i8* %20)
%43 = load i32*, i32** %8
%44 = load i8*, i8** %6
%45 = load i32, i32* %11
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45)
%47 = load i32*, i32** %8
%48 = load i8*, i8** %6
%49 = load i32, i32* %11
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 %49)
%51 = load i32*, i32** %8
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %12
br label %53
53: ; preds = %85, %32
%54 = load i32, i32* %11
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %86
56: ; preds = %53
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%58 = load i32*, i32** %7
%59 = call i32 @fread(i8* %57, i32 1, i32 2048, i32* %58)
store i32 %59, i32* %10
%60 = load i32, i32* %10
%61 = load i32, i32* %11
%62 = sub nsw i32 %61, %60
store i32 %62, i32* %11
store i32 0, i32* %13
br label %63
63: ; preds = %82, %56
%64 = load i32, i32* %13
%65 = load i32, i32* %10
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %85
67: ; preds = %63
%68 = load i32*, i32** %8
%69 = load i32, i32* %13
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
%77 = icmp sge i32 %76, 8
br i1 %77, label %78, label %81
78: ; preds = %67
store i32 0, i32* %12
%79 = load i32*, i32** %8
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %81
81: ; preds = %78, %67
br label %82
82: ; preds = %81
%83 = load i32, i32* %13
%84 = add nsw i32 %83, 1
store i32 %84, i32* %13
br label %63
85: ; preds = %63
br label %53
86: ; preds = %53
%87 = load i32*, i32** %8
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%89 = load i32*, i32** %7
%90 = call i32 @fclose(i32* %89)
%91 = load i32*, i32** %8
%92 = call i32 @fclose(i32* %91)
store i32 0, i32* %16
br label %93
93: ; preds = %86, %30
%94 = load i8*, i8** %14
%95 = load i32, i32* %16
switch i32 %95, label %97 [
i32 0, label %96
i32 1, label %96
]
96: ; preds = %93, %93
ret void
97: ; preds = %93
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"const int %s_size = %d;\0A\00"
@.str.4 = [34 x i8] c"const unsigned char %s_data[%d] =\00"
@.str.5 = [4 x i8] c"{\0A\09\00"
@.str.6 = [9 x i8] c"0x%02x, \00"
@.str.7 = [3 x i8] c"\0A\09\00"
@.str.8 = [5 x i8] c"\0A};\0A\00"
@str = [39 x i8] c"error: can't open input or output file\00"
define void @convert(i8* nocapture %0, i8* nocapture %1, i8* %2) {
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32* %10, null
%13 = icmp ne i32* %11, null
%14 = and i1 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %58
17: ; preds = %3
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %10, i32 0, i32 %18)
%20 = tail call i32 @ftell(i32* %10)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %10, i32 0, i32 %21)
%23 = call i32 @setbuf(i32* %11, i8* %9)
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %20)
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %20)
%26 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 3, i64 1, i32* %11)
%27 = icmp sgt i32 %20, 0
br i1 %27, label %31, label %54
28: ; preds = %50, %31
%29 = phi i32 [ %33, %31 ], [ %51, %50 ]
%30 = icmp sgt i32 %35, 0
br i1 %30, label %31, label %54
31: ; preds = %17, %28
%32 = phi i32 [ %35, %28 ], [ %20, %17 ]
%33 = phi i32 [ %29, %28 ], [ 0, %17 ]
%34 = call i32 @fread(i8* %5, i32 1, i32 2048, i32* %10)
%35 = sub nsw i32 %32, %34
%36 = icmp sgt i32 %34, 0
br i1 %36, label %37, label %28
37: ; preds = %31
%38 = zext i32 %34 to i64
br label %39
39: ; preds = %37, %50
%40 = phi i64 [ 0, %37 ], [ %52, %50 ]
%41 = phi i32 [ %33, %37 ], [ %51, %50 ]
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %40
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = add nsw i32 %41, 1
%47 = icmp sgt i32 %41, 6
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %11)
br label %50
50: ; preds = %39, %48
%51 = phi i32 [ 0, %48 ], [ %46, %39 ]
%52 = add nuw nsw i64 %40, 1
%53 = icmp eq i64 %52, %38
br i1 %53, label %28, label %39
54: ; preds = %28, %17
%55 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64 4, i64 1, i32* %11)
%56 = call i32 @fclose(i32* %10)
%57 = call i32 @fclose(i32* %11)
br label %58
58: ; preds = %54, %15
ret void
}