#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 int *);
int main(int argc, char **argv) {
  if (argc < 2)
    return 0;
  unsigned int *file, 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%08X,", file[i++]);
    if ((i % 5) == 0)
      fprintf(f, "\n");
    size -= 4;
  }
  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    1244 <main+0xf4>
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    1244 <main+0xf4>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    1234 <main+0xe4>
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
mov    (%rax,%rcx,4),%edx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1226 <main+0xd6>
mov    -0x28(%rbp),%rdi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
sub    $0x4,%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     1247 <main+0xe7>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <FileLoad@plt>
lea    0xe6d(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     122a <main+0xca>
mov    %rax,%r15
cmpl   $0x0,0xc(%rsp)
je     121e <main+0xbe>
mov    $0xffffffff,%r13d
mov    $0x1,%ebx
lea    0xe44(%rip),%r14
xor    %ebp,%ebp
jmp    11e2 <main+0x82>
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbp
add    $0xffffffff,%r13d
add    $0x1,%ebx
addl   $0xfffffffc,0xc(%rsp)
je     121e <main+0xbe>
mov    %ebx,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%r12d
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    %r13d,%r12d
jne    11d0 <main+0x70>
mov    $0xa,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
jmp    11d0 <main+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1239 <main+0xd9>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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%08X,\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 i32*
%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 = bitcast i32** %6 to i8**
%18 = call i32 @FileLoad(i8* %16, i8** %17, i32* %7)
%19 = 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* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32*, i32** %6
%24 = call i32 @free(i32* %23)
store i32 1, i32* %3
br label %50
25: ; preds = %13
store i32 0, i32* %9
br label %26
26: ; preds = %44, %25
%27 = load i32, i32* %7
%28 = icmp ugt i32 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %26
%30 = load i32*, i32** %8
%31 = load i32*, i32** %6
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i32, i32* %31, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, 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, 5
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %29
%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, %29
%45 = load i32, i32* %7
%46 = sub i32 %45, 4
store i32 %46, i32* %7
br label %26
47: ; preds = %26
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %47, %22, %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%08X,\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = icmp slt i32 %0, 2
br i1 %5, label %41, label %6
6: ; preds = %2
%7 = bitcast i32** %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = bitcast i32** %3 to i8**
%12 = call i32 @FileLoad(i8* %10, i8** %11, i32* %4)
%13 = 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))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %6
%16 = load i32*, i32** %3
%17 = call i32 @free(i32* %16)
br label %39
18: ; preds = %6
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %18, %33
%22 = phi i64 [ %24, %33 ], [ 0, %18 ]
%23 = load i32*, i32** %3
%24 = add nuw i64 %22, 1
%25 = getelementptr inbounds i32, i32* %23, i64 %22
%26 = load i32, i32* %25
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = trunc i64 %24 to i32
%29 = urem i32 %28, 5
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @fputc(i32 10, i32* %13)
br label %33
33: ; preds = %31, %21
%34 = load i32, i32* %4
%35 = add i32 %34, -4
store i32 %35, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %21
37: ; preds = %33, %18
%38 = call i32 @fclose(i32* %13)
br label %39
39: ; preds = %37, %15
%40 = phi i32 [ 1, %15 ], [ 0, %37 ]
br label %41
41: ; preds = %2, %39
%42 = phi i32 [ %40, %39 ], [ 0, %2 ]
ret i32 %42
}