#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*/ uint8_t;
typedef scalar_t__ time_t;
typedef int int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ makeRandomSubCube(int /*<<< orphan*/ *, int, int, int, int,
                                     int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ time(scalar_t__ *);
int main(int argc, char **argv) {
  FILE *cube = NULL;
  uint8_t cubeBuffer[128 * 128 * 128 * 3];
  int32_t i = 0, x, y, z;
  time_t seconds;
  memset(cubeBuffer, '\0', 128 * 128 * 128 * 3);
  for (i = 0; i < 200; i++) {
    time(&seconds);
    srand((unsigned int)seconds + i);
    x = rand() % 129;
    y = rand() % 129;
    z = rand() % 129;
    printf("Generating sub cube %d at (%d, %d, %d)\n", i, x, y, z);
    makeRandomSubCube(cubeBuffer, 128, 32, x, y, z);
  }
  cube = fopen(argv[1], "w+b");
  if (cube == NULL) {
    printf("Unable to open overlay cube file at %s\n", argv[1]);
    return 0;
  }
  if (fwrite(cubeBuffer, 1, 128 * 128 * 128 * 3, cube) != 128 * 128 * 128 * 3) {
    printf("Unable to write cube file.\n");
    if (fclose(cube) != 0)
      printf("Additionally, an error occured closing the file.\n");
    return 0;
  }
  if (fclose(cube) != 0)
    printf("Error closing the RGBA file\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1800040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1800024(%rbp)
lea    -0x1800020(%rbp),%rdi
xor    %esi,%esi
mov    $0x600000,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1800024(%rbp)
cmpl   $0xc8,-0x1800024(%rbp)
jge    12ac <main+0x11c>
lea    -0x1800038(%rbp),%rdi
call   1070 <time@plt>
mov    -0x1800038(%rbp),%rax
mov    %eax,%edi
add    -0x1800024(%rbp),%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x81,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1800028(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x81,%ecx
cltd
idiv   %ecx
mov    %edx,-0x180002c(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x81,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1800030(%rbp)
mov    -0x1800024(%rbp),%esi
mov    -0x1800028(%rbp),%edx
mov    -0x180002c(%rbp),%ecx
mov    -0x1800030(%rbp),%r8d
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1800020(%rbp),%rdi
mov    -0x1800028(%rbp),%ecx
mov    -0x180002c(%rbp),%r8d
mov    -0x1800030(%rbp),%r9d
mov    $0x80,%esi
mov    $0x20,%edx
call   10a0 <makeRandomSubCube@plt>
mov    -0x1800024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1800024(%rbp)
jmp    11d8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f1 <main+0x161>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1379 <main+0x1e9>
lea    -0x1800020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x600000,%edx
call   1090 <fwrite@plt>
cmp    $0x600000,%eax
je     1351 <main+0x1c1>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1345 <main+0x1b5>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1379 <main+0x1e9>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1372 <main+0x1e2>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1800040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1800018,%rsp
mov    %rsi,(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x600000,%edx
call   1060 <memset@plt>
lea    0x8(%rsp),%r12
lea    0xe2e(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1080 <time@plt>
mov    0x8(%rsp),%edi
add    %ebp,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%rbx
imul   $0xfe03f81,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
add    %eax,%ecx
sub    %ecx,%ebx
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%r14
imul   $0xfe03f81,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
add    %eax,%ecx
sub    %ecx,%r14d
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%r15
imul   $0xfe03f81,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
add    %eax,%ecx
sub    %ecx,%r15d
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    $0x20,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
mov    %r15d,%r9d
call   10b0 <makeRandomSubCube@plt>
add    $0x1,%ebp
cmp    $0xc8,%ebp
jne    11e0 <main+0x40>
mov    (%rsp),%rbx
mov    0x8(%rbx),%rdi
lea    0xd70(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12fe <main+0x15e>
mov    %rax,%rbp
lea    0x10(%rsp),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x600000,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
cmp    $0x600000,%eax
jne    1314 <main+0x174>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     133b <main+0x19b>
lea    0xd58(%rip),%rdi
jmp    1336 <main+0x196>
mov    0x8(%rbx),%rsi
lea    0xd23(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    133b <main+0x19b>
lea    0xd55(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     133b <main+0x19b>
lea    0xd55(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x1800018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Generating sub cube %d at (%d, %d, %d)\0A\00"
@.str.1 = [4 x i8] c"w+b\00"
@.str.2 = [40 x i8] c"Unable to open overlay cube file at %s\0A\00"
@.str.3 = [28 x i8] c"Unable to write cube file.\0A\00"
@.str.4 = [50 x i8] c"Additionally, an error occured closing the file.\0A\00"
@.str.5 = [29 x i8] c"Error closing the RGBA file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [6291456 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %8
%13 = getelementptr inbounds [6291456 x i32], [6291456 x i32]* %7, i64 0, i64 0
%14 = call i32 @memset(i32* %13, i8 signext 0, i32 6291456)
store i32 0, i32* %8
br label %15
15: ; preds = %41, %2
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 200
br i1 %17, label %18, label %44
18: ; preds = %15
%19 = call i32 @time(i64* %12)
%20 = load i64, i64* %12
%21 = trunc i64 %20 to i32
%22 = load i32, i32* %8
%23 = add i32 %21, %22
%24 = call i32 @srand(i32 %23)
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 129
store i32 %26, i32* %9
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 129
store i32 %28, i32* %10
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 129
store i32 %30, i32* %11
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = load i32, i32* %11
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32, i32 %33, i32 %34)
%36 = getelementptr inbounds [6291456 x i32], [6291456 x i32]* %7, i64 0, i64 0
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = call i32 @makeRandomSubCube(i32* %36, i32 128, i32 32, i32 %37, i32 %38, i32 %39)
br label %41
41: ; preds = %18
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %15
44: ; preds = %15
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %48, i32** %6
%49 = load i32*, i32** %6
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %56
51: ; preds = %44
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %54)
store i32 0, i32* %3
br label %76
56: ; preds = %44
%57 = getelementptr inbounds [6291456 x i32], [6291456 x i32]* %7, i64 0, i64 0
%58 = load i32*, i32** %6
%59 = call i32 @fwrite(i32* %57, i32 1, i32 6291456, i32* %58)
%60 = icmp ne i32 %59, 6291456
br i1 %60, label %61, label %69
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32*, i32** %6
%64 = call i64 @fclose(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %61
store i32 0, i32* %3
br label %76
69: ; preds = %56
%70 = load i32*, i32** %6
%71 = call i64 @fclose(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %73, %69
store i32 1, i32* %3
br label %76
76: ; preds = %75, %68, %51
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [40 x i8] c"Generating sub cube %d at (%d, %d, %d)\0A\00"
@.str.1 = [4 x i8] c"w+b\00"
@.str.2 = [40 x i8] c"Unable to open overlay cube file at %s\0A\00"
@str = [28 x i8] c"Error closing the RGBA file\00"
@str.6 = [27 x i8] c"Unable to write cube file.\00"
@str.7 = [49 x i8] c"Additionally, an error occured closing the file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6291456 x i32]
%4 = alloca i64
%5 = bitcast [6291456 x i32]* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = getelementptr inbounds [6291456 x i32], [6291456 x i32]* %3, i64 0, i64 0
%8 = call i32 @memset(i32* %7, i8 signext 0, i32 6291456)
br label %9
9: ; preds = %2, %9
%10 = phi i32 [ 0, %2 ], [ %24, %9 ]
%11 = call i32 @time(i64* %4)
%12 = load i64, i64* %4
%13 = trunc i64 %12 to i32
%14 = add i32 %10, %13
%15 = call i32 @srand(i32 %14)
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 129
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 129
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 129
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %17, i32 %19, i32 %21)
%23 = call i32 @makeRandomSubCube(i32* %7, i32 128, i32 32, i32 %17, i32 %19, i32 %21)
%24 = add nuw nsw i32 %10, 1
%25 = icmp eq i32 %24, 200
br i1 %25, label %26, label %9
26: ; preds = %9
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %27
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %48
34: ; preds = %26
%35 = call i32 @fwrite(i32* %7, i32 1, i32 6291456, i32* %29)
%36 = icmp eq i32 %35, 6291456
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%39 = call i64 @fclose(i32* %29)
%40 = icmp eq i64 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %37
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.7, i64 0, i64 0))
br label %48
43: ; preds = %34
%44 = call i64 @fclose(i32* %29)
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %43, %46, %37, %41, %31
%49 = phi i32 [ 0, %31 ], [ 0, %41 ], [ 0, %37 ], [ 1, %46 ], [ 1, %43 ]
ret i32 %49
}