#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 */

/* Variables and functions */
int /*<<< orphan*/ computeDensity(double *, double *);
int /*<<< orphan*/ computeFeq(double *, double *, double *);
int /*<<< orphan*/
computePostCollisionDistributions(double *, double const *const, double *);
int /*<<< orphan*/ computeVelocity(double *, double *, double *);
double *getEl(double *, int *, int /*<<< orphan*/, int *);
void doCollision(double *collideField, int *flagField, const double *const tau,
                 int *length) {
  double density;
  double velocity[3];
  double feq[19];
  double *currentCell;
  int x, y, z;
  int node[3];
  int n[3] = {length[0] + 2, length[1] + 2, length[2] + 2};
  for (z = 1; z <= length[2]; z++) {
    node[2] = z;
    for (y = 1; y <= length[1]; y++) {
      node[1] = y;
      for (x = 1; x <= length[0]; x++) {
        node[0] = x;
        currentCell = getEl(collideField, node, 0, n);
        computeDensity(currentCell, &density);
        computeVelocity(currentCell, &density, velocity);
        computeFeq(&density, velocity, feq);
        computePostCollisionDistributions(currentCell, tau, feq);
      }
    }
  }
}


x86 assembly (clang, -O0):
<doCollision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x2,%eax
mov    %eax,-0x108(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
add    $0x2,%eax
mov    %eax,-0x104(%rbp)
movl   $0x1,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%eax
jg     12c9 <doCollision+0x179>
mov    -0xf4(%rbp),%eax
mov    %eax,-0xf8(%rbp)
movl   $0x1,-0xf0(%rbp)
mov    -0xf0(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    0x4(%rcx),%eax
jg     12b0 <doCollision+0x160>
mov    -0xf0(%rbp),%eax
mov    %eax,-0xfc(%rbp)
movl   $0x1,-0xec(%rbp)
mov    -0xec(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     1297 <doCollision+0x147>
mov    -0xec(%rbp),%eax
mov    %eax,-0x100(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x100(%rbp),%rsi
lea    -0x10c(%rbp),%rcx
xor    %edx,%edx
call   1060 <getEl@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <computeDensity@plt>
mov    -0xe8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <computeVelocity@plt>
lea    -0x40(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
lea    -0x28(%rbp),%rdi
call   1070 <computeFeq@plt>
mov    -0xe8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
call   1050 <computePostCollisionDistributions@plt>
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
jmp    11f6 <doCollision+0xa6>
jmp    129c <doCollision+0x14c>
mov    -0xf0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf0(%rbp)
jmp    11cd <doCollision+0x7d>
jmp    12b5 <doCollision+0x165>
mov    -0xf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4(%rbp)
jmp    11a4 <doCollision+0x54>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doCollision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    (%rcx),%eax
lea    0x2(%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x4(%rbp),%r9d
lea    0x2(%r9),%edx
mov    %edx,0xc(%rsp)
mov    0x8(%rbp),%r8d
lea    0x2(%r8),%esi
mov    %esi,0x10(%rsp)
test   %r8d,%r8d
jle    127f <doCollision+0x12f>
mov    %rdi,%r13
mov    $0x1,%edx
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,0x30(%rsp)
jmp    11c9 <doCollision+0x79>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbp),%r8d
mov    0x20(%rsp),%rdx
lea    0x1(%rdx),%r10d
cmp    %r8d,%edx
mov    %r10d,%edx
jge    127f <doCollision+0x12f>
mov    %edx,0x1c(%rsp)
test   %r9d,%r9d
jle    11b9 <doCollision+0x69>
mov    %rdx,0x20(%rsp)
mov    $0x1,%edx
jmp    11ec <doCollision+0x9c>
xchg   %ax,%ax
lea    0x1(%rdx),%r8d
cmp    %r9d,%edx
mov    %r8d,%edx
jge    11b0 <doCollision+0x60>
mov    %edx,0x18(%rsp)
test   %eax,%eax
jle    11e0 <doCollision+0x90>
mov    %rdx,0x28(%rsp)
xor    %r15d,%r15d
nopl   0x0(%rax)
add    $0x1,%r15d
mov    %r15d,0x14(%rsp)
mov    %r13,%rdi
xor    %edx,%edx
call   1060 <getEl@plt>
mov    %rax,%r14
mov    %rax,%rdi
lea    0x38(%rsp),%rbp
mov    %rbp,%rsi
call   1040 <computeDensity@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
lea    0x40(%rsp),%r12
mov    %r12,%rdx
call   1030 <computeVelocity@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
lea    0x60(%rsp),%rbp
mov    %rbp,%rdx
call   1070 <computeFeq@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <computePostCollisionDistributions@plt>
lea    0x8(%rsp),%rcx
lea    0x14(%rsp),%rsi
mov    0x30(%rsp),%rbp
mov    0x0(%rbp),%eax
cmp    %eax,%r15d
jl     1200 <doCollision+0xb0>
mov    0x4(%rbp),%r9d
mov    0x28(%rsp),%rdx
jmp    11e0 <doCollision+0x90>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @doCollision(double* %0, i32* %1, double* %2, i32* %3) {
%5 = alloca double*
%6 = alloca i32*
%7 = alloca double*
%8 = alloca i32*
%9 = alloca double
%10 = alloca [3 x double]
%11 = alloca [19 x double]
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [3 x i32]
%17 = alloca [3 x i32]
store double* %0, double** %5
store i32* %1, i32** %6
store double* %2, double** %7
store i32* %3, i32** %8
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%19 = load i32*, i32** %8
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 2
store i32 %22, i32* %18
%23 = getelementptr inbounds i32, i32* %18, i64 1
%24 = load i32*, i32** %8
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 2
store i32 %27, i32* %23
%28 = getelementptr inbounds i32, i32* %23, i64 1
%29 = load i32*, i32** %8
%30 = getelementptr inbounds i32, i32* %29, i64 2
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 2
store i32 %32, i32* %28
store i32 1, i32* %15
br label %33
33: ; preds = %84, %4
%34 = load i32, i32* %15
%35 = load i32*, i32** %8
%36 = getelementptr inbounds i32, i32* %35, i64 2
%37 = load i32, i32* %36
%38 = icmp sle i32 %34, %37
br i1 %38, label %39, label %87
39: ; preds = %33
%40 = load i32, i32* %15
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 2
store i32 %40, i32* %41
store i32 1, i32* %14
br label %42
42: ; preds = %80, %39
%43 = load i32, i32* %14
%44 = load i32*, i32** %8
%45 = getelementptr inbounds i32, i32* %44, i64 1
%46 = load i32, i32* %45
%47 = icmp sle i32 %43, %46
br i1 %47, label %48, label %83
48: ; preds = %42
%49 = load i32, i32* %14
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 1
store i32 %49, i32* %50
store i32 1, i32* %13
br label %51
51: ; preds = %76, %48
%52 = load i32, i32* %13
%53 = load i32*, i32** %8
%54 = getelementptr inbounds i32, i32* %53, i64 0
%55 = load i32, i32* %54
%56 = icmp sle i32 %52, %55
br i1 %56, label %57, label %79
57: ; preds = %51
%58 = load i32, i32* %13
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
store i32 %58, i32* %59
%60 = load double*, double** %5
%61 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%62 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%63 = call double* @getEl(double* %60, i32* %61, i32 0, i32* %62)
store double* %63, double** %12
%64 = load double*, double** %12
%65 = call i32 @computeDensity(double* %64, double* %9)
%66 = load double*, double** %12
%67 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%68 = call i32 @computeVelocity(double* %66, double* %9, double* %67)
%69 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%70 = getelementptr inbounds [19 x double], [19 x double]* %11, i64 0, i64 0
%71 = call i32 @computeFeq(double* %9, double* %69, double* %70)
%72 = load double*, double** %12
%73 = load double*, double** %7
%74 = getelementptr inbounds [19 x double], [19 x double]* %11, i64 0, i64 0
%75 = call i32 @computePostCollisionDistributions(double* %72, double* %73, double* %74)
br label %76
76: ; preds = %57
%77 = load i32, i32* %13
%78 = add nsw i32 %77, 1
store i32 %78, i32* %13
br label %51
79: ; preds = %51
br label %80
80: ; preds = %79
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 1
store i32 %82, i32* %14
br label %42
83: ; preds = %42
br label %84
84: ; preds = %83
%85 = load i32, i32* %15
%86 = add nsw i32 %85, 1
store i32 %86, i32* %15
br label %33
87: ; preds = %33
ret void
}

LLVM IR (-O2):
define void @doCollision(double* %0, i32* nocapture readnone %1, double* %2, i32* nocapture %3) {
%5 = alloca double
%6 = alloca [3 x double]
%7 = alloca [19 x double]
%8 = alloca [3 x i32]
%9 = alloca [3 x i32]
%10 = bitcast double* %5 to i8*
%11 = bitcast [3 x double]* %6 to i8*
%12 = bitcast [19 x double]* %7 to i8*
%13 = bitcast [3 x i32]* %8 to i8*
%14 = bitcast [3 x i32]* %9 to i8*
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 2
store i32 %17, i32* %15
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 1
%19 = getelementptr inbounds i32, i32* %3, i64 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 2
store i32 %21, i32* %18
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 2
%23 = getelementptr inbounds i32, i32* %3, i64 2
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 2
store i32 %25, i32* %22
%26 = icmp slt i32 %24, 1
br i1 %26, label %71, label %27
27: ; preds = %4
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%31 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%32 = getelementptr inbounds [19 x double], [19 x double]* %7, i64 0, i64 0
br label %33
33: ; preds = %27, %64
%34 = phi i32 [ %24, %27 ], [ %65, %64 ]
%35 = phi i32 [ %20, %27 ], [ %66, %64 ]
%36 = phi i32 [ %16, %27 ], [ %67, %64 ]
%37 = phi i32 [ %20, %27 ], [ %68, %64 ]
%38 = phi i32 [ 1, %27 ], [ %69, %64 ]
store i32 %38, i32* %28
%39 = icmp slt i32 %37, 1
br i1 %39, label %64, label %40
40: ; preds = %33, %57
%41 = phi i32 [ %58, %57 ], [ %35, %33 ]
%42 = phi i32 [ %59, %57 ], [ %36, %33 ]
%43 = phi i32 [ %60, %57 ], [ 1, %33 ]
store i32 %43, i32* %29
%44 = icmp slt i32 %42, 1
br i1 %44, label %57, label %45
45: ; preds = %40, %45
%46 = phi i32 [ %52, %45 ], [ 1, %40 ]
store i32 %46, i32* %30
%47 = call double* @getEl(double* %0, i32* %30, i32 0, i32* %15)
%48 = call i32 @computeDensity(double* %47, double* %5)
%49 = call i32 @computeVelocity(double* %47, double* %5, double* %31)
%50 = call i32 @computeFeq(double* %5, double* %31, double* %32)
%51 = call i32 @computePostCollisionDistributions(double* %47, double* %2, double* %32)
%52 = add nuw nsw i32 %46, 1
%53 = load i32, i32* %3
%54 = icmp slt i32 %46, %53
br i1 %54, label %45, label %55
55: ; preds = %45
%56 = load i32, i32* %19
br label %57
57: ; preds = %55, %40
%58 = phi i32 [ %56, %55 ], [ %41, %40 ]
%59 = phi i32 [ %53, %55 ], [ %42, %40 ]
%60 = add nuw nsw i32 %43, 1
%61 = icmp slt i32 %43, %58
br i1 %61, label %40, label %62
62: ; preds = %57
%63 = load i32, i32* %23
br label %64
64: ; preds = %62, %33
%65 = phi i32 [ %63, %62 ], [ %34, %33 ]
%66 = phi i32 [ %58, %62 ], [ %35, %33 ]
%67 = phi i32 [ %59, %62 ], [ %36, %33 ]
%68 = phi i32 [ %58, %62 ], [ %37, %33 ]
%69 = add nuw nsw i32 %38, 1
%70 = icmp slt i32 %38, %65
br i1 %70, label %33, label %71
71: ; preds = %64, %4
ret void
}