#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*/ printf(char *, int);
double residual(double **, double **, double, double, int, int);
double sqrt(int);
double **stub1(double **, double **, double, double, int, int);
double **solvePoisson2D(double **(*iterate)(double **, double **, double,
                                            double, int, int),
                        double **array2D, double **rhs, double dx, double dy,
                        int nX, int nY) {
  int t, nIterations, iterationsPerCheck, maxIterations;
  double res, tolerance;
  tolerance = sqrt(nX * nY) * dx * dy;
  maxIterations = 100 * nX * nY;
  iterationsPerCheck = 10;
  nIterations = 0;
  do {
    res = residual(array2D, rhs, dx, dy, nX, nY);
    for (t = 0; t < iterationsPerCheck; t++) {
      array2D = (*iterate)(array2D, rhs, dx, dy, nX, nY);
      nIterations += 1;
    }
  } while (res > tolerance && nIterations <= maxIterations);
  printf("Done! Iterations required: %d\n", nIterations);
  if (nIterations >= maxIterations) {
    printf("Warning: Maximum number of iterations reached! (%d)\n",
           nIterations);
  }
  return array2D;
}


x86 assembly (clang, -O0):
<solvePoisson2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
imul   -0x30(%rbp),%edi
call   1050 <sqrt@plt>
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
imul   $0x64,-0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
movl   $0xa,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1040 <residual@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    11f7 <solvePoisson2D+0xc7>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   *%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b2 <solvePoisson2D+0x82>
jmp    11fc <solvePoisson2D+0xcc>
movsd  -0x48(%rbp),%xmm0
xor    %eax,%eax
ucomisd -0x50(%rbp),%xmm0
mov    %al,-0x51(%rbp)
jbe    121d <solvePoisson2D+0xed>
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
setle  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1189 <solvePoisson2D+0x59>
mov    -0x38(%rbp),%esi
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
cmp    -0x40(%rbp),%eax
jl     1252 <solvePoisson2D+0x122>
mov    -0x38(%rbp),%esi
lea    0xdd2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solvePoisson2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %ecx,%r13d
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %r8d,%ebp
imul   %ecx,%ebp
mov    %ebp,%edi
call   1050 <sqrt@plt>
mulsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
imul   $0x64,%ebp,%eax
mov    %eax,0x14(%rsp)
mov    %r12,%rax
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
mov    %rax,%rbp
call   1040 <residual@plt>
movsd  %xmm0,0x20(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
mov    %rax,%rdi
mov    %rbx,%rsi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r13d,%edx
mov    %r14d,%ecx
call   *%r15
lea    0xa(%r12),%ebp
movsd  0x20(%rsp),%xmm0
ucomisd 0x18(%rsp),%xmm0
jbe    12de <solvePoisson2D+0x1ae>
add    $0x9,%r12d
cmp    0x14(%rsp),%r12d
mov    %ebp,%r12d
jl     1190 <solvePoisson2D+0x60>
mov    %rax,%rbx
lea    0xd18(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
cmp    0x14(%rsp),%ebp
jl     1303 <solvePoisson2D+0x1d3>
lea    0xd23(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Done! Iterations required: %d\0A\00"
@.str.1 = [53 x i8] c"Warning: Maximum number of iterations reached! (%d)\0A\00"
define double** @solvePoisson2D(double** (double**, double**, double, double, i32, i32)* %0, double** %1, double** %2, double %3, double %4, i32 %5, i32 %6) {
%8 = alloca double** (double**, double**, double, double, i32, i32)*
%9 = alloca double**
%10 = alloca double**
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca double
store double** (double**, double**, double, double, i32, i32)* %0, double** (double**, double**, double, double, i32, i32)** %8
store double** %1, double*** %9
store double** %2, double*** %10
store double %3, double* %11
store double %4, double* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%21 = load i32, i32* %13
%22 = load i32, i32* %14
%23 = mul nsw i32 %21, %22
%24 = call double @sqrt(i32 %23)
%25 = load double, double* %11
%26 = fmul double %24, %25
%27 = load double, double* %12
%28 = fmul double %26, %27
store double %28, double* %20
%29 = load i32, i32* %13
%30 = mul nsw i32 100, %29
%31 = load i32, i32* %14
%32 = mul nsw i32 %30, %31
store i32 %32, i32* %18
store i32 10, i32* %17
store i32 0, i32* %16
br label %33
33: ; preds = %68, %7
%34 = load double**, double*** %9
%35 = load double**, double*** %10
%36 = load double, double* %11
%37 = load double, double* %12
%38 = load i32, i32* %13
%39 = load i32, i32* %14
%40 = call double @residual(double** %34, double** %35, double %36, double %37, i32 %38, i32 %39)
store double %40, double* %19
store i32 0, i32* %15
br label %41
41: ; preds = %56, %33
%42 = load i32, i32* %15
%43 = load i32, i32* %17
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %59
45: ; preds = %41
%46 = load double** (double**, double**, double, double, i32, i32)*, double** (double**, double**, double, double, i32, i32)** %8
%47 = load double**, double*** %9
%48 = load double**, double*** %10
%49 = load double, double* %11
%50 = load double, double* %12
%51 = load i32, i32* %13
%52 = load i32, i32* %14
%53 = call double** %46(double** %47, double** %48, double %49, double %50, i32 %51, i32 %52)
store double** %53, double*** %9
%54 = load i32, i32* %16
%55 = add nsw i32 %54, 1
store i32 %55, i32* %16
br label %56
56: ; preds = %45
%57 = load i32, i32* %15
%58 = add nsw i32 %57, 1
store i32 %58, i32* %15
br label %41
59: ; preds = %41
br label %60
60: ; preds = %59
%61 = load double, double* %19
%62 = load double, double* %20
%63 = fcmp ogt double %61, %62
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = load i32, i32* %16
%66 = load i32, i32* %18
%67 = icmp sle i32 %65, %66
br label %68
68: ; preds = %64, %60
%69 = phi i1 [ false, %60 ], [ %67, %64 ]
br i1 %69, label %33, label %70
70: ; preds = %68
%71 = load i32, i32* %16
%72 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %16
%74 = load i32, i32* %18
%75 = icmp sge i32 %73, %74
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = load i32, i32* %16
%78 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %76, %70
%80 = load double**, double*** %9
ret double** %80
}

LLVM IR (-O2):
@.str = [31 x i8] c"Done! Iterations required: %d\0A\00"
@.str.1 = [53 x i8] c"Warning: Maximum number of iterations reached! (%d)\0A\00"
define double** @solvePoisson2D(double** (double**, double**, double, double, i32, i32)* nocapture %0, double** %1, double** %2, double %3, double %4, i32 %5, i32 %6) {
%8 = mul i32 %6, %5
%9 = tail call double @sqrt(i32 %8)
%10 = fmul double %9, %3
%11 = fmul double %10, %4
%12 = mul i32 %8, 100
br label %13
13: ; preds = %13, %7
%14 = phi i32 [ 0, %7 ], [ %28, %13 ]
%15 = phi double** [ %1, %7 ], [ %27, %13 ]
%16 = tail call double @residual(double** %15, double** %2, double %3, double %4, i32 %5, i32 %6)
%17 = add i32 %14, 9
%18 = tail call double** %0(double** %15, double** %2, double %3, double %4, i32 %5, i32 %6)
%19 = tail call double** %0(double** %18, double** %2, double %3, double %4, i32 %5, i32 %6)
%20 = tail call double** %0(double** %19, double** %2, double %3, double %4, i32 %5, i32 %6)
%21 = tail call double** %0(double** %20, double** %2, double %3, double %4, i32 %5, i32 %6)
%22 = tail call double** %0(double** %21, double** %2, double %3, double %4, i32 %5, i32 %6)
%23 = tail call double** %0(double** %22, double** %2, double %3, double %4, i32 %5, i32 %6)
%24 = tail call double** %0(double** %23, double** %2, double %3, double %4, i32 %5, i32 %6)
%25 = tail call double** %0(double** %24, double** %2, double %3, double %4, i32 %5, i32 %6)
%26 = tail call double** %0(double** %25, double** %2, double %3, double %4, i32 %5, i32 %6)
%27 = tail call double** %0(double** %26, double** %2, double %3, double %4, i32 %5, i32 %6)
%28 = add i32 %14, 10
%29 = fcmp ogt double %16, %11
%30 = icmp slt i32 %17, %12
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %13, label %32
32: ; preds = %13
%33 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %28)
%34 = icmp slt i32 %28, %12
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %37
37: ; preds = %35, %32
ret double** %27
}