#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*/ GaussSeidel(double **, double **, int, int, int, int,
                               double);
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 sin(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;
  double omega;
  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);
  omega = 2.0 / (1 + sin(3.14 / X));
  for (t = 0; t < 256; t++) {
    swap = u_previous;
    u_previous = u_current;
    u_current = swap;
    gettimeofday(&tts, NULL);
    GaussSeidel(u_previous, u_current, 1, X - 1, 1, Y - 1, omega);
    gettimeofday(&ttf, NULL);
    time += (ttf.tv_sec - tts.tv_sec) + (ttf.tv_usec - tts.tv_usec) * 0.000001;
  }
  printf("GaussSeidelSOR 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    11e1 <main+0x51>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1206 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1226 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    122b <main+0x9b>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <allocate2d@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <allocate2d@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <init2d@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <init2d@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xd94(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1080 <sin@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xd74(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x100,-0x5c(%rbp)
jge    1343 <main+0x1b3>
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   1050 <gettimeofday@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%r9d
sub    $0x1,%r9d
movsd  -0x68(%rbp),%xmm0
mov    $0x1,%r8d
mov    %r8d,%edx
call   1030 <GaussSeidel@plt>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xced(%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    129c <main+0x10c>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%edi
cltd
idiv   %edi
mov    %eax,%edx
mov    -0x80(%rbp),%rax
movslq %edx,%rdx
mov    (%rax,%rdx,8),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%edi
cltd
idiv   %edi
mov    -0x74(%rbp),%edx
mov    %eax,%edi
mov    -0x70(%rbp),%rax
movslq %edi,%rdi
movsd  (%rax,%rdi,8),%xmm1
lea    0xc97(%rip),%rdi
call   1040 <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    $0x48,%rsp
cmp    $0x1,%edi
jle    1324 <main+0x194>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    %eax,%r13d
cmp    $0x2,%ebx
je     11cb <main+0x3b>
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r13d
mov    %ebp,%edi
mov    %r13d,%esi
call   1060 <allocate2d@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r13d,%esi
call   1060 <allocate2d@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1090 <init2d@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1090 <init2d@plt>
cvtsi2sd %ebp,%xmm1
movsd  0xdf5(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1080 <sin@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xde2(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
mov    %rbp,0x10(%rsp)
lea    -0x1(%rbp),%r12d
mov    %r13,0x8(%rsp)
add    $0xffffffff,%r13d
xorpd  %xmm0,%xmm0
mov    $0x100,%r14d
nopl   0x0(%rax)
movsd  %xmm0,0x20(%rsp)
mov    %r15,%rbp
mov    %rbx,%r15
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %r12d,%ecx
mov    $0x1,%r8d
mov    %r13d,%r9d
movsd  0x18(%rsp),%xmm0
call   1030 <GaussSeidel@plt>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x30(%rsp),%rax
sub    0x40(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x28(%rsp),%xmm1
subsd  0x38(%rsp),%xmm1
mulsd  0xd54(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
mov    %rbp,%rbx
add    $0xffffffff,%r14d
jne    1250 <main+0xc0>
mov    0x10(%rsp),%rsi
mov    %esi,%eax
shr    $0x1f,%eax
add    %esi,%eax
sar    %eax
cltq
mov    0x0(%rbp,%rax,8),%rax
mov    0x8(%rsp),%rdx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
sar    %ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xd2c(%rip),%rdi
mov    $0xff,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <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 = [56 x i8] c"GaussSeidelSOR 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
%16 = alloca double
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
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
store i32 %31, i32* %7
br label %41
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %6
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %7
br label %41
41: ; preds = %32, %26
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = call double** @allocate2d(i32 %43, i32 %44)
store double** %45, double*** %8
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = call double** @allocate2d(i32 %46, i32 %47)
store double** %48, double*** %9
%49 = load double**, double*** %8
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call i32 @init2d(double** %49, i32 %50, i32 %51)
%53 = load double**, double*** %9
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = call i32 @init2d(double** %53, i32 %54, i32 %55)
%57 = load i32, i32* %6
%58 = sitofp i32 %57 to double
%59 = fdiv double 3.140000e+00, %58
%60 = call i32 @sin(double %59)
%61 = add nsw i32 1, %60
%62 = sitofp i32 %61 to double
%63 = fdiv double 2.000000e+00, %62
store double %63, double* %16
store i32 0, i32* %14
br label %64
64: ; preds = %95, %42
%65 = load i32, i32* %14
%66 = icmp slt i32 %65, 256
br i1 %66, label %67, label %98
67: ; preds = %64
%68 = load double**, double*** %9
store double** %68, double*** %10
%69 = load double**, double*** %8
store double** %69, double*** %9
%70 = load double**, double*** %10
store double** %70, double*** %8
%71 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%72 = load double**, double*** %9
%73 = load double**, double*** %8
%74 = load i32, i32* %6
%75 = sub nsw i32 %74, 1
%76 = load i32, i32* %7
%77 = sub nsw i32 %76, 1
%78 = load double, double* %16
%79 = call i32 @GaussSeidel(double** %72, double** %73, i32 1, i32 %75, i32 1, i32 %77, double %78)
%80 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%82 = load i64, i64* %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%84 = load i64, i64* %83
%85 = sub nsw i64 %82, %84
%86 = sitofp i64 %85 to double
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%88 = load double, double* %87
%89 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%90 = load double, double* %89
%91 = fsub double %88, %90
%92 = call double @llvm.fmuladd.f64(double %91, double 0x3EB0C6F7A0B5ED8D, double %86)
%93 = load double, double* %13
%94 = fadd double %93, %92
store double %94, double* %13
br label %95
95: ; preds = %67
%96 = load i32, i32* %14
%97 = add nsw i32 %96, 1
store i32 %97, i32* %14
br label %64
98: ; preds = %64
%99 = load i32, i32* %6
%100 = load i32, i32* %7
%101 = load i32, i32* %14
%102 = sub nsw i32 %101, 1
%103 = load double, double* %13
%104 = load double**, double*** %8
%105 = load i32, i32* %6
%106 = sdiv i32 %105, 2
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double*, double** %104, i64 %107
%109 = load double*, double** %108
%110 = load i32, i32* %7
%111 = sdiv i32 %110, 2
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds double, double* %109, i64 %112
%114 = load double, double* %113
%115 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %99, i32 %100, i32 %102, double %103, double %114)
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 = [56 x i8] c"GaussSeidelSOR 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 = sitofp i32 %16 to double
%28 = fdiv double 3.140000e+00, %27
%29 = tail call i32 @sin(double %28)
%30 = add nsw i32 %29, 1
%31 = sitofp i32 %30 to double
%32 = fdiv double 2.000000e+00, %31
%33 = add nsw i32 %16, -1
%34 = add nsw i32 %22, -1
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
br label %39
39: ; preds = %21, %39
%40 = phi i32 [ 0, %21 ], [ %56, %39 ]
%41 = phi double [ 0.000000e+00, %21 ], [ %55, %39 ]
%42 = phi double** [ %23, %21 ], [ %43, %39 ]
%43 = phi double** [ %24, %21 ], [ %42, %39 ]
%44 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%45 = tail call i32 @GaussSeidel(double** %42, double** %43, i32 1, i32 %33, i32 1, i32 %34, double %32)
%46 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%47 = load i64, i64* %35
%48 = load i64, i64* %36
%49 = sub nsw i64 %47, %48
%50 = sitofp i64 %49 to double
%51 = load double, double* %37
%52 = load double, double* %38
%53 = fsub double %51, %52
%54 = tail call double @llvm.fmuladd.f64(double %53, double 0x3EB0C6F7A0B5ED8D, double %50)
%55 = fadd double %41, %54
%56 = add nuw nsw i32 %40, 1
%57 = icmp eq i32 %56, 256
br i1 %57, label %58, label %39
58: ; preds = %39
%59 = sdiv i32 %16, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double*, double** %43, i64 %60
%62 = load double*, double** %61
%63 = sdiv i32 %22, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %62, i64 %64
%66 = load double, double* %65
%67 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %22, i32 255, double %55, double %66)
ret i32 0
}