#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 */

/* Variables and functions */
int /*<<< orphan*/ GaussJacobiIteration(double *, double *, double *, int,
                                        double **);
int /*<<< orphan*/ copy(double *, double **, int, int);
int /*<<< orphan*/ print(double *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ zeros(int, int, double **);
void testGJ() {
  double *mat;
  zeros(2, 2, &mat);
  mat[0] = 1;
  mat[1] = 2;
  mat[1 * 2] = 3;
  mat[1 * 2 + 1] = 4;
  double *b;
  zeros(2, 1, &b);
  b[0] = 1;
  b[1] = 2;
  double *x0;
  zeros(2, 1, &x0);
  double *x;
  zeros(2, 1, &x);
  double *xtemp;
  zeros(2, 1, &xtemp);
  printf("A\n");
  print(mat, 2, 2);
  printf("B\n");
  print(b, 2, 1);
  printf("x0\n");
  print(x0, 2, 1);
  int iters = 5;
  for (int i = 0; i < iters; i++) {
    if (i == 0) {
      GaussJacobiIteration(mat, b, x0, 2, &x);
    } else {
      GaussJacobiIteration(mat, b, x, 2, &xtemp);
      copy(xtemp, &x, 2, 1);
    }
    printf("Iteration %d:\n", i);
    print(x, 2, 1);
  }
}


x86 assembly (clang, -O0):
<testGJ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x2,%esi
lea    -0x8(%rbp),%rdx
mov    %esi,%edi
call   1070 <zeros@plt>
mov    -0x8(%rbp),%rax
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe7c(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe6a(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x10(%rbp),%rdx
call   1070 <zeros@plt>
mov    -0x10(%rbp),%rax
movsd  0xe3e(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe26(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
call   1070 <zeros@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x20(%rbp),%rdx
call   1070 <zeros@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x28(%rbp),%rdx
call   1070 <zeros@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1040 <print@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <print@plt>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <print@plt>
movl   $0x5,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    131e <testGJ+0x1ce>
cmpl   $0x0,-0x30(%rbp)
jne    12bb <testGJ+0x16b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x20(%rbp),%r8
call   1060 <GaussJacobiIteration@plt>
jmp    12ec <testGJ+0x19c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x28(%rbp),%r8
call   1060 <GaussJacobiIteration@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1050 <copy@plt>
mov    -0x30(%rbp),%esi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <print@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1286 <testGJ+0x136>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testGJ>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x18(%rsp),%rdx
mov    $0x2,%edi
mov    $0x2,%esi
call   1080 <zeros@plt>
mov    0x18(%rsp),%rax
movaps 0xe77(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe7d(%rip),%xmm0
movups %xmm0,0x10(%rax)
lea    0x10(%rsp),%rdx
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <zeros@plt>
mov    0x10(%rsp),%rax
movaps 0xe49(%rip),%xmm0
movups %xmm0,(%rax)
lea    0x28(%rsp),%rdx
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <zeros@plt>
lea    0x8(%rsp),%r15
mov    $0x2,%edi
mov    $0x1,%esi
mov    %r15,%rdx
call   1080 <zeros@plt>
lea    0x20(%rsp),%r14
mov    $0x2,%edi
mov    $0x1,%esi
mov    %r14,%rdx
call   1080 <zeros@plt>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <print@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
mov    0x28(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x28(%rsp),%rdx
mov    $0x2,%ecx
mov    %r15,%r8
call   1070 <GaussJacobiIteration@plt>
lea    0xda1(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
call   1070 <GaussJacobiIteration@plt>
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1060 <copy@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
call   1070 <GaussJacobiIteration@plt>
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1060 <copy@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
call   1070 <GaussJacobiIteration@plt>
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1060 <copy@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    $0x2,%ecx
mov    %r14,%r8
call   1070 <GaussJacobiIteration@plt>
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1060 <copy@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"A\0A\00"
@.str.1 = [3 x i8] c"B\0A\00"
@.str.2 = [4 x i8] c"x0\0A\00"
@.str.3 = [15 x i8] c"Iteration %d:\0A\00"
define void @testGJ() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = call i32 @zeros(i32 2, i32 2, double** %1)
%9 = load double*, double** %1
%10 = getelementptr inbounds double, double* %9, i64 0
store double 1.000000e+00, double* %10
%11 = load double*, double** %1
%12 = getelementptr inbounds double, double* %11, i64 1
store double 2.000000e+00, double* %12
%13 = load double*, double** %1
%14 = getelementptr inbounds double, double* %13, i64 2
store double 3.000000e+00, double* %14
%15 = load double*, double** %1
%16 = getelementptr inbounds double, double* %15, i64 3
store double 4.000000e+00, double* %16
%17 = call i32 @zeros(i32 2, i32 1, double** %2)
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 0
store double 1.000000e+00, double* %19
%20 = load double*, double** %2
%21 = getelementptr inbounds double, double* %20, i64 1
store double 2.000000e+00, double* %21
%22 = call i32 @zeros(i32 2, i32 1, double** %3)
%23 = call i32 @zeros(i32 2, i32 1, double** %4)
%24 = call i32 @zeros(i32 2, i32 1, double** %5)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = load double*, double** %1
%27 = call i32 @print(double* %26, i32 2, i32 2)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = load double*, double** %2
%30 = call i32 @print(double* %29, i32 2, i32 1)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%32 = load double*, double** %3
%33 = call i32 @print(double* %32, i32 2, i32 1)
store i32 5, i32* %6
store i32 0, i32* %7
br label %34
34: ; preds = %58, %0
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %61
38: ; preds = %34
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load double*, double** %1
%43 = load double*, double** %2
%44 = load double*, double** %3
%45 = call i32 @GaussJacobiIteration(double* %42, double* %43, double* %44, i32 2, double** %4)
br label %53
46: ; preds = %38
%47 = load double*, double** %1
%48 = load double*, double** %2
%49 = load double*, double** %4
%50 = call i32 @GaussJacobiIteration(double* %47, double* %48, double* %49, i32 2, double** %5)
%51 = load double*, double** %5
%52 = call i32 @copy(double* %51, double** %4, i32 2, i32 1)
br label %53
53: ; preds = %46, %41
%54 = load i32, i32* %7
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load double*, double** %4
%57 = call i32 @print(double* %56, i32 2, i32 1)
br label %58
58: ; preds = %53
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %34
61: ; preds = %34
ret void
}

LLVM IR (-O2):
@.str.3 = [15 x i8] c"Iteration %d:\0A\00"
@str = [2 x i8] c"A\00"
@str.4 = [2 x i8] c"B\00"
@str.5 = [3 x i8] c"x0\00"
define void @testGJ() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = bitcast double** %1 to i8*
%7 = call i32 @zeros(i32 2, i32 2, double** %1)
%8 = load double*, double** %1
%9 = bitcast double* %8 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %9
%10 = getelementptr inbounds double, double* %8, i64 2
%11 = bitcast double* %10 to <2 x double>*
store <2 x double> <double 3.000000e+00, double 4.000000e+00>, <2 x double>* %11
%12 = bitcast double** %2 to i8*
%13 = call i32 @zeros(i32 2, i32 1, double** %2)
%14 = bitcast double** %2 to <2 x double>**
%15 = load <2 x double>*, <2 x double>** %14
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %15
%16 = bitcast double** %3 to i8*
%17 = call i32 @zeros(i32 2, i32 1, double** %3)
%18 = bitcast double** %4 to i8*
%19 = call i32 @zeros(i32 2, i32 1, double** %4)
%20 = bitcast double** %5 to i8*
%21 = call i32 @zeros(i32 2, i32 1, double** %5)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%23 = load double*, double** %1
%24 = call i32 @print(double* %23, i32 2, i32 2)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%26 = load double*, double** %2
%27 = call i32 @print(double* %26, i32 2, i32 1)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%29 = load double*, double** %3
%30 = call i32 @print(double* %29, i32 2, i32 1)
%31 = load double*, double** %1
%32 = load double*, double** %2
%33 = load double*, double** %3
%34 = call i32 @GaussJacobiIteration(double* %31, double* %32, double* %33, i32 2, double** %4)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 0)
%36 = load double*, double** %4
%37 = call i32 @print(double* %36, i32 2, i32 1)
%38 = load double*, double** %1
%39 = load double*, double** %2
%40 = load double*, double** %4
%41 = call i32 @GaussJacobiIteration(double* %38, double* %39, double* %40, i32 2, double** %5)
%42 = load double*, double** %5
%43 = call i32 @copy(double* %42, double** %4, i32 2, i32 1)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 1)
%45 = load double*, double** %4
%46 = call i32 @print(double* %45, i32 2, i32 1)
%47 = load double*, double** %1
%48 = load double*, double** %2
%49 = load double*, double** %4
%50 = call i32 @GaussJacobiIteration(double* %47, double* %48, double* %49, i32 2, double** %5)
%51 = load double*, double** %5
%52 = call i32 @copy(double* %51, double** %4, i32 2, i32 1)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 2)
%54 = load double*, double** %4
%55 = call i32 @print(double* %54, i32 2, i32 1)
%56 = load double*, double** %1
%57 = load double*, double** %2
%58 = load double*, double** %4
%59 = call i32 @GaussJacobiIteration(double* %56, double* %57, double* %58, i32 2, double** %5)
%60 = load double*, double** %5
%61 = call i32 @copy(double* %60, double** %4, i32 2, i32 1)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 3)
%63 = load double*, double** %4
%64 = call i32 @print(double* %63, i32 2, i32 1)
%65 = load double*, double** %1
%66 = load double*, double** %2
%67 = load double*, double** %4
%68 = call i32 @GaussJacobiIteration(double* %65, double* %66, double* %67, i32 2, double** %5)
%69 = load double*, double** %5
%70 = call i32 @copy(double* %69, double** %4, i32 2, i32 1)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 4)
%72 = load double*, double** %4
%73 = call i32 @print(double* %72, i32 2, i32 1)
ret void
}