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


x86 assembly (clang, -O0):
<read_file_to_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    121e <read_file_to_array+0xde>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120b <read_file_to_array+0xcb>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f8 <read_file_to_array+0xb8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%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),%rdx
mov    -0x40(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdx
lea    0xe1d(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <read_file_to_array+0x5a>
jmp    11fd <read_file_to_array+0xbd>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1187 <read_file_to_array+0x47>
jmp    1210 <read_file_to_array+0xd0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1174 <read_file_to_array+0x34>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_to_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %edx,%ebp
mov    %esi,%r13d
mov    %edi,%ebx
lea    0xe9f(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %ebx,%ebx
jle    11ee <read_file_to_array+0xae>
xor    %r12d,%r12d
jmp    1189 <read_file_to_array+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %ebx,%r12d
je     11ee <read_file_to_array+0xae>
test   %r13d,%r13d
jle    1180 <read_file_to_array+0x40>
xor    %r14d,%r14d
jmp    11a9 <read_file_to_array+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
cmp    %r13d,%r14d
je     1180 <read_file_to_array+0x40>
test   %ebp,%ebp
jle    11a0 <read_file_to_array+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    0x10(%rsp),%rcx
lea    (%rax,%rcx,1),%rdx
mov    0x8(%rsp),%rdi
lea    0xe24(%rip),%rsi
call   1050 <fscanf@plt>
add    $0x1,%r15d
cmp    %r15d,%ebp
jne    11b0 <read_file_to_array+0x70>
jmp    11a0 <read_file_to_array+0x60>
mov    0x8(%rsp),%rdi
add    $0x18,%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"r\00"
@.str.1 = [4 x i8] c"%Lf\00"
define void @read_file_to_array(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 = %51, %5
%18 = load i32, i32* %12
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %54
21: ; preds = %17
store i32 0, i32* %13
br label %22
22: ; preds = %47, %21
%23 = load i32, i32* %13
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %50
26: ; preds = %22
store i32 0, i32* %14
br label %27
27: ; preds = %43, %26
%28 = load i32, i32* %14
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
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 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), x86_fp80* %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %14
%45 = add nsw i32 %44, 1
store i32 %45, i32* %14
br label %27
46: ; preds = %27
br label %47
47: ; preds = %46
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %22
50: ; preds = %22
br label %51
51: ; preds = %50
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
br label %17
54: ; preds = %17
%55 = load i32*, i32** %11
%56 = call i32 @fclose(i32* %55)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%Lf\00"
define void @read_file_to_array(i32 %0, i32 %1, i32 %2, i8* nocapture %3, x86_fp80* %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 %28
8: ; preds = %5
%9 = icmp sgt i32 %1, 0
%10 = icmp sgt i32 %2, 0
br label %11
11: ; preds = %8, %25
%12 = phi i32 [ 0, %8 ], [ %26, %25 ]
br i1 %9, label %13, label %25
13: ; preds = %11, %22
%14 = phi i32 [ %23, %22 ], [ 0, %11 ]
br i1 %10, label %15, label %22
15: ; preds = %13, %15
%16 = phi i32 [ %20, %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 = tail call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), x86_fp80* %18)
%20 = add nuw nsw i32 %16, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %15
22: ; preds = %15, %13
%23 = add nuw nsw i32 %14, 1
%24 = icmp eq i32 %23, %1
br i1 %24, label %25, label %13
25: ; preds = %22, %11
%26 = add nuw nsw i32 %12, 1
%27 = icmp eq i32 %26, %0
br i1 %27, label %28, label %11
28: ; preds = %25, %5
%29 = tail call i32 @fclose(i32* %6)
ret void
}