#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(unsigned char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *fname_in;
  char *fname_out;
  FILE *fp_in;
  FILE *fp_out;
  const int BUFSIZE = 0xFFFF;
  unsigned char buf[BUFSIZE];
  size_t size;
  int i;
  if (argc != 3) {
    printf("Usage: %s input.dat output.c\n", argv[0]);
    return 1;
  }
  fname_in = argv[1];
  fname_out = argv[2];
  fp_in = fopen(fname_in, "r");
  fp_out = fopen(fname_out, "w");
  fprintf(fp_out, "unsigned char resource_data[] = {\n");
  while (size = fread(buf, 1, BUFSIZE, fp_in)) {
    for (i = 0; i < size; ++i) {
      int last = feof(fp_in) && i == size - 1;
      fprintf(fp_out, "    0x%x%s\n", buf[i], last ? "" : ",");
    }
  }
  fprintf(fp_out, "};\n");
  fclose(fp_in);
  fclose(fp_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffff,-0x34(%rbp)
mov    %rsp,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b7 <main+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1305 <main+0x1a5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rcx
lea    -0x10060(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
call   1030 <fread@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     12d3 <main+0x173>
movl   $0x0,-0x4c(%rbp)
movslq -0x4c(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    12ce <main+0x16e>
mov    -0x28(%rbp),%rdi
call   1070 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x10061(%rbp)
je     127c <main+0x11c>
movslq -0x4c(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
sete   %al
mov    %al,-0x10061(%rbp)
mov    -0x10061(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x4c(%rbp),%rax
movzbl -0x10060(%rbp,%rax,1),%edx
ff
mov    -0x54(%rbp),%esi
lea    0xdad(%rip),%rcx
lea    0xdab(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1238 <main+0xd8>
jmp    1209 <main+0xa9>
mov    -0x30(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x10070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
cmp    $0x3,%edi
jne    12a1 <main+0x131>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
lea    0xe6b(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %rax,0x8(%rsp)
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     126f <main+0xff>
mov    %rax,%rbx
lea    0xe59(%rip),%r13
mov    0x8(%rsp),%r14
nopl   (%rax)
lea    -0x1(%rbx),%rbp
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <feof@plt>
cmp    %r15,%rbp
mov    %r13,%rcx
lea    0xe31(%rip),%rdx
cmove  %rdx,%rcx
test   %rax,%rax
movzbl 0x10(%rsp,%r15,1),%edx
cmove  %r13,%rcx
mov    %r14,%rdi
lea    0xe05(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbx
jne    1210 <main+0xa0>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <main+0x90>
lea    0xddd(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rbx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12b5 <main+0x145>
mov    (%rsi),%rsi
lea    0xd55(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: %s input.dat output.c\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"unsigned char resource_data[] = {\0A\00"
@.str.4 = [12 x i8] c" 0x%x%s\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [2 x i8] c",\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 i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 65535, i32* %10
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = alloca i8, i64 65535
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
store i32 1, i32* %14
br label %83
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %7
%32 = load i8*, i8** %6
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %8
%34 = load i8*, i8** %7
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %9
%36 = load i32*, i32** %9
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %75, %25
%39 = load i32*, i32** %8
%40 = call i64 @fread(i8* %17, i32 1, i32 65535, i32* %39)
store i64 %40, i64* %12
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %76
42: ; preds = %38
store i32 0, i32* %13
br label %43
43: ; preds = %72, %42
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = load i64, i64* %12
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %75
48: ; preds = %43
%49 = load i32*, i32** %8
%50 = call i64 @feof(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = load i64, i64* %12
%56 = sub i64 %55, 1
%57 = icmp eq i64 %54, %56
br label %58
58: ; preds = %52, %48
%59 = phi i1 [ false, %48 ], [ %57, %52 ]
%60 = zext i1 %59 to i32
store i32 %60, i32* %15
%61 = load i32*, i32** %9
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %17, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i32, i32* %15
%68 = icmp ne i32 %67, 0
%69 = zext i1 %68 to i64
%70 = select i1 %68, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %66, i8* %70)
br label %72
72: ; preds = %58
%73 = load i32, i32* %13
%74 = add nsw i32 %73, 1
store i32 %74, i32* %13
br label %43
75: ; preds = %43
br label %38
76: ; preds = %38
%77 = load i32*, i32** %9
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%79 = load i32*, i32** %8
%80 = call i32 @fclose(i32* %79)
%81 = load i32*, i32** %9
%82 = call i32 @fclose(i32* %81)
store i32 0, i32* %3
store i32 1, i32* %14
br label %83
83: ; preds = %76, %20
%84 = load i8*, i8** %11
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [30 x i8] c"Usage: %s input.dat output.c\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"unsigned char resource_data[] = {\0A\00"
@.str.4 = [12 x i8] c" 0x%x%s\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [2 x i8] c",\00"
@.str.7 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65535 x i8]
%4 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %42
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 34, i64 1, i32* %15)
%17 = call i64 @fread(i8* %4, i32 1, i32 65535, i32* %14)
%18 = icmp eq i64 %17, 0
br i1 %18, label %38, label %22
19: ; preds = %25
%20 = call i64 @fread(i8* %4, i32 1, i32 65535, i32* %14)
%21 = icmp eq i64 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %9, %19
%23 = phi i64 [ %20, %19 ], [ %17, %9 ]
%24 = add i64 %23, -1
br label %25
25: ; preds = %22, %25
%26 = phi i64 [ 0, %22 ], [ %36, %25 ]
%27 = tail call i64 @feof(i32* %14)
%28 = icmp ne i64 %27, 0
%29 = icmp eq i64 %24, %26
%30 = select i1 %28, i1 %29, i1 false
%31 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 %26
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = select i1 %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %33, i8* %34)
%36 = add nuw i64 %26, 1
%37 = icmp eq i64 %36, %23
br i1 %37, label %19, label %25
38: ; preds = %19, %9
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 3, i64 1, i32* %15)
%40 = tail call i32 @fclose(i32* %14)
%41 = tail call i32 @fclose(i32* %15)
br label %42
42: ; preds = %38, %6
%43 = phi i32 [ 1, %6 ], [ 0, %38 ]
ret i32 %43
}