#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 */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ acc_device_default;
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ jacobi_(int, int, double, double, double, double *,
                           double *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
double rand();
int /*<<< orphan*/ srand(int);
int main(int argc, char *argv[]) {
  int i, it;
  double mean;
  struct timeval tim;
  double start, end;
  if (argc != 4) {
    printf("Usage: %s <nx> <ny> <nt>\n", argv[0]);
    exit(1);
  }
  int nx = atoi(argv[1]);
  if (nx < 0) {
    printf("Value for "
           "nx"
           " is invalid: %d\n",
           nx);
    exit(1);
  };
  int ny = atoi(argv[2]);
  if (ny < 0) {
    printf("Value for "
           "ny"
           " is invalid: %d\n",
           ny);
    exit(1);
  };
  int nt = atoi(argv[3]);
  if (nt < 0) {
    printf("Value for "
           "nt"
           " is invalid: %d\n",
           nt);
    exit(1);
  };
  srand(17);
  double c0 = (double)(rand() / (double)RAND_MAX);
  double c1 = (double)(rand() / (double)RAND_MAX) / 4.;
  double c2 = (double)(rand() / (double)RAND_MAX) / 4.;
  printf("c0 = %f, c1 = %f, c2 = %f\n", c0, c1, c2);
  int szarray = nx * ny;
  unsigned int szarrayb = szarray * sizeof(double);
  double *w0 = (double *)malloc(szarrayb);
  double *w1 = (double *)malloc(szarrayb);
  if (!w0 || !w1) {
    printf("Error allocating memory for arrays: %p, %p\n", w0, w1);
    exit(1);
  }
  for (i = 0; i < szarray; i++) {
    w0[i] = (double)(rand() / (double)RAND_MAX);
    w1[i] = (double)(rand() / (double)RAND_MAX);
  }
  acc_init(acc_device_default);
  gettimeofday(&tim, NULL);
  start = tim.tv_sec + (tim.tv_usec / 1000000.0);
#pragma acc data create(w0 [0:szarray], w1 [0:szarray])
  {
#pragma acc update device(w0 [0:szarray], w1 [0:szarray])
      {for (it = 0; it < nt; it++){jacobi_(nx, ny, c0, c1, c2, w0, w1);
  double *w = w0;
  w0 = w1;
  w1 = w;
}
}
#pragma acc update host(w0 [0:szarray])
}
gettimeofday(&tim, NULL);
end = tim.tv_sec + (tim.tv_usec / 1000000.0);
mean = 0.0f;
for (i = 0; i < szarray; i++)
  mean += w0[i];
printf("Final mean = %f\n", mean / szarray);
printf("Time for computing: %.2f s\n", end - start);
free(w0);
free(w1);
return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11e2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1217 <main+0x77>
mov    -0x44(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    124c <main+0xac>
mov    -0x48(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1281 <main+0xe1>
mov    -0x4c(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x11,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2d4f(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2d33(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd3a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2d0b(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd12(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
lea    0xd74(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
imul   -0x48(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movslq -0x6c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1357 <main+0x1b7>
cmpq   $0x0,-0x80(%rbp)
jne    1377 <main+0x1d7>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    13e0 <main+0x240>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2c50(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x78(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2c2c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x80(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    137e <main+0x1de>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   1080 <acc_init@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xbfb(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    147b <main+0x2db>
mov    -0x44(%rbp),%edi
mov    -0x48(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
mov    -0x78(%rbp),%rdx
mov    -0x80(%rbp),%rcx
call   1090 <jacobi_@plt>
mov    -0x78(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1421 <main+0x281>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xb6e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    14e7 <main+0x347>
mov    -0x78(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14b6 <main+0x316>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x6c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xbcc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xbc5(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    14bb <main+0x31b>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
js     14d6 <main+0x336>
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
test   %eax,%eax
js     14df <main+0x33f>
mov    %ebp,(%rsp)
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
js     14eb <main+0x34b>
mov    $0x11,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
mov    0x2dd9(%rip),%r15
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xdc7(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   10c0 <rand@plt>
movapd %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
divsd  %xmm0,%xmm2
mulsd  0xda2(%rip),%xmm2
lea    0xe2c(%rip),%rdi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  %xmm2,0x38(%rsp)
mov    $0x3,%al
call   1040 <printf@plt>
mov    %r14d,0x4(%rsp)
mov    %r14d,%r12d
imul   (%rsp),%r12d
lea    0x0(,%r12,8),%r14d
mov    %r14d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1505 <main+0x365>
test   %r14,%r14
je     1505 <main+0x365>
mov    %r12d,%r13d
mov    %r12,0x30(%rsp)
test   %r12d,%r12d
jle    130b <main+0x16b>
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%r12,8)
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%r12,8)
add    $0x1,%r12
cmp    %r12,%r13
jne    12d0 <main+0x130>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1080 <acc_init@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x20(%rsp),%xmm0
movaps %xmm0,0x50(%rsp)
movsd  0x28(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
test   %ebp,%ebp
jle    1381 <main+0x1e1>
mov    %r14,%rax
mov    (%rsp),%r12d
mov    0x4(%rsp),%r15d
nopl   0x0(%rax)
mov    %rbx,%r14
mov    %rax,%rbx
mov    %r12d,%edi
mov    %r15d,%esi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x38(%rsp),%xmm2
mov    %r14,%rdx
mov    %rax,%rcx
call   1090 <jacobi_@plt>
mov    %r14,%rax
add    $0xffffffff,%ebp
jne    1350 <main+0x1b0>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movapd 0x20(%rsp),%xmm1
mov    0x30(%rsp),%rsi
test   %esi,%esi
jle    13c0 <main+0x220>
lea    -0x1(%r13),%rcx
mov    %r13d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
movapd 0x50(%rsp),%xmm2
movapd 0x40(%rsp),%xmm3
jae    13d2 <main+0x232>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1418 <main+0x278>
xorpd  %xmm0,%xmm0
movapd 0x50(%rsp),%xmm2
movapd 0x40(%rsp),%xmm3
jmp    143e <main+0x29e>
and    $0xfffffff8,%r13d
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopl   0x0(%rax)
addsd  (%rbx,%rcx,8),%xmm0
addsd  0x8(%rbx,%rcx,8),%xmm0
addsd  0x10(%rbx,%rcx,8),%xmm0
addsd  0x18(%rbx,%rcx,8),%xmm0
addsd  0x20(%rbx,%rcx,8),%xmm0
addsd  0x28(%rbx,%rcx,8),%xmm0
addsd  0x30(%rbx,%rcx,8),%xmm0
addsd  0x38(%rbx,%rcx,8),%xmm0
add    $0x8,%rcx
cmp    %rcx,%r13
jne    13e0 <main+0x240>
test   %rax,%rax
je     143e <main+0x29e>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1430 <main+0x290>
movapd %xmm1,%xmm4
shufpd $0x1,%xmm3,%xmm1
divpd  0xbc1(%rip),%xmm1
unpcklpd %xmm2,%xmm4
addpd  %xmm1,%xmm4
movapd %xmm4,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
divsd  %xmm1,%xmm0
lea    0xc69(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movapd 0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xc56(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xb5b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xb5d(%rip),%rdi
jmp    14f2 <main+0x352>
lea    0xb71(%rip),%rdi
mov    %r14d,%esi
jmp    14f4 <main+0x354>
lea    0xb82(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xba0(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [26 x i8] c"Usage: %s <nx> <ny> <nt>\0A\00"
@.str.1 = [29 x i8] c"Value for nx is invalid: %d\0A\00"
@.str.2 = [29 x i8] c"Value for ny is invalid: %d\0A\00"
@.str.3 = [29 x i8] c"Value for nt is invalid: %d\0A\00"
@RAND_MAX = global i64 0
@.str.4 = [27 x i8] c"c0 = %f, c1 = %f, c2 = %f\0A\00"
@.str.5 = [44 x i8] c"Error allocating memory for arrays: %p, %p\0A\00"
@acc_device_default = global i32 0
@.str.6 = [17 x i8] c"Final mean = %f\0A\00"
@.str.7 = [28 x i8] c"Time for computing: %.2f s\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 double
%9 = alloca %struct.timeval
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 4
br i1 %24, label %25, label %31
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* %12
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %31
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %13
%47 = load i32, i32* %13
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* %13
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %14
%58 = load i32, i32* %14
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* %14
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %53
%65 = call i32 @srand(i32 17)
%66 = call double (...) @rand()
%67 = load i64, i64* @RAND_MAX
%68 = sitofp i64 %67 to double
%69 = fdiv double %66, %68
store double %69, double* %15
%70 = call double (...) @rand()
%71 = load i64, i64* @RAND_MAX
%72 = sitofp i64 %71 to double
%73 = fdiv double %70, %72
%74 = fdiv double %73, 4.000000e+00
store double %74, double* %16
%75 = call double (...) @rand()
%76 = load i64, i64* @RAND_MAX
%77 = sitofp i64 %76 to double
%78 = fdiv double %75, %77
%79 = fdiv double %78, 4.000000e+00
store double %79, double* %17
%80 = load double, double* %15
%81 = load double, double* %16
%82 = load double, double* %17
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %80, double %81, double %82)
%84 = load i32, i32* %12
%85 = load i32, i32* %13
%86 = mul nsw i32 %84, %85
store i32 %86, i32* %18
%87 = load i32, i32* %18
%88 = sext i32 %87 to i64
%89 = mul i64 %88, 8
%90 = trunc i64 %89 to i32
store i32 %90, i32* %19
%91 = load i32, i32* %19
%92 = call i64 @malloc(i32 %91)
%93 = inttoptr i64 %92 to double*
store double* %93, double** %20
%94 = load i32, i32* %19
%95 = call i64 @malloc(i32 %94)
%96 = inttoptr i64 %95 to double*
store double* %96, double** %21
%97 = load double*, double** %20
%98 = icmp ne double* %97, null
br i1 %98, label %99, label %102
99: ; preds = %64
%100 = load double*, double** %21
%101 = icmp ne double* %100, null
br i1 %101, label %107, label %102
102: ; preds = %99, %64
%103 = load double*, double** %20
%104 = load double*, double** %21
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), double* %103, double* %104)
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %99
store i32 0, i32* %6
br label %108
108: ; preds = %129, %107
%109 = load i32, i32* %6
%110 = load i32, i32* %18
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %132
112: ; preds = %108
%113 = call double (...) @rand()
%114 = load i64, i64* @RAND_MAX
%115 = sitofp i64 %114 to double
%116 = fdiv double %113, %115
%117 = load double*, double** %20
%118 = load i32, i32* %6
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %117, i64 %119
store double %116, double* %120
%121 = call double (...) @rand()
%122 = load i64, i64* @RAND_MAX
%123 = sitofp i64 %122 to double
%124 = fdiv double %121, %123
%125 = load double*, double** %21
%126 = load i32, i32* %6
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
store double %124, double* %128
br label %129
129: ; preds = %112
%130 = load i32, i32* %6
%131 = add nsw i32 %130, 1
store i32 %131, i32* %6
br label %108
132: ; preds = %108
%133 = load i32, i32* @acc_device_default
%134 = call i32 @acc_init(i32 %133)
%135 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%136 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%137 = load double, double* %136
%138 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%139 = load double, double* %138
%140 = fdiv double %139, 1.000000e+06
%141 = fadd double %137, %140
store double %141, double* %10
store i32 0, i32* %7
br label %142
142: ; preds = %158, %132
%143 = load i32, i32* %7
%144 = load i32, i32* %14
%145 = icmp slt i32 %143, %144
br i1 %145, label %146, label %161
146: ; preds = %142
%147 = load i32, i32* %12
%148 = load i32, i32* %13
%149 = load double, double* %15
%150 = load double, double* %16
%151 = load double, double* %17
%152 = load double*, double** %20
%153 = load double*, double** %21
%154 = call i32 @jacobi_(i32 %147, i32 %148, double %149, double %150, double %151, double* %152, double* %153)
%155 = load double*, double** %20
store double* %155, double** %22
%156 = load double*, double** %21
store double* %156, double** %20
%157 = load double*, double** %22
store double* %157, double** %21
br label %158
158: ; preds = %146
%159 = load i32, i32* %7
%160 = add nsw i32 %159, 1
store i32 %160, i32* %7
br label %142
161: ; preds = %142
%162 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%163 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%164 = load double, double* %163
%165 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%166 = load double, double* %165
%167 = fdiv double %166, 1.000000e+06
%168 = fadd double %164, %167
store double %168, double* %11
store double 0.000000e+00, double* %8
store i32 0, i32* %6
br label %169
169: ; preds = %181, %161
%170 = load i32, i32* %6
%171 = load i32, i32* %18
%172 = icmp slt i32 %170, %171
br i1 %172, label %173, label %184
173: ; preds = %169
%174 = load double*, double** %20
%175 = load i32, i32* %6
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds double, double* %174, i64 %176
%178 = load double, double* %177
%179 = load double, double* %8
%180 = fadd double %179, %178
store double %180, double* %8
br label %181
181: ; preds = %173
%182 = load i32, i32* %6
%183 = add nsw i32 %182, 1
store i32 %183, i32* %6
br label %169
184: ; preds = %169
%185 = load double, double* %8
%186 = load i32, i32* %18
%187 = sitofp i32 %186 to double
%188 = fdiv double %185, %187
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), double %188)
%190 = load double, double* %11
%191 = load double, double* %10
%192 = fsub double %190, %191
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), double %192)
%194 = load double*, double** %20
%195 = call i32 @free(double* %194)
%196 = load double*, double** %21
%197 = call i32 @free(double* %196)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [26 x i8] c"Usage: %s <nx> <ny> <nt>\0A\00"
@.str.1 = [29 x i8] c"Value for nx is invalid: %d\0A\00"
@.str.2 = [29 x i8] c"Value for ny is invalid: %d\0A\00"
@.str.3 = [29 x i8] c"Value for nt is invalid: %d\0A\00"
@RAND_MAX = global i64 0
@.str.4 = [27 x i8] c"c0 = %f, c1 = %f, c2 = %f\0A\00"
@.str.5 = [44 x i8] c"Error allocating memory for arrays: %p, %p\0A\00"
@acc_device_default = global i32 0
@.str.6 = [17 x i8] c"Final mean = %f\0A\00"
@.str.7 = [28 x i8] c"Time for computing: %.2f s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timeval*
%5 = bitcast <2 x double>* %3 to i8*
%6 = icmp eq i32 %0, 4
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = tail call i32 @srand(i32 17)
%37 = tail call double (...) @rand()
%38 = load i64, i64* @RAND_MAX
%39 = sitofp i64 %38 to double
%40 = fdiv double %37, %39
%41 = tail call double (...) @rand()
%42 = load i64, i64* @RAND_MAX
%43 = sitofp i64 %42 to double
%44 = fdiv double %41, %43
%45 = fmul double %44, 2.500000e-01
%46 = tail call double (...) @rand()
%47 = load i64, i64* @RAND_MAX
%48 = sitofp i64 %47 to double
%49 = fdiv double %46, %48
%50 = fmul double %49, 2.500000e-01
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %40, double %45, double %50)
%52 = mul nsw i32 %22, %14
%53 = shl i32 %52, 3
%54 = tail call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to double*
%56 = tail call i64 @malloc(i32 %53)
%57 = inttoptr i64 %56 to double*
%58 = icmp ne i64 %54, 0
%59 = icmp ne i64 %56, 0
%60 = select i1 %58, i1 %59, i1 false
br i1 %60, label %61, label %65
61: ; preds = %35
%62 = icmp sgt i32 %52, 0
br i1 %62, label %63, label %82
63: ; preds = %61
%64 = zext i32 %52 to i64
br label %68
65: ; preds = %35
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), double* %55, double* %57)
%67 = tail call i32 @exit(i32 1)
unreachable
68: ; preds = %63, %68
%69 = phi i64 [ 0, %63 ], [ %80, %68 ]
%70 = tail call double (...) @rand()
%71 = load i64, i64* @RAND_MAX
%72 = sitofp i64 %71 to double
%73 = fdiv double %70, %72
%74 = getelementptr inbounds double, double* %55, i64 %69
store double %73, double* %74
%75 = tail call double (...) @rand()
%76 = load i64, i64* @RAND_MAX
%77 = sitofp i64 %76 to double
%78 = fdiv double %75, %77
%79 = getelementptr inbounds double, double* %57, i64 %69
store double %78, double* %79
%80 = add nuw nsw i64 %69, 1
%81 = icmp eq i64 %80, %64
br i1 %81, label %82, label %68
82: ; preds = %68, %61
%83 = load i32, i32* @acc_device_default
%84 = tail call i32 @acc_init(i32 %83)
%85 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%86 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 0
%87 = load double, double* %86
%88 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 1
%89 = load double, double* %88
%90 = icmp sgt i32 %30, 0
br i1 %90, label %91, label %98
91: ; preds = %82, %91
%92 = phi double* [ %93, %91 ], [ %57, %82 ]
%93 = phi double* [ %92, %91 ], [ %55, %82 ]
%94 = phi i32 [ %96, %91 ], [ 0, %82 ]
%95 = tail call i32 @jacobi_(i32 %14, i32 %22, double %40, double %45, double %50, double* %93, double* %92)
%96 = add nuw nsw i32 %94, 1
%97 = icmp eq i32 %96, %30
br i1 %97, label %98, label %91
98: ; preds = %91, %82
%99 = phi double* [ %55, %82 ], [ %92, %91 ]
%100 = phi double* [ %57, %82 ], [ %93, %91 ]
%101 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%102 = load <2 x double>, <2 x double>* %3
br i1 %62, label %103, label %163
103: ; preds = %98
%104 = zext i32 %52 to i64
%105 = add nsw i64 %104, -1
%106 = and i64 %104, 7
%107 = icmp ult i64 %105, 7
br i1 %107, label %148, label %108
108: ; preds = %103
%109 = and i64 %104, 4294967288
br label %110
110: ; preds = %110, %108
%111 = phi i64 [ 0, %108 ], [ %145, %110 ]
%112 = phi double [ 0.000000e+00, %108 ], [ %144, %110 ]
%113 = phi i64 [ 0, %108 ], [ %146, %110 ]
%114 = getelementptr inbounds double, double* %99, i64 %111
%115 = load double, double* %114
%116 = fadd double %112, %115
%117 = or i64 %111, 1
%118 = getelementptr inbounds double, double* %99, i64 %117
%119 = load double, double* %118
%120 = fadd double %116, %119
%121 = or i64 %111, 2
%122 = getelementptr inbounds double, double* %99, i64 %121
%123 = load double, double* %122
%124 = fadd double %120, %123
%125 = or i64 %111, 3
%126 = getelementptr inbounds double, double* %99, i64 %125
%127 = load double, double* %126
%128 = fadd double %124, %127
%129 = or i64 %111, 4
%130 = getelementptr inbounds double, double* %99, i64 %129
%131 = load double, double* %130
%132 = fadd double %128, %131
%133 = or i64 %111, 5
%134 = getelementptr inbounds double, double* %99, i64 %133
%135 = load double, double* %134
%136 = fadd double %132, %135
%137 = or i64 %111, 6
%138 = getelementptr inbounds double, double* %99, i64 %137
%139 = load double, double* %138
%140 = fadd double %136, %139
%141 = or i64 %111, 7
%142 = getelementptr inbounds double, double* %99, i64 %141
%143 = load double, double* %142
%144 = fadd double %140, %143
%145 = add nuw nsw i64 %111, 8
%146 = add i64 %113, 8
%147 = icmp eq i64 %146, %109
br i1 %147, label %148, label %110
148: ; preds = %110, %103
%149 = phi double [ undef, %103 ], [ %144, %110 ]
%150 = phi i64 [ 0, %103 ], [ %145, %110 ]
%151 = phi double [ 0.000000e+00, %103 ], [ %144, %110 ]
%152 = icmp eq i64 %106, 0
br i1 %152, label %163, label %153
153: ; preds = %148, %153
%154 = phi i64 [ %160, %153 ], [ %150, %148 ]
%155 = phi double [ %159, %153 ], [ %151, %148 ]
%156 = phi i64 [ %161, %153 ], [ 0, %148 ]
%157 = getelementptr inbounds double, double* %99, i64 %154
%158 = load double, double* %157
%159 = fadd double %155, %158
%160 = add nuw nsw i64 %154, 1
%161 = add i64 %156, 1
%162 = icmp eq i64 %161, %106
br i1 %162, label %163, label %153
163: ; preds = %148, %153, %98
%164 = phi double [ 0.000000e+00, %98 ], [ %149, %148 ], [ %159, %153 ]
%165 = shufflevector <2 x double> %102, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%166 = insertelement <2 x double> %165, double %89, i64 1
%167 = fdiv <2 x double> %166, <double 1.000000e+06, double 1.000000e+06>
%168 = insertelement <2 x double> %102, double %87, i64 1
%169 = fadd <2 x double> %168, %167
%170 = sitofp i32 %52 to double
%171 = fdiv double %164, %170
%172 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), double %171)
%173 = shufflevector <2 x double> %169, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%174 = fsub <2 x double> %169, %173
%175 = extractelement <2 x double> %174, i64 0
%176 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), double %175)
%177 = tail call i32 @free(double* %99)
%178 = tail call i32 @free(double* %100)
ret i32 0
}