#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*/ BlackSOR(double **, double **, int, int, int, int, double);
int /*<<< orphan*/ RedSOR(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);
    RedSOR(u_previous, u_current, 1, X - 1, 1, Y - 1, omega);
    BlackSOR(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("RedBlackSOR 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    11f1 <main+0x51>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1216 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1236 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    123b <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   1090 <init2d@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <init2d@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xd84(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1070 <sin@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xd64(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x100,-0x5c(%rbp)
jge    137c <main+0x1dc>
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
movsd  -0x68(%rbp),%xmm0
mov    $0x1,%r8d
mov    %r8d,%edx
call   10a0 <RedSOR@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   1080 <BlackSOR@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  0xcb4(%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    12ac <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    0xc5e(%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    $0x48,%rsp
cmp    $0x1,%edi
jle    1355 <main+0x1b5>
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%ebp
cmp    $0x2,%r15d
je     11db <main+0x3b>
mov    0x10(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <allocate2d@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <allocate2d@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1090 <init2d@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1090 <init2d@plt>
cvtsi2sd %ebx,%xmm1
movsd  0xde9(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1070 <sin@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdd6(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,0x18(%rsp)
lea    -0x1(%rbx),%r12d
mov    %rbp,0x10(%rsp)
add    $0xffffffff,%ebp
xorpd  %xmm0,%xmm0
mov    $0x100,%r15d
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
mov    %r13,%rbx
mov    %r14,%r13
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r12d,%ecx
mov    $0x1,%r8d
mov    %ebp,%r9d
movsd  0x8(%rsp),%xmm0
call   10a0 <RedSOR@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r12d,%ecx
mov    $0x1,%r8d
mov    %ebp,%r9d
movsd  0x8(%rsp),%xmm0
call   1080 <BlackSOR@plt>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1040 <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  0xd22(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
mov    %rbx,%r14
add    $0xffffffff,%r15d
jne    1260 <main+0xc0>
mov    0x18(%rsp),%rsi
mov    %esi,%eax
shr    $0x1f,%eax
add    %esi,%eax
sar    %eax
cltq
mov    (%rbx,%rax,8),%rax
mov    0x10(%rsp),%rdx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
sar    %ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xcfb(%rip),%rdi
mov    $0xff,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <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 = [53 x i8] c"RedBlackSOR 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 = %103, %42
%65 = load i32, i32* %14
%66 = icmp slt i32 %65, 256
br i1 %66, label %67, label %106
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 @RedSOR(double** %72, double** %73, i32 1, i32 %75, i32 1, i32 %77, double %78)
%80 = load double**, double*** %9
%81 = load double**, double*** %8
%82 = load i32, i32* %6
%83 = sub nsw i32 %82, 1
%84 = load i32, i32* %7
%85 = sub nsw i32 %84, 1
%86 = load double, double* %16
%87 = call i32 @BlackSOR(double** %80, double** %81, i32 1, i32 %83, i32 1, i32 %85, double %86)
%88 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%89 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%90 = load i64, i64* %89
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%92 = load i64, i64* %91
%93 = sub nsw i64 %90, %92
%94 = sitofp i64 %93 to double
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%96 = load double, double* %95
%97 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%98 = load double, double* %97
%99 = fsub double %96, %98
%100 = call double @llvm.fmuladd.f64(double %99, double 0x3EB0C6F7A0B5ED8D, double %94)
%101 = load double, double* %13
%102 = fadd double %101, %100
store double %102, double* %13
br label %103
103: ; preds = %67
%104 = load i32, i32* %14
%105 = add nsw i32 %104, 1
store i32 %105, i32* %14
br label %64
106: ; preds = %64
%107 = load i32, i32* %6
%108 = load i32, i32* %7
%109 = load i32, i32* %14
%110 = sub nsw i32 %109, 1
%111 = load double, double* %13
%112 = load double**, double*** %8
%113 = load i32, i32* %6
%114 = sdiv i32 %113, 2
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double*, double** %112, i64 %115
%117 = load double*, double** %116
%118 = load i32, i32* %7
%119 = sdiv i32 %118, 2
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %117, i64 %120
%122 = load double, double* %121
%123 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %107, i32 %108, i32 %110, double %111, double %122)
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 = [53 x i8] c"RedBlackSOR 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 ], [ %57, %39 ]
%41 = phi double [ 0.000000e+00, %21 ], [ %56, %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 @RedSOR(double** %42, double** %43, i32 1, i32 %33, i32 1, i32 %34, double %32)
%46 = tail call i32 @BlackSOR(double** %42, double** %43, i32 1, i32 %33, i32 1, i32 %34, double %32)
%47 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%48 = load i64, i64* %35
%49 = load i64, i64* %36
%50 = sub nsw i64 %48, %49
%51 = sitofp i64 %50 to double
%52 = load double, double* %37
%53 = load double, double* %38
%54 = fsub double %52, %53
%55 = tail call double @llvm.fmuladd.f64(double %54, double 0x3EB0C6F7A0B5ED8D, double %51)
%56 = fadd double %41, %55
%57 = add nuw nsw i32 %40, 1
%58 = icmp eq i32 %57, 256
br i1 %58, label %59, label %39
59: ; preds = %39
%60 = sdiv i32 %16, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %43, i64 %61
%63 = load double*, double** %62
%64 = sdiv i32 %22, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %22, i32 255, double %56, double %67)
ret i32 0
}