#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int M_PI;
int /*<<< orphan*/ alloc_grid(double ***, int);
int atoi(char *);
double cos(int);
int even(int);
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ init_grid(double **, int);
int /*<<< orphan*/ print_grid(double **, int);
int /*<<< orphan*/ printf(char *, int, double, double);
int sqrt(int);
int /*<<< orphan*/ stderr;
double stencil(double **, int, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int N;
  int ncol, nrow;
  double Gnew, r, omega, stopdiff, maxdiff, diff;
  double **G;
  int i, j, phase, iteration;
  struct timeval start;
  struct timeval end;
  double time;
  int print = 0;
  N = 100;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-print")) {
      print = 1;
    } else {
      N = atoi(argv[i]);
    }
  }
  fprintf(stderr, "Running %d x %d SOR\n", N, N);
  N += 2;
  ncol = nrow = N;
  r = 0.5 * (cos(M_PI / ncol) + cos(M_PI / nrow));
  omega = 2.0 / (1 + sqrt(1 - r * r));
  stopdiff = 0.001 / (2.0 - omega);
  omega *= 0.8;
  alloc_grid(&G, N);
  init_grid(G, N);
  if (gettimeofday(&start, 0) != 0) {
    fprintf(stderr, "could not do timing\n");
    exit(1);
  }
  iteration = 0;
  do {
    maxdiff = 0.0;
    for (phase = 0; phase < 2; phase++) {
      for (i = 1; i < N - 1; i++) {
        for (j = 1 + (even(i) ^ phase); j < N - 1; j += 2) {
          Gnew = stencil(G, i, j);
          diff = fabs(Gnew - G[i][j]);
          if (diff > maxdiff)
            maxdiff = diff;
          G[i][j] = G[i][j] + omega * (Gnew - G[i][j]);
        }
      }
    }
    iteration++;
  } while (maxdiff > stopdiff);
  if (gettimeofday(&end, 0) != 0) {
    fprintf(stderr, "could not do timing\n");
    exit(1);
  }
  time = (end.tv_sec + (end.tv_usec / 1000000.0)) -
         (start.tv_sec + (start.tv_usec / 1000000.0));
  fprintf(stderr, "SOR took %10.3f seconds\n", time);
  printf("Used %5d iterations, diff is %10.6f, allowed diff is %10.6f\n",
         iteration, maxdiff, stopdiff);
  if (print == 1) {
    print_grid(G, N);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1264 <main+0x94>
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe20(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123d <main+0x6d>
movl   $0x1,-0x94(%rbp)
jmp    1251 <main+0x81>
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1256 <main+0x86>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1201 <main+0x31>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x18(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%edi
call   10a0 <cos@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%edi
call   10a0 <cos@plt>
movsd  -0xa0(%rbp),%xmm1
ff
addsd  %xmm0,%xmm1
movsd  0xd49(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd0b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   10c0 <sqrt@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xce7(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xcd6(%rip),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xcc1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xca8(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x58(%rbp),%rdi
call   10f0 <alloc_grid@plt>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10e0 <init_grid@plt>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     13b0 <main+0x1e0>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
lea    0xcbd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x2,-0x64(%rbp)
jge    14e7 <main+0x317>
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14d4 <main+0x304>
mov    -0x5c(%rbp),%edi
call   1070 <even@plt>
xor    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14c1 <main+0x2f1>
mov    -0x58(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
call   1090 <stencil@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xbf1(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1462 <main+0x292>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x60(%rbp)
jmp    13f9 <main+0x229>
jmp    14c6 <main+0x2f6>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    13d7 <main+0x207>
jmp    14d9 <main+0x309>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    13c6 <main+0x1f6>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
ja     13b7 <main+0x1e7>
lea    -0x88(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     1539 <main+0x369>
mov    0x2ab9(%rip),%rax
mov    (%rax),%edi
lea    0xb34(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x80(%rbp),%xmm1
movsd  0xada(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  -0x78(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movsd  0xac0(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    0x2a55(%rip),%rax
mov    (%rax),%edi
movsd  -0x90(%rbp),%xmm0
ff
lea    0xadd(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
mov    -0x68(%rbp),%esi
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xadb(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x94(%rbp)
jne    15cd <main+0x3fd>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <print_grid@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jl     1241 <main+0x71>
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x64,%r12d
movl   $0x0,0xc(%rsp)
mov    $0x1,%ebp
lea    0xe4d(%rip),%r14
jmp    1224 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   10b0 <atoi@plt>
mov    %eax,%r12d
add    $0x1,%rbp
cmp    %rbp,%r13
je     124f <main+0x7f>
mov    (%r15,%rbp,8),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1210 <main+0x40>
movl   $0x1,0xc(%rsp)
jmp    121b <main+0x4b>
movl   $0x0,0xc(%rsp)
mov    $0x64,%r12d
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
xor    %r15d,%r15d
mov    %r12d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x2(%r12),%ebp
mov    0x2d6d(%rip),%rbx
mov    (%rbx),%eax
cltd
idiv   %ebp
mov    %eax,%edi
call   10a0 <cos@plt>
movsd  %xmm0,0x10(%rsp)
mov    (%rbx),%eax
cltd
idiv   %ebp
mov    %eax,%edi
call   10a0 <cos@plt>
addsd  0x10(%rsp),%xmm0
mulsd  0xd59(%rip),%xmm0
mulsd  %xmm0,%xmm0
movsd  0xd55(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   10c0 <sqrt@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%rdi
mov    %ebp,%esi
call   10f0 <alloc_grid@plt>
mov    0x20(%rsp),%rdi
mov    %ebp,0x2c(%rsp)
mov    %ebp,%esi
call   10e0 <init_grid@plt>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    156e <main+0x39e>
add    $0x1,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xd0b(%rip),%xmm1
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  0xcff(%rip),%xmm0
mulsd  0xcff(%rip),%xmm2
movsd  %xmm2,0x38(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
movslq %r12d,%r14
lea    0x1(%r12),%r13d
jmp    1354 <main+0x184>
nopl   0x0(%rax,%rax,1)
xorpd  %xmm2,%xmm2
add    $0x1,%r15d
ucomisd 0x30(%rsp),%xmm2
jbe    14c9 <main+0x2f9>
test   %r12d,%r12d
jle    1340 <main+0x170>
xorpd  %xmm0,%xmm0
mov    $0x1,%ebp
jmp    1383 <main+0x1b3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd 0x10(%rsp),%xmm0
add    $0x1,%rbp
cmp    %r13,%rbp
je     1410 <main+0x240>
movapd %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1070 <even@plt>
cmp    %r12d,%eax
jge    1370 <main+0x1a0>
add    $0x1,%eax
movslq %eax,%rbx
mov    0x20(%rsp),%rdi
movaps 0x10(%rsp),%xmm1
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm1,0x10(%rsp)
mov    %ebp,%esi
mov    %ebx,%edx
call   1090 <stencil@plt>
mov    0x20(%rsp),%rdi
mov    (%rdi,%rbp,8),%rax
movsd  (%rax,%rbx,8),%xmm2
subsd  %xmm2,%xmm0
movsd  0x38(%rsp),%xmm1
mulsd  %xmm0,%xmm1
andpd  0xc4d(%rip),%xmm0
maxsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm1
movsd  %xmm1,(%rax,%rbx,8)
add    $0x2,%rbx
movapd %xmm0,%xmm1
cmp    %r14,%rbx
jle    13b0 <main+0x1e0>
jmp    1376 <main+0x1a6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r12d,%r12d
jle    14c0 <main+0x2f0>
mov    $0x1,%ebp
jmp    1437 <main+0x267>
movapd 0x10(%rsp),%xmm2
add    $0x1,%rbp
movapd %xmm2,%xmm0
cmp    %r13,%rbp
je     1344 <main+0x174>
movapd %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1070 <even@plt>
xor    $0x1,%eax
cmp    %r12d,%eax
jge    1420 <main+0x250>
add    $0x1,%eax
movslq %eax,%rbx
mov    0x20(%rsp),%rdi
movapd 0x10(%rsp),%xmm0
nopl   (%rax)
movapd %xmm0,0x10(%rsp)
mov    %ebp,%esi
mov    %ebx,%edx
call   1090 <stencil@plt>
movapd %xmm0,%xmm2
mov    0x20(%rsp),%rdi
mov    (%rdi,%rbp,8),%rax
movsd  (%rax,%rbx,8),%xmm0
subsd  %xmm0,%xmm2
movsd  0x38(%rsp),%xmm1
mulsd  %xmm2,%xmm1
andpd  0xb99(%rip),%xmm2
maxsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rbx,8)
add    $0x2,%rbx
movapd %xmm2,%xmm0
cmp    %r14,%rbx
jle    1460 <main+0x290>
jmp    1426 <main+0x256>
nopl   0x0(%rax,%rax,1)
movapd %xmm0,%xmm2
jmp    1344 <main+0x174>
movapd %xmm2,0x10(%rsp)
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    156e <main+0x39e>
movapd 0x50(%rsp),%xmm0
movsd  0x48(%rsp),%xmm1
movapd %xmm0,%xmm2
shufpd $0x1,%xmm1,%xmm2
divpd  0xb3f(%rip),%xmm2
movhpd 0x40(%rsp),%xmm0
addpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
lea    0xb5a(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
lea    0xb65(%rip),%rdi
mov    %r15d,%esi
movaps 0x10(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
call   1030 <printf@plt>
cmpl   $0x1,0xc(%rsp)
jne    155d <main+0x38d>
mov    0x20(%rsp),%rdi
mov    0x2c(%rsp),%esi
call   1050 <print_grid@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a63(%rip),%rax
mov    (%rax),%edi
lea    0xaee(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [7 x i8] c"-print\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Running %d x %d SOR\0A\00"
@M_PI = global i32 0
@.str.2 = [21 x i8] c"could not do timing\0A\00"
@.str.3 = [25 x i8] c"SOR took %10.3f seconds\0A\00"
@.str.4 = [61 x i8] c"Used %5d iterations, diff is %10.6f, allowed diff is %10.6f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double**
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca %struct.timeval
%21 = alloca %struct.timeval
%22 = alloca double
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %23
store i32 100, i32* %6
store i32 1, i32* %16
br label %24
24: ; preds = %45, %2
%25 = load i32, i32* %16
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %48
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %16
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %28
store i32 1, i32* %23
br label %44
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %6
br label %44
44: ; preds = %37, %36
br label %45
45: ; preds = %44
%46 = load i32, i32* %16
%47 = add nsw i32 %46, 1
store i32 %47, i32* %16
br label %24
48: ; preds = %24
%49 = load i32, i32* @stderr
%50 = load i32, i32* %6
%51 = load i32, i32* %6
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 2
store i32 %54, i32* %6
%55 = load i32, i32* %6
store i32 %55, i32* %8
store i32 %55, i32* %7
%56 = load i32, i32* @M_PI
%57 = load i32, i32* %7
%58 = sdiv i32 %56, %57
%59 = call double @cos(i32 %58)
%60 = load i32, i32* @M_PI
%61 = load i32, i32* %8
%62 = sdiv i32 %60, %61
%63 = call double @cos(i32 %62)
%64 = fadd double %59, %63
%65 = fmul double 5.000000e-01, %64
store double %65, double* %10
%66 = load double, double* %10
%67 = load double, double* %10
%68 = fneg double %66
%69 = call double @llvm.fmuladd.f64(double %68, double %67, double 1.000000e+00)
%70 = fptosi double %69 to i32
%71 = call i32 @sqrt(i32 %70)
%72 = add nsw i32 1, %71
%73 = sitofp i32 %72 to double
%74 = fdiv double 2.000000e+00, %73
store double %74, double* %11
%75 = load double, double* %11
%76 = fsub double 2.000000e+00, %75
%77 = fdiv double 1.000000e-03, %76
store double %77, double* %12
%78 = load double, double* %11
%79 = fmul double %78, 8.000000e-01
store double %79, double* %11
%80 = load i32, i32* %6
%81 = call i32 @alloc_grid(double*** %15, i32 %80)
%82 = load double**, double*** %15
%83 = load i32, i32* %6
%84 = call i32 @init_grid(double** %82, i32 %83)
%85 = call i64 @gettimeofday(%struct.timeval* %20, i32 0)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %48
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %48
store i32 0, i32* %19
br label %92
92: ; preds = %180, %91
store double 0.000000e+00, double* %13
store i32 0, i32* %18
br label %93
93: ; preds = %174, %92
%94 = load i32, i32* %18
%95 = icmp slt i32 %94, 2
br i1 %95, label %96, label %177
96: ; preds = %93
store i32 1, i32* %16
br label %97
97: ; preds = %170, %96
%98 = load i32, i32* %16
%99 = load i32, i32* %6
%100 = sub nsw i32 %99, 1
%101 = icmp slt i32 %98, %100
br i1 %101, label %102, label %173
102: ; preds = %97
%103 = load i32, i32* %16
%104 = call i32 @even(i32 %103)
%105 = load i32, i32* %18
%106 = xor i32 %104, %105
%107 = add nsw i32 1, %106
store i32 %107, i32* %17
br label %108
108: ; preds = %166, %102
%109 = load i32, i32* %17
%110 = load i32, i32* %6
%111 = sub nsw i32 %110, 1
%112 = icmp slt i32 %109, %111
br i1 %112, label %113, label %169
113: ; preds = %108
%114 = load double**, double*** %15
%115 = load i32, i32* %16
%116 = load i32, i32* %17
%117 = call double @stencil(double** %114, i32 %115, i32 %116)
store double %117, double* %9
%118 = load double, double* %9
%119 = load double**, double*** %15
%120 = load i32, i32* %16
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds double*, double** %119, i64 %121
%123 = load double*, double** %122
%124 = load i32, i32* %17
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds double, double* %123, i64 %125
%127 = load double, double* %126
%128 = fsub double %118, %127
%129 = call double @llvm.fabs.f64(double %128)
store double %129, double* %14
%130 = load double, double* %14
%131 = load double, double* %13
%132 = fcmp ogt double %130, %131
br i1 %132, label %133, label %135
133: ; preds = %113
%134 = load double, double* %14
store double %134, double* %13
br label %135
135: ; preds = %133, %113
%136 = load double**, double*** %15
%137 = load i32, i32* %16
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds double*, double** %136, i64 %138
%140 = load double*, double** %139
%141 = load i32, i32* %17
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds double, double* %140, i64 %142
%144 = load double, double* %143
%145 = load double, double* %11
%146 = load double, double* %9
%147 = load double**, double*** %15
%148 = load i32, i32* %16
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds double*, double** %147, i64 %149
%151 = load double*, double** %150
%152 = load i32, i32* %17
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds double, double* %151, i64 %153
%155 = load double, double* %154
%156 = fsub double %146, %155
%157 = call double @llvm.fmuladd.f64(double %145, double %156, double %144)
%158 = load double**, double*** %15
%159 = load i32, i32* %16
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds double*, double** %158, i64 %160
%162 = load double*, double** %161
%163 = load i32, i32* %17
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds double, double* %162, i64 %164
store double %157, double* %165
br label %166
166: ; preds = %135
%167 = load i32, i32* %17
%168 = add nsw i32 %167, 2
store i32 %168, i32* %17
br label %108
169: ; preds = %108
br label %170
170: ; preds = %169
%171 = load i32, i32* %16
%172 = add nsw i32 %171, 1
store i32 %172, i32* %16
br label %97
173: ; preds = %97
br label %174
174: ; preds = %173
%175 = load i32, i32* %18
%176 = add nsw i32 %175, 1
store i32 %176, i32* %18
br label %93
177: ; preds = %93
%178 = load i32, i32* %19
%179 = add nsw i32 %178, 1
store i32 %179, i32* %19
br label %180
180: ; preds = %177
%181 = load double, double* %13
%182 = load double, double* %12
%183 = fcmp ogt double %181, %182
br i1 %183, label %92, label %184
184: ; preds = %180
%185 = call i64 @gettimeofday(%struct.timeval* %21, i32 0)
%186 = icmp ne i64 %185, 0
br i1 %186, label %187, label %191
187: ; preds = %184
%188 = load i32, i32* @stderr
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%190 = call i32 @exit(i32 1)
unreachable
191: ; preds = %184
%192 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%193 = load double, double* %192
%194 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%195 = load double, double* %194
%196 = fdiv double %195, 1.000000e+06
%197 = fadd double %193, %196
%198 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
%199 = load double, double* %198
%200 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
%201 = load double, double* %200
%202 = fdiv double %201, 1.000000e+06
%203 = fadd double %199, %202
%204 = fsub double %197, %203
store double %204, double* %22
%205 = load i32, i32* @stderr
%206 = load double, double* %22
%207 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), double %206)
%208 = load i32, i32* %19
%209 = load double, double* %13
%210 = load double, double* %12
%211 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %208, double %209, double %210)
%212 = load i32, i32* %23
%213 = icmp eq i32 %212, 1
br i1 %213, label %214, label %218
214: ; preds = %191
%215 = load double**, double*** %15
%216 = load i32, i32* %6
%217 = call i32 @print_grid(double** %215, i32 %216)
br label %218
218: ; preds = %214, %191
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [7 x i8] c"-print\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Running %d x %d SOR\0A\00"
@M_PI = global i32 0
@.str.2 = [21 x i8] c"could not do timing\0A\00"
@.str.3 = [25 x i8] c"SOR took %10.3f seconds\0A\00"
@.str.4 = [61 x i8] c"Used %5d iterations, diff is %10.6f, allowed diff is %10.6f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double**
%4 = alloca %struct.timeval
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timeval*
%7 = bitcast double*** %3 to i8*
%8 = bitcast %struct.timeval* %4 to i8*
%9 = bitcast <2 x double>* %5 to i8*
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %23
%14 = phi i64 [ 1, %11 ], [ %26, %23 ]
%15 = phi i32 [ 0, %11 ], [ %25, %23 ]
%16 = phi i32 [ 100, %11 ], [ %24, %23 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %14
%18 = load i8*, i8** %17
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %18, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %13
%22 = tail call i32 @atoi(i8* %18)
br label %23
23: ; preds = %13, %21
%24 = phi i32 [ %22, %21 ], [ %16, %13 ]
%25 = phi i32 [ %15, %21 ], [ 1, %13 ]
%26 = add nuw nsw i64 %14, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %13
28: ; preds = %23, %2
%29 = phi i32 [ 100, %2 ], [ %24, %23 ]
%30 = phi i32 [ 0, %2 ], [ %25, %23 ]
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %29)
%33 = add nsw i32 %29, 2
%34 = load i32, i32* @M_PI
%35 = sdiv i32 %34, %33
%36 = tail call double @cos(i32 %35)
%37 = load i32, i32* @M_PI
%38 = sdiv i32 %37, %33
%39 = tail call double @cos(i32 %38)
%40 = fadd double %36, %39
%41 = fmul double %40, 5.000000e-01
%42 = fneg double %41
%43 = tail call double @llvm.fmuladd.f64(double %42, double %41, double 1.000000e+00)
%44 = fptosi double %43 to i32
%45 = tail call i32 @sqrt(i32 %44)
%46 = add nsw i32 %45, 1
%47 = sitofp i32 %46 to double
%48 = fdiv double 2.000000e+00, %47
%49 = fsub double 2.000000e+00, %48
%50 = fdiv double 1.000000e-03, %49
%51 = fmul double %48, 8.000000e-01
%52 = call i32 @alloc_grid(double*** %3, i32 %33)
%53 = load double**, double*** %3
%54 = call i32 @init_grid(double** %53, i32 %33)
%55 = call i64 @gettimeofday(%struct.timeval* %4, i32 0)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %28
%58 = icmp slt i32 %29, 1
%59 = sext i32 %29 to i64
%60 = add i32 %29, 1
%61 = zext i32 %60 to i64
%62 = zext i32 %60 to i64
br label %67
63: ; preds = %28
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %57, %135
%68 = phi i32 [ %137, %135 ], [ 0, %57 ]
br i1 %58, label %135, label %69
69: ; preds = %67, %97
%70 = phi i64 [ %99, %97 ], [ 1, %67 ]
%71 = phi double [ %98, %97 ], [ 0.000000e+00, %67 ]
%72 = trunc i64 %70 to i32
%73 = call i32 @even(i32 %72)
%74 = icmp slt i32 %73, %29
br i1 %74, label %75, label %97
75: ; preds = %69
%76 = add nsw i32 %73, 1
%77 = sext i32 %76 to i64
%78 = load double**, double*** %3
br label %79
79: ; preds = %75, %79
%80 = phi double** [ %78, %75 ], [ %85, %79 ]
%81 = phi i64 [ %77, %75 ], [ %95, %79 ]
%82 = phi double [ %71, %75 ], [ %93, %79 ]
%83 = trunc i64 %81 to i32
%84 = call double @stencil(double** %80, i32 %72, i32 %83)
%85 = load double**, double*** %3
%86 = getelementptr inbounds double*, double** %85, i64 %70
%87 = load double*, double** %86
%88 = getelementptr inbounds double, double* %87, i64 %81
%89 = load double, double* %88
%90 = fsub double %84, %89
%91 = call double @llvm.fabs.f64(double %90)
%92 = fcmp ogt double %91, %82
%93 = select i1 %92, double %91, double %82
%94 = call double @llvm.fmuladd.f64(double %51, double %90, double %89)
store double %94, double* %88
%95 = add nsw i64 %81, 2
%96 = icmp sgt i64 %95, %59
br i1 %96, label %97, label %79
97: ; preds = %79, %69
%98 = phi double [ %71, %69 ], [ %93, %79 ]
%99 = add nuw nsw i64 %70, 1
%100 = icmp eq i64 %99, %61
br i1 %100, label %101, label %69
101: ; preds = %97
br i1 %58, label %135, label %102
102: ; preds = %101, %131
%103 = phi i64 [ %133, %131 ], [ 1, %101 ]
%104 = phi double [ %132, %131 ], [ %98, %101 ]
%105 = trunc i64 %103 to i32
%106 = call i32 @even(i32 %105)
%107 = xor i32 %106, 1
%108 = icmp slt i32 %107, %29
br i1 %108, label %109, label %131
109: ; preds = %102
%110 = add nsw i32 %107, 1
%111 = sext i32 %110 to i64
%112 = load double**, double*** %3
br label %113
113: ; preds = %113, %109
%114 = phi double** [ %112, %109 ], [ %119, %113 ]
%115 = phi i64 [ %111, %109 ], [ %129, %113 ]
%116 = phi double [ %104, %109 ], [ %127, %113 ]
%117 = trunc i64 %115 to i32
%118 = call double @stencil(double** %114, i32 %105, i32 %117)
%119 = load double**, double*** %3
%120 = getelementptr inbounds double*, double** %119, i64 %103
%121 = load double*, double** %120
%122 = getelementptr inbounds double, double* %121, i64 %115
%123 = load double, double* %122
%124 = fsub double %118, %123
%125 = call double @llvm.fabs.f64(double %124)
%126 = fcmp ogt double %125, %116
%127 = select i1 %126, double %125, double %116
%128 = call double @llvm.fmuladd.f64(double %51, double %124, double %123)
store double %128, double* %122
%129 = add nsw i64 %115, 2
%130 = icmp sgt i64 %129, %59
br i1 %130, label %131, label %113
131: ; preds = %113, %102
%132 = phi double [ %104, %102 ], [ %127, %113 ]
%133 = add nuw nsw i64 %103, 1
%134 = icmp eq i64 %133, %62
br i1 %134, label %135, label %102
135: ; preds = %131, %67, %101
%136 = phi double [ %98, %101 ], [ 0.000000e+00, %67 ], [ %132, %131 ]
%137 = add nuw nsw i32 %68, 1
%138 = fcmp ogt double %136, %50
br i1 %138, label %67, label %139
139: ; preds = %135
%140 = call i64 @gettimeofday(%struct.timeval* %6, i32 0)
%141 = icmp eq i64 %140, 0
br i1 %141, label %146, label %142
142: ; preds = %139
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%145 = call i32 @exit(i32 1)
unreachable
146: ; preds = %139
%147 = load <2 x double>, <2 x double>* %5
%148 = shufflevector <2 x double> %147, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%149 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%150 = load double, double* %149
%151 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%152 = load double, double* %151
%153 = insertelement <2 x double> %148, double %152, i64 1
%154 = fdiv <2 x double> %153, <double 1.000000e+06, double 1.000000e+06>
%155 = insertelement <2 x double> %147, double %150, i64 1
%156 = fadd <2 x double> %155, %154
%157 = shufflevector <2 x double> %156, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%158 = fsub <2 x double> %156, %157
%159 = extractelement <2 x double> %158, i64 0
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), double %159)
%162 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %137, double %136, double %50)
%163 = icmp eq i32 %30, 1
br i1 %163, label %164, label %167
164: ; preds = %146
%165 = load double**, double*** %3
%166 = call i32 @print_grid(double** %165, i32 %33)
br label %167
167: ; preds = %164, %146
ret i32 0
}