#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*/ fread(double *, int, int, int /*<<< orphan*/ *);
void read_subsample(double *q, int nx, int ny, int nz, FILE *file) {
  int i, j, k;
  for (k = 0; k < nz; k++) {
    for (j = 0; j < ny; j++) {
      fread(q + i + j * nx + k * nx * ny, sizeof(double), 1, file);
    }
  }
}


x86 assembly (clang, -O0):
<read_subsample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b6 <read_subsample+0xa6>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a3 <read_subsample+0x93>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x2c(%rbp),%eax
imul   -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1143 <read_subsample+0x33>
jmp    11a8 <read_subsample+0x98>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1130 <read_subsample+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_subsample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0x8(%rsp)
mov    %rdi,0x18(%rsp)
test   %ecx,%ecx
jle    11b0 <read_subsample+0xa0>
mov    %r8,%r13
mov    0x8(%rsp),%eax
mov    %eax,%edx
imul   %esi,%edx
mov    %edx,0xc(%rsp)
movslq %esi,%rbx
mov    %ecx,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%eax
mov    %rax,0x10(%rsp)
shl    $0x3,%rbx
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1170 <read_subsample+0x60>
nopl   0x0(%rax)
add    $0x1,%r14
add    0xc(%rsp),%r15d
cmp    0x20(%rsp),%r14
je     11b0 <read_subsample+0xa0>
cmpl   $0x0,0x8(%rsp)
jle    1160 <read_subsample+0x50>
movslq %r15d,%rax
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%rbp
mov    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
add    %rbx,%rbp
add    $0xffffffffffffffff,%r12
jne    1190 <read_subsample+0x80>
jmp    1160 <read_subsample+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_subsample(double* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
store i32 0, i32* %13
br label %14
14: ; preds = %46, %5
%15 = load i32, i32* %13
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
store i32 0, i32* %12
br label %19
19: ; preds = %42, %18
%20 = load i32, i32* %12
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %45
23: ; preds = %19
%24 = load double*, double** %6
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load i32, i32* %12
%29 = load i32, i32* %7
%30 = mul nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %27, i64 %31
%33 = load i32, i32* %13
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %8
%37 = mul nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %32, i64 %38
%40 = load i32*, i32** %10
%41 = call i32 @fread(double* %39, i32 8, i32 1, i32* %40)
br label %42
42: ; preds = %23
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %19
45: ; preds = %19
br label %46
46: ; preds = %45
%47 = load i32, i32* %13
%48 = add nsw i32 %47, 1
store i32 %48, i32* %13
br label %14
49: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @read_subsample(double* nocapture %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %30
7: ; preds = %5
%8 = icmp sgt i32 %2, 0
%9 = mul i32 %2, %1
%10 = sext i32 %1 to i64
%11 = zext i32 %3 to i64
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %7, %27
%14 = phi i64 [ 0, %7 ], [ %28, %27 ]
br i1 %8, label %15, label %27
15: ; preds = %13
%16 = trunc i64 %14 to i32
%17 = mul i32 %9, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %0, i64 %18
br label %20
20: ; preds = %15, %20
%21 = phi i64 [ 0, %15 ], [ %25, %20 ]
%22 = mul nsw i64 %21, %10
%23 = getelementptr inbounds double, double* %19, i64 %22
%24 = tail call i32 @fread(double* %23, i32 8, i32 1, i32* %4)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %20
27: ; preds = %20, %13
%28 = add nuw nsw i64 %14, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %30, label %13
30: ; preds = %27, %5
ret void
}