#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_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
double **allocate2d(int, int);
int atoi(char *);
int converge(double **, double **, int, int, int, int);
int /*<<< orphan*/ copy2d(double **, double **, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprint2d(char *, double **, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ init2d(double **, int, int);
int /*<<< orphan*/ jacobi(double **, double **, int, int, int, int);
int omp_get_thread_num();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, int, double, double);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int global[2], local[2];
  int global_padded[2];
  int grid[2];
  double time = 0, compTime = 0;
  struct timeval tts, ttf;
  double **u_current, **u_previous;
  double **swap;
  if (argc != 5) {
    fprintf(stderr, "Usage: ./execname X Y Px Py\n");
    exit(-1);
  } else {
    global[0] = atoi(argv[1]);
    global[1] = atoi(argv[2]);
    grid[0] = atoi(argv[3]);
    grid[1] = atoi(argv[4]);
  }
  int i;
  for (i = 0; i < 2; i++) {
    if (global[i] % grid[i] == 0) {
      local[i] = global[i] / grid[i];
      global_padded[i] = global[i];
    } else {
      local[i] = (global[i] / grid[i]) + 1;
      global_padded[i] = local[i] * grid[i];
    }
  }
  u_previous = allocate2d(global_padded[0], global_padded[1]);
  init2d(u_previous, global[0], global[1]);
  u_current = allocate2d(global_padded[0], global_padded[1]);
  copy2d(u_current, u_previous, global[0], global[1]);
  int nthreads = grid[0] * grid[1];
  omp_set_num_threads(nthreads);
  int converged = 0;
  int globalConv = 0;
  int iters = 0;
  gettimeofday(&tts, NULL);
#pragma omp parallel reduction(+ : compTime)
  {
    int tid = omp_get_thread_num();
    int i, j, endi, endj, conv;
    conv = 0;
    struct timeval tcs, tcf;
    i = (global_padded[0] / grid[0]) * (tid % grid[0]);
    j = (global_padded[1] / grid[1]) * (tid / grid[0]);
    endi = ((i + local[0]) < global[0]) ? i + local[0] : (global[0] - 1);
    endj = ((j + local[1]) < global[1]) ? j + local[1] : (global[1] - 1);
    i += (i == 0);
    j += (j == 0);
    while (!globalConv) {
#pragma omp single
      { ++iters; }
      gettimeofday(&tcs, NULL);
      jacobi(u_previous, u_current, i, endi, j, endj);
      gettimeofday(&tcf, NULL);
      compTime +=
          (tcf.tv_sec - tcs.tv_sec) + (tcf.tv_usec - tcs.tv_usec) * 0.000001;
      if ((iters % 100) == 0) {
        conv = converge(u_previous, u_current, i, endi, j, endj);
      }
#pragma omp atomic
      converged += conv;
      if ((iters % 100 == 0) && (tid == 0)) {
        if (converged == nthreads) {
          globalConv = 1;
        }
      }
#pragma omp single
      {
        converged = 0;
        swap = u_previous;
        u_previous = u_current;
        u_current = swap;
      }
    }
  }
  gettimeofday(&ttf, NULL);
  time += (ttf.tv_sec - tts.tv_sec) + (ttf.tv_usec - tts.tv_usec) * 0.000001;
  printf("Simple Jacobi - Iters: %d Time: %.3lf   Computation: %.3lf\n", iters,
         time, (compTime / nthreads));
  fprint2d("testjacobi.out", u_current, global[0], global[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1222 <main+0x52>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x7c(%rbp)
cmpl   $0x2,-0x7c(%rbp)
jge    1307 <main+0x137>
movslq -0x7c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%eax
movslq -0x7c(%rbp),%rcx
cltd
idivl  -0x30(%rbp,%rcx,4)
cmp    $0x0,%edx
jne    12bd <main+0xed>
movslq -0x7c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%eax
movslq -0x7c(%rbp),%rcx
cltd
idivl  -0x30(%rbp,%rcx,4)
mov    %eax,%ecx
movslq -0x7c(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
movslq -0x7c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%ecx
movslq -0x7c(%rbp),%rax
mov    %ecx,-0x28(%rbp,%rax,4)
jmp    12f4 <main+0x124>
movslq -0x7c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%eax
movslq -0x7c(%rbp),%rcx
cltd
idivl  -0x30(%rbp,%rcx,4)
mov    %eax,%ecx
add    $0x1,%ecx
movslq -0x7c(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
movslq -0x7c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%ecx
movslq -0x7c(%rbp),%rax
imul   -0x30(%rbp,%rax,4),%ecx
movslq -0x7c(%rbp),%rax
mov    %ecx,-0x28(%rbp,%rax,4)
jmp    12f9 <main+0x129>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1269 <main+0x99>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <allocate2d@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1090 <init2d@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <allocate2d@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   10b0 <copy2d@plt>
mov    -0x30(%rbp),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%edi
call   10c0 <omp_set_num_threads@plt>
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    $0x0,%al
call   1040 <omp_get_thread_num@plt>
mov    %eax,-0x90(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x28(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,-0xd0(%rbp)
mov    -0x90(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    -0xd0(%rbp),%eax
imul   %edx,%eax
mov    %eax,-0x94(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,-0xcc(%rbp)
mov    -0x90(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,%ecx
mov    -0xcc(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    140f <main+0x23f>
mov    -0x94(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0xd4(%rbp)
jmp    141b <main+0x24b>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xd4(%rbp)
mov    -0xd4(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    144d <main+0x27d>
mov    -0x98(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0xd8(%rbp)
jmp    1459 <main+0x289>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xd8(%rbp)
mov    -0xd8(%rbp),%eax
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0x94(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x94(%rbp),%eax
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x98(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x98(%rbp),%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x88(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14b4 <main+0x2e4>
jmp    1606 <main+0x436>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
lea    -0xb8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x94(%rbp),%edx
mov    -0x9c(%rbp),%ecx
mov    -0x98(%rbp),%r8d
mov    -0xa0(%rbp),%r9d
call   1030 <jacobi@plt>
lea    -0xc8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0xc0(%rbp),%rax
sub    -0xb0(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0xc8(%rbp),%xmm0
ff
subsd  -0xb8(%rbp),%xmm0
ff
movsd  0xacb(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    158b <main+0x3bb>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x94(%rbp),%edx
mov    -0x9c(%rbp),%ecx
mov    -0x98(%rbp),%r8d
mov    -0xa0(%rbp),%r9d
call   10a0 <converge@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
add    -0x84(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x8c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    15df <main+0x40f>
cmpl   $0x0,-0x90(%rbp)
jne    15df <main+0x40f>
mov    -0x84(%rbp),%eax
cmp    -0x80(%rbp),%eax
jne    15da <main+0x40a>
movl   $0x1,-0x88(%rbp)
jmp    15df <main+0x40f>
movl   $0x0,-0x84(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    149b <main+0x2cb>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x58(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x60(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  0x9ce(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8c(%rbp),%esi
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
cvtsi2sdl -0x80(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0x9c1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x68(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0x9e7(%rip),%rdi
call   10d0 <fprint2d@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x5,%edi
jne    14e6 <main+0x316>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
mov    0x20(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%esi
mov    %eax,0x18(%rsp)
mov    %ebp,%eax
cltd
mov    %r14d,0x10(%rsp)
idiv   %r14d
lea    0x1(%rax),%edi
mov    %edi,%r12d
imul   %r14d,%r12d
test   %edx,%edx
cmove  %ebp,%r12d
mov    %rbp,%r14
cmove  %eax,%edi
mov    %edi,0x14(%rsp)
mov    %r15,%rbx
mov    %ebx,%eax
cltd
idiv   %esi
lea    0x1(%rax),%r15d
mov    %r15d,%ebp
imul   %esi,%ebp
test   %edx,%edx
cmove  %ebx,%ebp
mov    %rbx,0x38(%rsp)
cmove  %eax,%r15d
mov    %r12d,%edi
mov    %ebp,%esi
call   1070 <allocate2d@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r14d,%esi
mov    %r14,0x40(%rsp)
mov    %ebx,%edx
call   1090 <init2d@plt>
mov    %r12d,%edi
mov    %ebp,%esi
call   1070 <allocate2d@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,0x30(%rsp)
mov    %r13,%rsi
mov    %r14d,%edx
mov    0x38(%rsp),%r14
mov    %r14d,%ecx
call   10b0 <copy2d@plt>
mov    0x18(%rsp),%edi
mov    0x10(%rsp),%r13d
imul   %r13d,%edi
mov    %edi,0x24(%rsp)
call   10c0 <omp_set_num_threads@plt>
xor    %eax,%eax
mov    %rax,0x48(%rsp)
lea    0x78(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%r8d
mov    %r12d,%eax
cltd
idiv   %r13d
mov    %eax,%esi
mov    %r8d,%eax
cltd
idiv   %r13d
mov    %eax,%edi
mov    %edx,%ecx
imul   %esi,%ecx
mov    %ebp,%eax
cltd
idivl  0x18(%rsp)
imul   %edi,%eax
mov    0x14(%rsp),%edi
add    %ecx,%edi
mov    0x40(%rsp),%rsi
lea    -0x1(%rsi),%edx
cmp    %esi,%edi
cmovl  %edi,%edx
mov    %edx,0x2c(%rsp)
add    %eax,%r15d
lea    -0x1(%r14),%edx
cmp    %r14d,%r15d
cmovl  %r15d,%edx
mov    %edx,0x28(%rsp)
cmp    $0x1,%ecx
adc    $0x0,%ecx
mov    %ecx,0x14(%rsp)
cmp    $0x1,%eax
adc    $0x0,%eax
mov    %eax,0x10(%rsp)
test   %r8d,%r8d
sete   0xf(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x30(%rsp),%r15
mov    %ebp,%r13d
mov    %rbx,%rbp
mov    %r14d,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%ebx
add    $0xffffffff,%ebx
xor    %r12d,%r12d
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r15,%rdi
mov    %rbp,0x30(%rsp)
mov    %rbp,%rsi
mov    %r13d,%ebp
mov    0x14(%rsp),%edx
mov    0x2c(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0x28(%rsp),%r9d
call   1030 <jacobi@plt>
lea    0x68(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x70(%rsp),%r13
sub    0x58(%rsp),%r13
movsd  0x68(%rsp),%xmm1
subsd  0x50(%rsp),%xmm1
mulsd  0xc23(%rip),%xmm1
cmp    %ebp,%ebx
jne    1419 <main+0x249>
mov    %r15,%rdi
mov    0x30(%rsp),%rsi
mov    0x14(%rsp),%edx
mov    0x2c(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0x28(%rsp),%r9d
movsd  %xmm1,0x60(%rsp)
call   10a0 <converge@plt>
movsd  0x60(%rsp),%xmm1
mov    %rax,0x48(%rsp)
movzbl 0xf(%rsp),%eax
mov    %eax,%r12d
xorps  %xmm0,%xmm0
cvtsi2sd %r13,%xmm0
addsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
add    $0x1,%r14d
add    $0x1,%ebp
mov    %r15,%rbx
test   %r12b,%r12b
je     1360 <main+0x190>
mov    %r15,%rbx
mov    0x48(%rsp),%rax
cmp    0x24(%rsp),%eax
jne    1360 <main+0x190>
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x58(%rsp),%rax
sub    0x80(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x50(%rsp),%xmm1
subsd  0x78(%rsp),%xmm1
mulsd  0xb71(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl 0x24(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
divsd  %xmm2,%xmm1
lea    0xb73(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
lea    0xba1(%rip),%rdi
mov    %r15,%rsi
mov    0x40(%rsp),%rdx
mov    0x38(%rsp),%rcx
call   10d0 <fprint2d@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
lea    0xb12(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./execname X Y Px Py\0A\00"
@.str.1 = [60 x i8] c"Simple Jacobi - Iters: %d Time: %.3lf Computation: %.3lf\0A\00"
@.str.2 = [15 x i8] c"testjacobi.out\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca [2 x i32]
%9 = alloca [2 x i32]
%10 = alloca double
%11 = alloca double
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca double**
%15 = alloca double**
%16 = alloca double**
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca %struct.timeval
%29 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 5
br i1 %31, label %32, label %36
32: ; preds = %2
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %40, i32* %41
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
store i32 %45, i32* %46
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
store i32 %50, i32* %51
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 4
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
store i32 %55, i32* %56
br label %57
57: ; preds = %36
store i32 0, i32* %17
br label %58
58: ; preds = %119, %57
%59 = load i32, i32* %17
%60 = icmp slt i32 %59, 2
br i1 %60, label %61, label %122
61: ; preds = %58
%62 = load i32, i32* %17
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %17
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = srem i32 %65, %69
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %92
72: ; preds = %61
%73 = load i32, i32* %17
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = load i32, i32* %17
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = sdiv i32 %76, %80
%82 = load i32, i32* %17
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 %83
store i32 %81, i32* %84
%85 = load i32, i32* %17
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = load i32, i32* %17
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %90
store i32 %88, i32* %91
br label %118
92: ; preds = %61
%93 = load i32, i32* %17
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 %94
%96 = load i32, i32* %95
%97 = load i32, i32* %17
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %98
%100 = load i32, i32* %99
%101 = sdiv i32 %96, %100
%102 = add nsw i32 %101, 1
%103 = load i32, i32* %17
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 %104
store i32 %102, i32* %105
%106 = load i32, i32* %17
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 %107
%109 = load i32, i32* %108
%110 = load i32, i32* %17
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 %111
%113 = load i32, i32* %112
%114 = mul nsw i32 %109, %113
%115 = load i32, i32* %17
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %116
store i32 %114, i32* %117
br label %118
118: ; preds = %92, %72
br label %119
119: ; preds = %118
%120 = load i32, i32* %17
%121 = add nsw i32 %120, 1
store i32 %121, i32* %17
br label %58
122: ; preds = %58
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%124 = load i32, i32* %123
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%126 = load i32, i32* %125
%127 = call double** @allocate2d(i32 %124, i32 %126)
store double** %127, double*** %15
%128 = load double**, double*** %15
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%130 = load i32, i32* %129
%131 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%132 = load i32, i32* %131
%133 = call i32 @init2d(double** %128, i32 %130, i32 %132)
%134 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%135 = load i32, i32* %134
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%137 = load i32, i32* %136
%138 = call double** @allocate2d(i32 %135, i32 %137)
store double** %138, double*** %14
%139 = load double**, double*** %14
%140 = load double**, double*** %15
%141 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%142 = load i32, i32* %141
%143 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%144 = load i32, i32* %143
%145 = call i32 @copy2d(double** %139, double** %140, i32 %142, i32 %144)
%146 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%147 = load i32, i32* %146
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%149 = load i32, i32* %148
%150 = mul nsw i32 %147, %149
store i32 %150, i32* %18
%151 = load i32, i32* %18
%152 = call i32 @omp_set_num_threads(i32 %151)
store i32 0, i32* %19
store i32 0, i32* %20
store i32 0, i32* %21
%153 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%154 = call i32 (...) @omp_get_thread_num()
store i32 %154, i32* %22
store i32 0, i32* %27
%155 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%156 = load i32, i32* %155
%157 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%158 = load i32, i32* %157
%159 = sdiv i32 %156, %158
%160 = load i32, i32* %22
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%162 = load i32, i32* %161
%163 = srem i32 %160, %162
%164 = mul nsw i32 %159, %163
store i32 %164, i32* %23
%165 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%166 = load i32, i32* %165
%167 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%168 = load i32, i32* %167
%169 = sdiv i32 %166, %168
%170 = load i32, i32* %22
%171 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%172 = load i32, i32* %171
%173 = sdiv i32 %170, %172
%174 = mul nsw i32 %169, %173
store i32 %174, i32* %24
%175 = load i32, i32* %23
%176 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%177 = load i32, i32* %176
%178 = add nsw i32 %175, %177
%179 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%180 = load i32, i32* %179
%181 = icmp slt i32 %178, %180
br i1 %181, label %182, label %187
182: ; preds = %122
%183 = load i32, i32* %23
%184 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%185 = load i32, i32* %184
%186 = add nsw i32 %183, %185
br label %191
187: ; preds = %122
%188 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%189 = load i32, i32* %188
%190 = sub nsw i32 %189, 1
br label %191
191: ; preds = %187, %182
%192 = phi i32 [ %186, %182 ], [ %190, %187 ]
store i32 %192, i32* %25
%193 = load i32, i32* %24
%194 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%195 = load i32, i32* %194
%196 = add nsw i32 %193, %195
%197 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%198 = load i32, i32* %197
%199 = icmp slt i32 %196, %198
br i1 %199, label %200, label %205
200: ; preds = %191
%201 = load i32, i32* %24
%202 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%203 = load i32, i32* %202
%204 = add nsw i32 %201, %203
br label %209
205: ; preds = %191
%206 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%207 = load i32, i32* %206
%208 = sub nsw i32 %207, 1
br label %209
209: ; preds = %205, %200
%210 = phi i32 [ %204, %200 ], [ %208, %205 ]
store i32 %210, i32* %26
%211 = load i32, i32* %23
%212 = icmp eq i32 %211, 0
%213 = zext i1 %212 to i32
%214 = load i32, i32* %23
%215 = add nsw i32 %214, %213
store i32 %215, i32* %23
%216 = load i32, i32* %24
%217 = icmp eq i32 %216, 0
%218 = zext i1 %217 to i32
%219 = load i32, i32* %24
%220 = add nsw i32 %219, %218
store i32 %220, i32* %24
br label %221
221: ; preds = %278, %209
%222 = load i32, i32* %20
%223 = icmp ne i32 %222, 0
%224 = xor i1 %223, true
br i1 %224, label %225, label %282
225: ; preds = %221
%226 = load i32, i32* %21
%227 = add nsw i32 %226, 1
store i32 %227, i32* %21
%228 = call i32 @gettimeofday(%struct.timeval* %28, i32* null)
%229 = load double**, double*** %15
%230 = load double**, double*** %14
%231 = load i32, i32* %23
%232 = load i32, i32* %25
%233 = load i32, i32* %24
%234 = load i32, i32* %26
%235 = call i32 @jacobi(double** %229, double** %230, i32 %231, i32 %232, i32 %233, i32 %234)
%236 = call i32 @gettimeofday(%struct.timeval* %29, i32* null)
%237 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
%238 = load i64, i64* %237
%239 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 1
%240 = load i64, i64* %239
%241 = sub nsw i64 %238, %240
%242 = sitofp i64 %241 to double
%243 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 0
%244 = load double, double* %243
%245 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
%246 = load double, double* %245
%247 = fsub double %244, %246
%248 = call double @llvm.fmuladd.f64(double %247, double 0x3EB0C6F7A0B5ED8D, double %242)
%249 = load double, double* %11
%250 = fadd double %249, %248
store double %250, double* %11
%251 = load i32, i32* %21
%252 = srem i32 %251, 100
%253 = icmp eq i32 %252, 0
br i1 %253, label %254, label %262
254: ; preds = %225
%255 = load double**, double*** %15
%256 = load double**, double*** %14
%257 = load i32, i32* %23
%258 = load i32, i32* %25
%259 = load i32, i32* %24
%260 = load i32, i32* %26
%261 = call i32 @converge(double** %255, double** %256, i32 %257, i32 %258, i32 %259, i32 %260)
store i32 %261, i32* %27
br label %262
262: ; preds = %254, %225
%263 = load i32, i32* %27
%264 = load i32, i32* %19
%265 = add nsw i32 %264, %263
store i32 %265, i32* %19
%266 = load i32, i32* %21
%267 = srem i32 %266, 100
%268 = icmp eq i32 %267, 0
br i1 %268, label %269, label %278
269: ; preds = %262
%270 = load i32, i32* %22
%271 = icmp eq i32 %270, 0
br i1 %271, label %272, label %278
272: ; preds = %269
%273 = load i32, i32* %19
%274 = load i32, i32* %18
%275 = icmp eq i32 %273, %274
br i1 %275, label %276, label %277
276: ; preds = %272
store i32 1, i32* %20
br label %277
277: ; preds = %276, %272
br label %278
278: ; preds = %277, %269, %262
store i32 0, i32* %19
%279 = load double**, double*** %15
store double** %279, double*** %16
%280 = load double**, double*** %14
store double** %280, double*** %15
%281 = load double**, double*** %16
store double** %281, double*** %14
br label %221
282: ; preds = %221
%283 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%284 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%285 = load i64, i64* %284
%286 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%287 = load i64, i64* %286
%288 = sub nsw i64 %285, %287
%289 = sitofp i64 %288 to double
%290 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%291 = load double, double* %290
%292 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%293 = load double, double* %292
%294 = fsub double %291, %293
%295 = call double @llvm.fmuladd.f64(double %294, double 0x3EB0C6F7A0B5ED8D, double %289)
%296 = load double, double* %10
%297 = fadd double %296, %295
store double %297, double* %10
%298 = load i32, i32* %21
%299 = load double, double* %10
%300 = load double, double* %11
%301 = load i32, i32* %18
%302 = sitofp i32 %301 to double
%303 = fdiv double %300, %302
%304 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %298, double %299, double %303)
%305 = load double**, double*** %14
%306 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%307 = load i32, i32* %306
%308 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%309 = load i32, i32* %308
%310 = call i32 @fprint2d(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double** %305, i32 %307, i32 %309)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./execname X Y Px Py\0A\00"
@.str.1 = [60 x i8] c"Simple Jacobi - Iters: %d Time: %.3lf Computation: %.3lf\0A\00"
@.str.2 = [15 x i8] c"testjacobi.out\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = bitcast %struct.timeval* %3 to i8*
%8 = bitcast %struct.timeval* %4 to i8*
%9 = icmp eq i32 %0, 5
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 4
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = srem i32 %17, %23
%28 = icmp eq i32 %27, 0
%29 = sdiv i32 %17, %23
%30 = add nsw i32 %29, 1
%31 = mul nsw i32 %30, %23
%32 = select i1 %28, i32 %17, i32 %31
%33 = select i1 %28, i32 %29, i32 %30
%34 = srem i32 %20, %26
%35 = icmp eq i32 %34, 0
%36 = sdiv i32 %20, %26
%37 = add nsw i32 %36, 1
%38 = mul nsw i32 %37, %26
%39 = select i1 %35, i32 %20, i32 %38
%40 = select i1 %35, i32 %36, i32 %37
%41 = tail call double** @allocate2d(i32 %32, i32 %39)
%42 = tail call i32 @init2d(double** %41, i32 %17, i32 %20)
%43 = tail call double** @allocate2d(i32 %32, i32 %39)
%44 = tail call i32 @copy2d(double** %43, double** %41, i32 %17, i32 %20)
%45 = mul nsw i32 %26, %23
%46 = tail call i32 @omp_set_num_threads(i32 %45)
%47 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%48 = tail call i32 (...) @omp_get_thread_num()
%49 = bitcast %struct.timeval* %5 to i8*
%50 = bitcast %struct.timeval* %6 to i8*
%51 = sdiv i32 %32, %23
%52 = srem i32 %48, %23
%53 = mul nsw i32 %52, %51
%54 = sdiv i32 %39, %26
%55 = sdiv i32 %48, %23
%56 = mul nsw i32 %55, %54
%57 = add nsw i32 %33, %53
%58 = icmp slt i32 %57, %17
%59 = add nsw i32 %17, -1
%60 = select i1 %58, i32 %57, i32 %59
%61 = add nsw i32 %40, %56
%62 = icmp slt i32 %61, %20
%63 = add nsw i32 %20, -1
%64 = select i1 %62, i32 %61, i32 %63
%65 = icmp eq i32 %53, 0
%66 = zext i1 %65 to i32
%67 = add nsw i32 %53, %66
%68 = icmp eq i32 %56, 0
%69 = zext i1 %68 to i32
%70 = add nsw i32 %56, %69
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%75 = icmp eq i32 %48, 0
br label %76
76: ; preds = %14, %99
%77 = phi i32 [ 0, %14 ], [ %101, %99 ]
%78 = phi double [ 0.000000e+00, %14 ], [ %94, %99 ]
%79 = phi double** [ %43, %14 ], [ %81, %99 ]
%80 = phi i32 [ 0, %14 ], [ %82, %99 ]
%81 = phi double** [ %41, %14 ], [ %79, %99 ]
%82 = add nuw nsw i32 %80, 1
%83 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%84 = tail call i32 @jacobi(double** %81, double** %79, i32 %67, i32 %60, i32 %70, i32 %64)
%85 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%86 = load i64, i64* %71
%87 = load i64, i64* %72
%88 = sub nsw i64 %86, %87
%89 = sitofp i64 %88 to double
%90 = load double, double* %73
%91 = load double, double* %74
%92 = fsub double %90, %91
%93 = tail call double @llvm.fmuladd.f64(double %92, double 0x3EB0C6F7A0B5ED8D, double %89)
%94 = fadd double %78, %93
%95 = urem i32 %82, 100
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %76
%98 = tail call i32 @converge(double** %81, double** %79, i32 %67, i32 %60, i32 %70, i32 %64)
br label %99
99: ; preds = %97, %76
%100 = phi i1 [ %75, %97 ], [ false, %76 ]
%101 = phi i32 [ %98, %97 ], [ %77, %76 ]
%102 = icmp ne i32 %101, %45
%103 = xor i1 %100, true
%104 = select i1 %103, i1 true, i1 %102
br i1 %104, label %76, label %105
105: ; preds = %99
%106 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%107 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%108 = load i64, i64* %107
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%110 = load i64, i64* %109
%111 = sub nsw i64 %108, %110
%112 = sitofp i64 %111 to double
%113 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%114 = load double, double* %113
%115 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%116 = load double, double* %115
%117 = fsub double %114, %116
%118 = tail call double @llvm.fmuladd.f64(double %117, double 0x3EB0C6F7A0B5ED8D, double %112)
%119 = fadd double %118, 0.000000e+00
%120 = sitofp i32 %45 to double
%121 = fdiv double %94, %120
%122 = tail call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %82, double %119, double %121)
%123 = tail call i32 @fprint2d(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double** %81, i32 %17, i32 %20)
ret i32 0
}