#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*/ copy(double *, double **, int, int);
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ zeros(int, int, double **);
void GaussJacobiIteration(double *A, double *b, double *x, int n, double **x2) {
  double *x2temp;
  zeros(n, 1, &x2temp);
  double sum;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < n; j++) {
      if (i != j) {
        printf("[%f][%f]\n", A[i * n + j], x[j]);
        sum += A[i * n + j] * x[j];
      }
    }
    printf("%f\n", sum);
    x2temp[i] = (b[i] - sum) / A[i * n + i];
  }
  copy(x2temp, x2, n, n);
}


x86 assembly (clang, -O0):
<GaussJacobiIteration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
lea    -0x30(%rbp),%rdx
call   1050 <zeros@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1265 <GaussJacobiIteration+0x135>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <GaussJacobiIteration+0xdf>
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     11fc <GaussJacobiIteration+0xcc>
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe40(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1201 <GaussJacobiIteration+0xd1>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    117e <GaussJacobiIteration+0x4e>
movsd  -0x38(%rbp),%xmm0
lea    0xdef(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1163 <GaussJacobiIteration+0x33>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <copy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GaussJacobiIteration>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x18(%rsp)
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,0x30(%rsp)
mov    %rdi,%rbp
lea    0x10(%rsp),%rdx
mov    %ecx,%edi
mov    $0x1,%esi
call   1050 <zeros@plt>
test   %r15d,%r15d
jle    124c <GaussJacobiIteration+0x11c>
mov    %r15d,%r13d
lea    0x0(,%r13,8),%rax
mov    %rax,0x20(%rsp)
xor    %r12d,%r12d
lea    0xe7b(%rip),%r14
mov    %rbp,0x28(%rsp)
mov    %r15d,0xc(%rsp)
jmp    11f7 <GaussJacobiIteration+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe63(%rip),%rdi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x30(%rsp),%rax
movsd  (%rax,%r12,8),%xmm0
subsd  (%rsp),%xmm0
mov    %r12d,%eax
mov    0xc(%rsp),%r15d
imul   %r15d,%eax
cltq
add    %r12,%rax
mov    0x28(%rsp),%rcx
divsd  (%rcx,%rax,8),%xmm0
mov    0x10(%rsp),%rdi
movsd  %xmm0,(%rdi,%r12,8)
add    $0x1,%r12
add    0x20(%rsp),%rbp
cmp    %r13,%r12
je     1251 <GaussJacobiIteration+0x121>
xorpd  %xmm0,%xmm0
xor    %r15d,%r15d
jmp    1209 <GaussJacobiIteration+0xd9>
add    $0x1,%r15
cmp    %r15,%r13
je     11a0 <GaussJacobiIteration+0x70>
cmp    %r15,%r12
je     1200 <GaussJacobiIteration+0xd0>
movsd  %xmm0,(%rsp)
movsd  0x0(%rbp,%r15,8),%xmm0
movsd  (%rbx,%r15,8),%xmm1
mov    %r14,%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0x0(%rbp,%r15,8),%xmm0
mulsd  (%rbx,%r15,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
jmp    1200 <GaussJacobiIteration+0xd0>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,%edx
mov    %r15d,%ecx
call   1040 <copy@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"[%f][%f]\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define void @GaussJacobiIteration(double* %0, double* %1, double* %2, i32 %3, double** %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double**
%11 = alloca double*
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double** %4, double*** %10
%15 = load i32, i32* %9
%16 = call i32 @zeros(i32 %15, i32 1, double** %11)
store i32 0, i32* %13
br label %17
17: ; preds = %90, %5
%18 = load i32, i32* %13
%19 = load i32, i32* %9
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %93
21: ; preds = %17
store double 0.000000e+00, double* %12
store i32 0, i32* %14
br label %22
22: ; preds = %63, %21
%23 = load i32, i32* %14
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %66
26: ; preds = %22
%27 = load i32, i32* %13
%28 = load i32, i32* %14
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %62
30: ; preds = %26
%31 = load double*, double** %6
%32 = load i32, i32* %13
%33 = load i32, i32* %9
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %14
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %31, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %8
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %39, double %44)
%46 = load double*, double** %6
%47 = load i32, i32* %13
%48 = load i32, i32* %9
%49 = mul nsw i32 %47, %48
%50 = load i32, i32* %14
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %46, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %8
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double, double* %12
%61 = call double @llvm.fmuladd.f64(double %54, double %59, double %60)
store double %61, double* %12
br label %62
62: ; preds = %30, %26
br label %63
63: ; preds = %62
%64 = load i32, i32* %14
%65 = add nsw i32 %64, 1
store i32 %65, i32* %14
br label %22
66: ; preds = %22
%67 = load double, double* %12
%68 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %67)
%69 = load double*, double** %7
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = load double, double* %12
%75 = fsub double %73, %74
%76 = load double*, double** %6
%77 = load i32, i32* %13
%78 = load i32, i32* %9
%79 = mul nsw i32 %77, %78
%80 = load i32, i32* %13
%81 = add nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %76, i64 %82
%84 = load double, double* %83
%85 = fdiv double %75, %84
%86 = load double*, double** %11
%87 = load i32, i32* %13
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
store double %85, double* %89
br label %90
90: ; preds = %66
%91 = load i32, i32* %13
%92 = add nsw i32 %91, 1
store i32 %92, i32* %13
br label %17
93: ; preds = %17
%94 = load double*, double** %11
%95 = load double**, double*** %10
%96 = load i32, i32* %9
%97 = load i32, i32* %9
%98 = call i32 @copy(double* %94, double** %95, i32 %96, i32 %97)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"[%f][%f]\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define void @GaussJacobiIteration(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, double** %4) {
%6 = alloca double*
%7 = bitcast double** %6 to i8*
%8 = call i32 @zeros(i32 %3, i32 1, double** %6)
%9 = icmp sgt i32 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = load double*, double** %6
br label %19
12: ; preds = %5
%13 = zext i32 %3 to i64
%14 = zext i32 %3 to i64
br label %15
15: ; preds = %22, %12
%16 = phi i64 [ 0, %12 ], [ %35, %22 ]
%17 = trunc i64 %16 to i32
%18 = mul nsw i64 %16, %13
br label %37
19: ; preds = %22, %10
%20 = phi double* [ %11, %10 ], [ %33, %22 ]
%21 = call i32 @copy(double* %20, double** %4, i32 %3, i32 %3)
ret void
22: ; preds = %51
%23 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %52)
%24 = getelementptr inbounds double, double* %1, i64 %16
%25 = load double, double* %24
%26 = fsub double %25, %52
%27 = mul nsw i32 %17, %3
%28 = sext i32 %27 to i64
%29 = add nsw i64 %16, %28
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = fdiv double %26, %31
%33 = load double*, double** %6
%34 = getelementptr inbounds double, double* %33, i64 %16
store double %32, double* %34
%35 = add nuw nsw i64 %16, 1
%36 = icmp eq i64 %35, %14
br i1 %36, label %19, label %15
37: ; preds = %15, %51
%38 = phi i64 [ 0, %15 ], [ %53, %51 ]
%39 = phi double [ 0.000000e+00, %15 ], [ %52, %51 ]
%40 = icmp eq i64 %16, %38
br i1 %40, label %51, label %41
41: ; preds = %37
%42 = add nuw nsw i64 %38, %18
%43 = getelementptr inbounds double, double* %0, i64 %42
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %2, i64 %38
%46 = load double, double* %45
%47 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %44, double %46)
%48 = load double, double* %43
%49 = load double, double* %45
%50 = call double @llvm.fmuladd.f64(double %48, double %49, double %39)
br label %51
51: ; preds = %37, %41
%52 = phi double [ %50, %41 ], [ %39, %37 ]
%53 = add nuw nsw i64 %38, 1
%54 = icmp eq i64 %53, %14
br i1 %54, label %22, label %37
}