#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long double);
size_t indices(int, int, int, int, int, int);
void write_array_to_file(int x, int y, int z, char filename[],
                         long double *imageArray) {
  FILE *imagefile;
  int i, j, k;
  imagefile = fopen(filename, "w");
  for (i = 0; i < x; i++) {
    for (j = 0; j < y; j++) {
      for (k = 0; k < z; k++) {
        fprintf(imagefile, "%.18Lf\n", imageArray[indices(x, y, z, i, j, k)]);
      }
    }
  }
  fclose(imagefile);
}


x86 assembly (clang, -O0):
<write_array_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1226 <write_array_to_file+0xe6>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1213 <write_array_to_file+0xd3>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1200 <write_array_to_file+0xc0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x34(%rbp),%r9d
call   1030 <indices@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
shl    $0x4,%rcx
fldt   (%rax,%rcx,1)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <write_array_to_file+0x5a>
jmp    1205 <write_array_to_file+0xc5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1187 <write_array_to_file+0x47>
jmp    1218 <write_array_to_file+0xd8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1174 <write_array_to_file+0x34>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_array_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %edx,%ebp
mov    %esi,%r13d
mov    %edi,%ebx
lea    0xe9f(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %ebx,%ebx
jle    11f0 <write_array_to_file+0xb0>
xor    %r12d,%r12d
jmp    1189 <write_array_to_file+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %ebx,%r12d
je     11f0 <write_array_to_file+0xb0>
test   %r13d,%r13d
jle    1180 <write_array_to_file+0x40>
xor    %r14d,%r14d
jmp    11a9 <write_array_to_file+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
cmp    %r13d,%r14d
je     1180 <write_array_to_file+0x40>
test   %ebp,%ebp
jle    11a0 <write_array_to_file+0x60>
xor    %r15d,%r15d
mov    %ebx,%edi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %r15d,%r9d
call   1030 <indices@plt>
shl    $0x4,%rax
mov    0x20(%rsp),%rcx
fldt   (%rcx,%rax,1)
fstpt  (%rsp)
mov    0x18(%rsp),%rdi
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%r15d
cmp    %r15d,%ebp
jne    11b0 <write_array_to_file+0x70>
jmp    11a0 <write_array_to_file+0x60>
mov    0x18(%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [8 x i8] c"%.18Lf\0A\00"
define void @write_array_to_file(i32 %0, i32 %1, i32 %2, i8* %3, x86_fp80* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca x86_fp80*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store x86_fp80* %4, x86_fp80** %10
%15 = load i8*, i8** %9
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
store i32 0, i32* %12
br label %17
17: ; preds = %52, %5
%18 = load i32, i32* %12
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %55
21: ; preds = %17
store i32 0, i32* %13
br label %22
22: ; preds = %48, %21
%23 = load i32, i32* %13
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %51
26: ; preds = %22
store i32 0, i32* %14
br label %27
27: ; preds = %44, %26
%28 = load i32, i32* %14
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = load i32*, i32** %11
%33 = load x86_fp80*, x86_fp80** %10
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %12
%38 = load i32, i32* %13
%39 = load i32, i32* %14
%40 = call i64 @indices(i32 %34, i32 %35, i32 %36, i32 %37, i32 %38, i32 %39)
%41 = getelementptr inbounds x86_fp80, x86_fp80* %33, i64 %40
%42 = load x86_fp80, x86_fp80* %41
%43 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %42)
br label %44
44: ; preds = %31
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
store i32 %46, i32* %14
br label %27
47: ; preds = %27
br label %48
48: ; preds = %47
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
store i32 %50, i32* %13
br label %22
51: ; preds = %22
br label %52
52: ; preds = %51
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
br label %17
55: ; preds = %17
%56 = load i32*, i32** %11
%57 = call i32 @fclose(i32* %56)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [8 x i8] c"%.18Lf\0A\00"
define void @write_array_to_file(i32 %0, i32 %1, i32 %2, i8* nocapture %3, x86_fp80* nocapture %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = icmp sgt i32 %1, 0
%10 = icmp sgt i32 %2, 0
br label %11
11: ; preds = %8, %26
%12 = phi i32 [ 0, %8 ], [ %27, %26 ]
br i1 %9, label %13, label %26
13: ; preds = %11, %23
%14 = phi i32 [ %24, %23 ], [ 0, %11 ]
br i1 %10, label %15, label %23
15: ; preds = %13, %15
%16 = phi i32 [ %21, %15 ], [ 0, %13 ]
%17 = tail call i64 @indices(i32 %0, i32 %1, i32 %2, i32 %12, i32 %14, i32 %16)
%18 = getelementptr inbounds x86_fp80, x86_fp80* %4, i64 %17
%19 = load x86_fp80, x86_fp80* %18
%20 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %19)
%21 = add nuw nsw i32 %16, 1
%22 = icmp eq i32 %21, %2
br i1 %22, label %23, label %15
23: ; preds = %15, %13
%24 = add nuw nsw i32 %14, 1
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %13
26: ; preds = %23, %11
%27 = add nuw nsw i32 %12, 1
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %11
29: ; preds = %26, %5
%30 = tail call i32 @fclose(i32* %6)
ret void
}