#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 */
int /*<<< orphan*/ Jacobi(double **, double **, int, int, int, int);
double **allocate2d(int, int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ init2d(double **, int, int);
int /*<<< orphan*/ printf(char *, int, int, int, double, double);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int X, Y;
  double **u_current, **u_previous;
  double **swap;
  struct timeval tts, ttf;
  double time = 0;
  int t, converged = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: ./exec X (Y-optional)");
    exit(-1);
  } else if (argc == 2) {
    X = atoi(argv[1]);
    Y = X;
  } else {
    X = atoi(argv[1]);
    Y = atoi(argv[2]);
  }
  u_current = allocate2d(X, Y);
  u_previous = allocate2d(X, Y);
  init2d(u_current, X, Y);
  init2d(u_previous, X, Y);
  for (t = 0; t < 256; t++) {
    swap = u_previous;
    u_previous = u_current;
    u_current = swap;
    gettimeofday(&tts, NULL);
    Jacobi(u_previous, u_current, 1, X - 1, 1, Y - 1);
    gettimeofday(&ttf, NULL);
    time += (ttf.tv_sec - tts.tv_sec) + (ttf.tv_usec - tts.tv_usec) * 0.000001;
  }
  printf("Jacobi X %d Y %d Iter %d Time %lf midpoint %lf\n", X, Y, t - 1, time,
         u_current[X / 2][Y / 2]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d1 <main+0x51>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11f6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1216 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    121b <main+0x9b>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <allocate2d@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <allocate2d@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <init2d@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <init2d@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x100,-0x5c(%rbp)
jge    1300 <main+0x180>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%r9d
sub    $0x1,%r9d
mov    $0x1,%r8d
mov    %r8d,%edx
call   10a0 <Jacobi@plt>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xd20(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    125e <main+0xde>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%edi
cltd
idiv   %edi
mov    %eax,%edx
mov    -0x78(%rbp),%rax
movslq %edx,%rdx
mov    (%rax,%rdx,8),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%edi
cltd
idiv   %edi
mov    -0x6c(%rbp),%edx
mov    %eax,%edi
mov    -0x68(%rbp),%rax
movslq %edi,%rdi
movsd  (%rax,%rdi,8),%xmm1
lea    0xcca(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jle    12d9 <main+0x159>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    %eax,%ebp
cmp    $0x2,%ebx
je     11ba <main+0x3a>
mov    0x10(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %ebp,%esi
call   1050 <allocate2d@plt>
mov    %rax,%r13
mov    %r15d,%edi
mov    %ebp,%esi
call   1050 <allocate2d@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1070 <init2d@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1070 <init2d@plt>
mov    %r15,0x8(%rsp)
lea    -0x1(%r15),%r12d
mov    %rbp,(%rsp)
add    $0xffffffff,%ebp
xorpd  %xmm0,%xmm0
mov    $0x100,%r14d
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    %r13,%r15
mov    %rbx,%r13
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r12d,%ecx
mov    $0x1,%r8d
mov    %ebp,%r9d
call   10a0 <Jacobi@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x20(%rsp),%rax
sub    0x30(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x18(%rsp),%xmm1
subsd  0x28(%rsp),%xmm1
mulsd  0xd8a(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
mov    %r15,%rbx
add    $0xffffffff,%r14d
jne    1210 <main+0x90>
mov    0x8(%rsp),%rsi
mov    %esi,%eax
shr    $0x1f,%eax
add    %esi,%eax
sar    %eax
cltq
mov    0x0(%r13,%rax,8),%rax
mov    (%rsp),%rdx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
sar    %ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xd67(%rip),%rdi
mov    $0xff,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./exec X (Y-optional)\00"
@.str.1 = [48 x i8] c"Jacobi X %d Y %d Iter %d Time %lf midpoint %lf\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 double**
%10 = alloca double**
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %13
store i32 0, i32* %15
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
store i32 %30, i32* %7
br label %40
31: ; preds = %22
%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* %6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %7
br label %40
40: ; preds = %31, %25
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call double** @allocate2d(i32 %42, i32 %43)
store double** %44, double*** %8
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = call double** @allocate2d(i32 %45, i32 %46)
store double** %47, double*** %9
%48 = load double**, double*** %8
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = call i32 @init2d(double** %48, i32 %49, i32 %50)
%52 = load double**, double*** %9
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = call i32 @init2d(double** %52, i32 %53, i32 %54)
store i32 0, i32* %14
br label %56
56: ; preds = %86, %41
%57 = load i32, i32* %14
%58 = icmp slt i32 %57, 256
br i1 %58, label %59, label %89
59: ; preds = %56
%60 = load double**, double*** %9
store double** %60, double*** %10
%61 = load double**, double*** %8
store double** %61, double*** %9
%62 = load double**, double*** %10
store double** %62, double*** %8
%63 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%64 = load double**, double*** %9
%65 = load double**, double*** %8
%66 = load i32, i32* %6
%67 = sub nsw i32 %66, 1
%68 = load i32, i32* %7
%69 = sub nsw i32 %68, 1
%70 = call i32 @Jacobi(double** %64, double** %65, i32 1, i32 %67, i32 1, i32 %69)
%71 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%73 = load i64, i64* %72
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%75 = load i64, i64* %74
%76 = sub nsw i64 %73, %75
%77 = sitofp i64 %76 to double
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%79 = load double, double* %78
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%81 = load double, double* %80
%82 = fsub double %79, %81
%83 = call double @llvm.fmuladd.f64(double %82, double 0x3EB0C6F7A0B5ED8D, double %77)
%84 = load double, double* %13
%85 = fadd double %84, %83
store double %85, double* %13
br label %86
86: ; preds = %59
%87 = load i32, i32* %14
%88 = add nsw i32 %87, 1
store i32 %88, i32* %14
br label %56
89: ; preds = %56
%90 = load i32, i32* %6
%91 = load i32, i32* %7
%92 = load i32, i32* %14
%93 = sub nsw i32 %92, 1
%94 = load double, double* %13
%95 = load double**, double*** %8
%96 = load i32, i32* %6
%97 = sdiv i32 %96, 2
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double*, double** %95, i64 %98
%100 = load double*, double** %99
%101 = load i32, i32* %7
%102 = sdiv i32 %101, 2
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %100, i64 %103
%105 = load double, double* %104
%106 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %90, i32 %91, i32 %93, double %94, double %105)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./exec X (Y-optional)\00"
@.str.1 = [48 x i8] c"Jacobi X %d Y %d Iter %d Time %lf midpoint %lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = icmp eq i32 %0, 2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
br i1 %13, label %21, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
br label %21
21: ; preds = %12, %17
%22 = phi i32 [ %20, %17 ], [ %16, %12 ]
%23 = tail call double** @allocate2d(i32 %16, i32 %22)
%24 = tail call double** @allocate2d(i32 %16, i32 %22)
%25 = tail call i32 @init2d(double** %23, i32 %16, i32 %22)
%26 = tail call i32 @init2d(double** %24, i32 %16, i32 %22)
%27 = add nsw i32 %16, -1
%28 = add nsw i32 %22, -1
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
br label %33
33: ; preds = %21, %33
%34 = phi i32 [ 0, %21 ], [ %50, %33 ]
%35 = phi double [ 0.000000e+00, %21 ], [ %49, %33 ]
%36 = phi double** [ %24, %21 ], [ %37, %33 ]
%37 = phi double** [ %23, %21 ], [ %36, %33 ]
%38 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%39 = tail call i32 @Jacobi(double** %37, double** %36, i32 1, i32 %27, i32 1, i32 %28)
%40 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%41 = load i64, i64* %29
%42 = load i64, i64* %30
%43 = sub nsw i64 %41, %42
%44 = sitofp i64 %43 to double
%45 = load double, double* %31
%46 = load double, double* %32
%47 = fsub double %45, %46
%48 = tail call double @llvm.fmuladd.f64(double %47, double 0x3EB0C6F7A0B5ED8D, double %44)
%49 = fadd double %35, %48
%50 = add nuw nsw i32 %34, 1
%51 = icmp eq i32 %50, 256
br i1 %51, label %52, label %33
52: ; preds = %33
%53 = sdiv i32 %16, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double*, double** %36, i64 %54
%56 = load double*, double** %55
%57 = sdiv i32 %22, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %22, i32 255, double %49, double %60)
ret i32 0
}