#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*/ laplacian(int, int, int, 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, j, k, it;
  double mean;
  struct timeval tim;
  double start, end;
  if (argc != 5) {
    printf("Usage: %s <nx> <ny> <ns> <nt>\n", argv[0]);
    exit(1);
  }
  srand(17);
  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 ns = atoi(argv[3]);
  if (ns < 0) {
    printf("Value for "
           "ns"
           " is invalid: %d\n",
           ns);
    exit(1);
  };
  int nt = atoi(argv[4]);
  if (nt < 0) {
    printf("Value for "
           "nt"
           " is invalid: %d\n",
           nt);
    exit(1);
  };
  double alpha = (double)(rand() / (double)RAND_MAX);
  double beta = (double)(rand() / (double)RAND_MAX);
  printf("alpha = %f, beta = %f\n", alpha, beta);
  unsigned int szarray = (unsigned int)nx * ny * ns;
  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++){laplacian(nx, ny, ns, alpha, beta, 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   $0x5,-0x8(%rbp)
je     11e2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x11,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1221 <main+0x81>
mov    -0x4c(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    1256 <main+0xb6>
mov    -0x50(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    128b <main+0xeb>
mov    -0x54(%rbp),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    12c0 <main+0x120>
mov    -0x58(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2d1a(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2cfe(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
lea    0xd92(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%eax
imul   -0x50(%rbp),%eax
imul   -0x54(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
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     1356 <main+0x1b6>
cmpq   $0x0,-0x80(%rbp)
jne    1376 <main+0x1d6>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jae    13df <main+0x23f>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    0x2c51(%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    0x2c2d(%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    137d <main+0x1dd>
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
call   1080 <acc_init@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xbf4(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1478 <main+0x2d8>
mov    -0x4c(%rbp),%edi
mov    -0x50(%rbp),%esi
mov    -0x54(%rbp),%edx
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mov    -0x78(%rbp),%rcx
mov    -0x80(%rbp),%r8
call   10b0 <laplacian@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    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1420 <main+0x280>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xb69(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jae    14e4 <main+0x344>
mov    -0x78(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14b3 <main+0x313>
movsd  -0x28(%rbp),%xmm0
mov    -0x6c(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
lea    0xbe2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
lea    0xbdb(%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    $0x78,%rsp
mov    %rsi,%rbx
cmp    $0x5,%edi
jne    14cc <main+0x32c>
mov    $0x11,%edi
call   1060 <srand@plt>
mov    0x8(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
test   %eax,%eax
js     14e7 <main+0x347>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
js     14f3 <main+0x353>
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
test   %eax,%eax
js     14fc <main+0x35c>
mov    %ebp,0xc(%rsp)
mov    0x20(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1508 <main+0x368>
xor    %eax,%eax
call   10c0 <rand@plt>
mov    0x2dc4(%rip),%r13
cvtsi2sdq 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   10c0 <rand@plt>
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%r13),%xmm0
divsd  %xmm0,%xmm1
lea    0xe50(%rip),%rdi
movsd  0x20(%rsp),%xmm0
movsd  %xmm1,0x48(%rsp)
mov    $0x2,%al
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%r12d
mov    %r14d,0x14(%rsp)
imul   %r14d,%r12d
mov    %r15d,0x10(%rsp)
imul   %r15d,%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     1522 <main+0x382>
test   %r14,%r14
je     1522 <main+0x382>
mov    %r12d,%r15d
mov    %r12,0x40(%rsp)
test   %r12d,%r12d
je     12fd <main+0x15d>
xor    %r12d,%r12d
nop
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%r12,8)
xor    %eax,%eax
call   10c0 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%r12,8)
add    $0x1,%r12
cmp    %r12,%r15
jne    12c0 <main+0x120>
mov    %r15,0x18(%rsp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1080 <acc_init@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x30(%rsp),%xmm0
movaps %xmm0,0x60(%rsp)
movsd  0x38(%rsp),%xmm0
movapd %xmm0,0x50(%rsp)
test   %ebp,%ebp
jle    137e <main+0x1de>
mov    %r14,%rax
mov    0x14(%rsp),%r15d
mov    0xc(%rsp),%r13d
mov    0x10(%rsp),%r12d
nopl   0x0(%rax)
mov    %rbx,%r14
mov    %rax,%rbx
mov    %r15d,%edi
mov    %r13d,%esi
mov    %r12d,%edx
movsd  0x20(%rsp),%xmm0
movsd  0x48(%rsp),%xmm1
mov    %r14,%rcx
mov    %rax,%r8
call   10b0 <laplacian@plt>
mov    %r14,%rax
add    $0xffffffff,%ebp
jne    1350 <main+0x1b0>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movapd 0x30(%rsp),%xmm1
cmpl   $0x0,0x40(%rsp)
je     13bf <main+0x21f>
mov    0x18(%rsp),%rsi
lea    -0x1(%rsi),%rcx
mov    %esi,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
movapd 0x60(%rsp),%xmm2
movapd 0x50(%rsp),%xmm3
jae    13d6 <main+0x236>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    1428 <main+0x288>
xorpd  %xmm0,%xmm0
mov    0x18(%rsp),%rsi
movapd 0x60(%rsp),%xmm2
movapd 0x50(%rsp),%xmm3
jmp    144e <main+0x2ae>
mov    %esi,%edx
and    $0xfffffff8,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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,%rdx
jne    13f0 <main+0x250>
test   %rax,%rax
je     144e <main+0x2ae>
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    1440 <main+0x2a0>
movapd %xmm1,%xmm4
shufpd $0x1,%xmm3,%xmm1
divpd  0xba1(%rip),%xmm1
unpcklpd %xmm2,%xmm4
addpd  %xmm1,%xmm4
movapd %xmm4,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %rsi,%xmm1
divsd  %xmm1,%xmm0
lea    0xc66(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
lea    0xc53(%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    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xb3a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xb41(%rip),%rdi
mov    %r14d,%esi
jmp    1511 <main+0x371>
lea    0xb52(%rip),%rdi
jmp    150f <main+0x36f>
lea    0xb66(%rip),%rdi
mov    %r15d,%esi
jmp    1511 <main+0x371>
lea    0xb77(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xb91(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

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