#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*/ FileLoad(char *, void **, unsigned int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int main(int argc, char **argv) {
  if (argc < 2)
    return 0;
  unsigned char *file;
  unsigned int size;
  FileLoad(argv[1], (void **)&file, &size);
  FILE *f = fopen("out.c", "w");
  if (f == NULL) {
    free(file);
    return 1;
  }
  int i = 0;
  while (size > 0) {
    fprintf(f, "0x%02X,", file[i++]);
    if ((i % 16) == 0)
      fprintf(f, "\n");
    size--;
  }
  fclose(f);
  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)
jge    117c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1245 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <FileLoad@plt>
lea    0xe68(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <main+0x78>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1245 <main+0xf5>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    1235 <main+0xe5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1227 <main+0xd7>
mov    -0x28(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <main+0x7f>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
xor    %eax,%eax
cmp    $0x2,%edi
jl     121a <main+0xba>
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1040 <FileLoad@plt>
lea    0xe72(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1202 <main+0xa2>
mov    %rax,%r15
cmpl   $0x0,0x4(%rsp)
je     11f6 <main+0x96>
mov    $0x1,%ebx
lea    0xe53(%rip),%r14
jmp    11cb <main+0x6b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
addl   $0xffffffff,0x4(%rsp)
je     11f6 <main+0x96>
mov    0x8(%rsp),%rax
movzbl -0x1(%rax,%rbx,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
test   $0xf,%bl
jne    11c0 <main+0x60>
mov    $0xa,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
jmp    11c0 <main+0x60>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1211 <main+0xb1>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"out.c\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"0x%02X,\00"
@.str.3 = [2 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 i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %50
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @FileLoad(i8* %16, i8** %6, i32* %7)
%18 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
store i32 1, i32* %3
br label %50
24: ; preds = %13
store i32 0, i32* %9
br label %25
25: ; preds = %44, %24
%26 = load i32, i32* %7
%27 = icmp ugt i32 %26, 0
br i1 %27, label %28, label %47
28: ; preds = %25
%29 = load i32*, i32** %8
%30 = load i8*, i8** %6
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %9
%39 = srem i32 %38, 16
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %28
%42 = load i32*, i32** %8
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %41, %28
%45 = load i32, i32* %7
%46 = add i32 %45, -1
store i32 %46, i32* %7
br label %25
47: ; preds = %25
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %47, %21, %12
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [6 x i8] c"out.c\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"0x%02X,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = icmp slt i32 %0, 2
br i1 %5, label %40, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @FileLoad(i8* %10, i8** %3, i32* %4)
%12 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = call i32 @free(i8* %15)
br label %38
17: ; preds = %6
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %17, %32
%21 = phi i64 [ %23, %32 ], [ 0, %17 ]
%22 = load i8*, i8** %3
%23 = add nuw i64 %21, 1
%24 = getelementptr inbounds i8, i8* %22, i64 %21
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = and i64 %23, 15
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @fputc(i32 10, i32* %12)
br label %32
32: ; preds = %30, %20
%33 = load i32, i32* %4
%34 = add i32 %33, -1
store i32 %34, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %20
36: ; preds = %32, %17
%37 = call i32 @fclose(i32* %12)
br label %38
38: ; preds = %36, %14
%39 = phi i32 [ 1, %14 ], [ 0, %36 ]
br label %40
40: ; preds = %2, %38
%41 = phi i32 [ %39, %38 ], [ 0, %2 ]
ret i32 %41
}