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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *in;
  FILE *out;
  char buff[256];
  int len;
  int i;
  if (argc < 3) {
    fprintf(stderr, "usage: %s {out} {in}\n", argv[0]);
    return 1;
  }
  in = fopen(argv[1], "r");
  if (!in)
    return 1;
  snprintf(buff, sizeof(buff), "%s.c", argv[2]);
  out = fopen(buff, "w");
  if (!out)
    return 1;
  fprintf(out, "const char %s[] = {\n", argv[2]);
  for (;;) {
    len = fread(buff, 1, sizeof(buff), in);
    for (i = 0; i < len; ++i) {
      fprintf(out, "0x%02x, ", buff[i]);
    }
    if (len <= 0)
      break;
  }
  fprintf(out, "};\n");
  fclose(out);
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119e <main+0x4e>
mov    0x2e66(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cd <main+0x7d>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <main+0x198>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x100,%esi
lea    0xe30(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <main+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <main+0x198>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %eax,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x124(%rbp),%eax
jge    12a6 <main+0x156>
mov    -0x20(%rbp),%rdi
movslq -0x128(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%edx
ff
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    125f <main+0x10f>
cmpl   $0x0,-0x124(%rbp)
jg     12b8 <main+0x168>
jmp    12bd <main+0x16d>
jmp    1235 <main+0xe5>
mov    -0x20(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
jg     119e <main+0x3e>
mov    0x2e60(%rip),%rax
movslq (%rax),%rdi
mov    (%r15),%rdx
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    129b <main+0x13b>
mov    0x8(%r15),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%r14
mov    0x10(%r15),%rcx
lea    0xe4e(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
lea    0xe3c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%rbx
mov    0x10(%r15),%rdx
lea    0xe1f(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe23(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1270 <main+0x110>
mov    %eax,%r13d
mov    %eax,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%r15,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1250 <main+0xf0>
test   %r13d,%r13d
jg     1220 <main+0xc0>
lea    0xdc6(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s {out} {in}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.5 = [9 x i8] c"0x%02x, \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 i32*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %77
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %29, label %28
28: ; preds = %21
store i32 1, i32* %3
br label %77
29: ; preds = %21
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @snprintf(i8* %30, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %40, label %39
39: ; preds = %29
store i32 1, i32* %3
br label %77
40: ; preds = %29
%41 = load i32*, i32** %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %69, %40
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%48 = load i32*, i32** %6
%49 = call i32 @fread(i8* %47, i32 1, i32 256, i32* %48)
store i32 %49, i32* %9
store i32 0, i32* %10
br label %50
50: ; preds = %62, %46
%51 = load i32, i32* %10
%52 = load i32, i32* %9
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = load i32*, i32** %7
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %54
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %50
65: ; preds = %50
%66 = load i32, i32* %9
%67 = icmp sle i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %65
br label %70
69: ; preds = %65
br label %46
70: ; preds = %68
%71 = load i32*, i32** %7
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32*, i32** %7
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %6
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %70, %39, %28, %13
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"usage: %s {out} {in}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s.c\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"const char %s[] = {\0A\00"
@.str.5 = [9 x i8] c"0x%02x, \00"
@.str.6 = [4 x i8] c"};\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = load i8*, i8** %1
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %45
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %45, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %45, label %23
23: ; preds = %17
%24 = load i8*, i8** %18
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %39, %23
%27 = call i32 @fread(i8* %4, i32 1, i32 256, i32* %15)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = zext i32 %27 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %37, %31 ]
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %32, 1
%38 = icmp eq i64 %37, %30
br i1 %38, label %39, label %31
39: ; preds = %31
%40 = icmp slt i32 %27, 1
br i1 %40, label %41, label %26
41: ; preds = %26, %39
%42 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %21)
%43 = call i32 @fclose(i32* %21)
%44 = call i32 @fclose(i32* %15)
br label %45
45: ; preds = %17, %12, %41, %6
%46 = phi i32 [ 1, %6 ], [ 0, %41 ], [ 1, %12 ], [ 1, %17 ]
ret i32 %46
}