#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_NoError(char *, void **, unsigned int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc < 2)
    return 1;
  unsigned char *d;
  unsigned int s;
  FileLoad_NoError(argv[1], (void **)&d, &s);
  if (s > 0) {
    int l = (s & 0x1FFF) + 4;
    FILE *f = fopen("out.bin", "wb");
    if (f) {
      int i;
      for (i = 0; i < l; i++) {
        unsigned char x, y, z, w;
        x = d[i + 0x0000];
        y = d[i + 0x2000];
        z = d[i + 0x4000];
        w = d[i + 0x6000];
        fwrite(&x, 1, 1, f);
        fwrite(&y, 1, 1, f);
        fwrite(&z, 1, 1, f);
        fwrite(&w, 1, 1, f);
      }
      fclose(f);
    }
    free(d);
  }
  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   $0x1,-0x4(%rbp)
jmp    12aa <main+0x15a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <FileLoad_NoError@plt>
cmpl   $0x0,-0x1c(%rbp)
jbe    12a3 <main+0x153>
mov    -0x1c(%rbp),%eax
and    $0x1fff,%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     129a <main+0x14a>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1291 <main+0x141>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2d(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2000,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2e(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x4000,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2f(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x6000,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x2d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rcx
lea    -0x2e(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rcx
lea    -0x2f(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d2 <main+0x82>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1236 <main+0xe6>
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_NoError@plt>
mov    0xc(%rsp),%r12d
test   %r12,%r12
je     1226 <main+0xd6>
lea    0xe6c(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121c <main+0xcc>
mov    %rax,%r13
and    $0x1fff,%r12d
add    $0x4,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%rax
movsbl (%rax,%rbx,1),%edi
movsbl 0x2000(%rax,%rbx,1),%ebp
movsbl 0x4000(%rax,%rbx,1),%r14d
movsbl 0x6000(%rax,%rbx,1),%r15d
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %ebp,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %r14d,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %r15d,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <main+0x70>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"out.bin\00"
@.str.1 = [3 x i8] c"wb\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 %51, 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_NoError(i8* %10, i8** %3, i32* %4)
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %50, label %14
14: ; preds = %6
%15 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %47, label %17
17: ; preds = %14
%18 = and i32 %12, 8191
%19 = add nuw nsw i32 %18, 4
%20 = zext i32 %19 to i64
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %43, %21 ]
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 %22
%25 = load i8, i8* %24
%26 = add nuw nsw i64 %22, 8192
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = add nuw nsw i64 %22, 16384
%30 = getelementptr inbounds i8, i8* %23, i64 %29
%31 = load i8, i8* %30
%32 = add nuw nsw i64 %22, 24576
%33 = getelementptr inbounds i8, i8* %23, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %25 to i32
%36 = call i32 @fputc(i32 %35, i32* %15)
%37 = sext i8 %28 to i32
%38 = call i32 @fputc(i32 %37, i32* %15)
%39 = sext i8 %31 to i32
%40 = call i32 @fputc(i32 %39, i32* %15)
%41 = sext i8 %34 to i32
%42 = call i32 @fputc(i32 %41, i32* %15)
%43 = add nuw nsw i64 %22, 1
%44 = icmp eq i64 %43, %20
br i1 %44, label %45, label %21
45: ; preds = %21
%46 = call i32 @fclose(i32* %15)
br label %47
47: ; preds = %45, %14
%48 = load i8*, i8** %3
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %47, %6
br label %51
51: ; preds = %2, %50
%52 = phi i32 [ 0, %50 ], [ 1, %2 ]
ret i32 %52
}