#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int, double);
void run_gauss_seidel_method(int p, int n, double **A, double *b,
                             double epsilon, int maxit, int *numit, double *x) {
  double *dx;
  dx = (double *)calloc(n, sizeof(double));
  int i, j, k, id, jstart, jstop;
  int dnp = n / p;
  double dxi;
  for (k = 0; k < maxit; k++) {
    double sum = 0.0;
    for (i = 0; i < n; i++) {
      dx[i] = b[i];
#pragma omp parallel shared(A, x) private(id, j, jstart, jstop, dxi)
      {
        id = omp_get_thread_num();
        jstart = id * dnp;
        jstop = jstart + dnp;
        dxi = 0.0;
        for (j = jstart; j < jstop; j++)
          dxi += A[i][j] * x[j];
#pragma omp critical
        dx[i] -= dxi;
      }
      dx[i] /= A[i][i];
      x[i] += dx[i];
      sum += ((dx[i] >= 0.0) ? dx[i] : -dx[i]);
    }
    printf("%4d : %.3e\n", k, sum);
    if (sum <= epsilon)
      break;
  }
  *numit = k + 1;
  free(dx);
}


x86 assembly (clang, -O0):
<run_gauss_seidel_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    135f <run_gauss_seidel_method+0x21f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131f <run_gauss_seidel_method+0x1df>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1040 <omp_get_thread_num@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
imul   -0x54(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1243 <run_gauss_seidel_method+0x103>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11f5 <run_gauss_seidel_method+0xb5>
movsd  -0x60(%rbp),%xmm1
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12d9 <run_gauss_seidel_method+0x199>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    1302 <run_gauss_seidel_method+0x1c2>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a4 <run_gauss_seidel_method+0x64>
mov    -0x44(%rbp),%esi
movsd  -0x68(%rbp),%xmm0
lea    0xcd2(%rip),%rdi
call   1050 <printf@plt>
movsd  -0x68(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     134c <run_gauss_seidel_method+0x20c>
jmp    135f <run_gauss_seidel_method+0x21f>
jmp    1351 <run_gauss_seidel_method+0x211>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1189 <run_gauss_seidel_method+0x49>
mov    -0x44(%rbp),%ecx
add    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_gauss_seidel_method>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r15
mov    %r8d,%r12d
movsd  %xmm0,0x28(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,0x20(%rsp)
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x70(%rsp),%r13
mov    %esi,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %ebx,%ecx
mov    %rax,%rbx
mov    %ecx,%eax
cltd
idiv   %r14d
mov    %r12d,0x4(%rsp)
test   %r12d,%r12d
jle    12ee <run_gauss_seidel_method+0x1ae>
mov    %eax,%r14d
mov    %r15,0x18(%rsp)
mov    %ecx,%r15d
xor    %ebp,%ebp
mov    %ecx,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
test   %ecx,%ecx
jle    12b0 <run_gauss_seidel_method+0x170>
xorpd  %xmm0,%xmm0
xor    %r12d,%r12d
jmp    1241 <run_gauss_seidel_method+0x101>
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp),%rax
mov    (%rax,%r12,8),%rcx
xorpd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm0
movsd  (%rbx,%r12,8),%xmm1
subsd  %xmm2,%xmm1
movsd  %xmm1,(%rbx,%r12,8)
divsd  (%rcx,%r12,8),%xmm1
movsd  %xmm1,(%rbx,%r12,8)
addsd  0x0(%r13,%r12,8),%xmm1
movsd  %xmm1,0x0(%r13,%r12,8)
movsd  (%rbx,%r12,8),%xmm3
movapd %xmm3,%xmm1
xorpd  0xde1(%rip),%xmm1
xorpd  %xmm2,%xmm2
cmpnlesd %xmm3,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm3,%xmm2
orpd   %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%r12
cmp    %r15,%r12
je     12b0 <run_gauss_seidel_method+0x170>
movsd  %xmm0,0x8(%rsp)
mov    0x30(%rsp),%rax
movsd  (%rax,%r12,8),%xmm0
movsd  %xmm0,(%rbx,%r12,8)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
test   %r14d,%r14d
jle    11d0 <run_gauss_seidel_method+0x90>
imul   %r14d,%eax
mov    0x20(%rsp),%rcx
mov    (%rcx,%r12,8),%rcx
movslq %eax,%rdx
add    %r14d,%eax
cltq
xorpd  %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rcx,%rdx,8),%xmm1
mulsd  0x0(%r13,%rdx,8),%xmm1
addsd  %xmm1,%xmm2
add    $0x1,%rdx
cmp    %rax,%rdx
jl     1290 <run_gauss_seidel_method+0x150>
jmp    11dd <run_gauss_seidel_method+0x9d>
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
lea    0xd53(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
movsd  0x28(%rsp),%xmm0
ucomisd 0x8(%rsp),%xmm0
jae    12e7 <run_gauss_seidel_method+0x1a7>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
mov    0x14(%rsp),%ecx
jne    11b0 <run_gauss_seidel_method+0x70>
mov    0x4(%rsp),%ebp
mov    0x18(%rsp),%r15
jmp    12f0 <run_gauss_seidel_method+0x1b0>
xor    %ebp,%ebp
add    $0x1,%ebp
mov    %ebp,(%r15)
mov    %rbx,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%4d : %.3e\0A\00"
define void @run_gauss_seidel_method(i32 %0, i32 %1, double** %2, double* %3, double %4, i32 %5, i32* %6, double* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
%12 = alloca double*
%13 = alloca double
%14 = alloca i32
%15 = alloca i32*
%16 = alloca double*
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca double
%26 = alloca double
store i32 %0, i32* %9
store i32 %1, i32* %10
store double** %2, double*** %11
store double* %3, double** %12
store double %4, double* %13
store i32 %5, i32* %14
store i32* %6, i32** %15
store double* %7, double** %16
%27 = load i32, i32* %10
%28 = call i64 @calloc(i32 %27, i32 8)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %17
%30 = load i32, i32* %10
%31 = load i32, i32* %9
%32 = sdiv i32 %30, %31
store i32 %32, i32* %24
store i32 0, i32* %20
br label %33
33: ; preds = %153, %8
%34 = load i32, i32* %20
%35 = load i32, i32* %14
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %156
37: ; preds = %33
store double 0.000000e+00, double* %26
store i32 0, i32* %18
br label %38
38: ; preds = %141, %37
%39 = load i32, i32* %18
%40 = load i32, i32* %10
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %144
42: ; preds = %38
%43 = load double*, double** %12
%44 = load i32, i32* %18
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %17
%49 = load i32, i32* %18
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
store double %47, double* %51
%52 = call i32 (...) @omp_get_thread_num()
store i32 %52, i32* %21
%53 = load i32, i32* %21
%54 = load i32, i32* %24
%55 = mul nsw i32 %53, %54
store i32 %55, i32* %22
%56 = load i32, i32* %22
%57 = load i32, i32* %24
%58 = add nsw i32 %56, %57
store i32 %58, i32* %23
store double 0.000000e+00, double* %25
%59 = load i32, i32* %22
store i32 %59, i32* %19
br label %60
60: ; preds = %81, %42
%61 = load i32, i32* %19
%62 = load i32, i32* %23
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %84
64: ; preds = %60
%65 = load double**, double*** %11
%66 = load i32, i32* %18
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
%69 = load double*, double** %68
%70 = load i32, i32* %19
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = load double*, double** %16
%75 = load i32, i32* %19
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load double, double* %77
%79 = load double, double* %25
%80 = call double @llvm.fmuladd.f64(double %73, double %78, double %79)
store double %80, double* %25
br label %81
81: ; preds = %64
%82 = load i32, i32* %19
%83 = add nsw i32 %82, 1
store i32 %83, i32* %19
br label %60
84: ; preds = %60
%85 = load double, double* %25
%86 = load double*, double** %17
%87 = load i32, i32* %18
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
%90 = load double, double* %89
%91 = fsub double %90, %85
store double %91, double* %89
%92 = load double**, double*** %11
%93 = load i32, i32* %18
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double*, double** %92, i64 %94
%96 = load double*, double** %95
%97 = load i32, i32* %18
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = load double*, double** %17
%102 = load i32, i32* %18
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %101, i64 %103
%105 = load double, double* %104
%106 = fdiv double %105, %100
store double %106, double* %104
%107 = load double*, double** %17
%108 = load i32, i32* %18
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = load double*, double** %16
%113 = load i32, i32* %18
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %112, i64 %114
%116 = load double, double* %115
%117 = fadd double %116, %111
store double %117, double* %115
%118 = load double*, double** %17
%119 = load i32, i32* %18
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %118, i64 %120
%122 = load double, double* %121
%123 = fcmp oge double %122, 0.000000e+00
br i1 %123, label %124, label %130
124: ; preds = %84
%125 = load double*, double** %17
%126 = load i32, i32* %18
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
%129 = load double, double* %128
br label %137
130: ; preds = %84
%131 = load double*, double** %17
%132 = load i32, i32* %18
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds double, double* %131, i64 %133
%135 = load double, double* %134
%136 = fneg double %135
br label %137
137: ; preds = %130, %124
%138 = phi double [ %129, %124 ], [ %136, %130 ]
%139 = load double, double* %26
%140 = fadd double %139, %138
store double %140, double* %26
br label %141
141: ; preds = %137
%142 = load i32, i32* %18
%143 = add nsw i32 %142, 1
store i32 %143, i32* %18
br label %38
144: ; preds = %38
%145 = load i32, i32* %20
%146 = load double, double* %26
%147 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %145, double %146)
%148 = load double, double* %26
%149 = load double, double* %13
%150 = fcmp ole double %148, %149
br i1 %150, label %151, label %152
151: ; preds = %144
br label %156
152: ; preds = %144
br label %153
153: ; preds = %152
%154 = load i32, i32* %20
%155 = add nsw i32 %154, 1
store i32 %155, i32* %20
br label %33
156: ; preds = %151, %33
%157 = load i32, i32* %20
%158 = add nsw i32 %157, 1
%159 = load i32*, i32** %15
store i32 %158, i32* %159
%160 = load double*, double** %17
%161 = call i32 @free(double* %160)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%4d : %.3e\0A\00"
define void @run_gauss_seidel_method(i32 %0, i32 %1, double** nocapture %2, double* nocapture %3, double %4, i32 %5, i32* nocapture writeonly %6, double* nocapture %7) {
%9 = tail call i64 @calloc(i32 %1, i32 8)
%10 = inttoptr i64 %9 to double*
%11 = sdiv i32 %1, %0
%12 = icmp sgt i32 %5, 0
br i1 %12, label %13, label %71
13: ; preds = %8
%14 = icmp sgt i32 %1, 0
%15 = zext i32 %1 to i64
%16 = icmp sgt i32 %11, 0
br label %17
17: ; preds = %13, %68
%18 = phi i32 [ 0, %13 ], [ %69, %68 ]
br i1 %14, label %19, label %64
19: ; preds = %17, %46
%20 = phi i64 [ %62, %46 ], [ 0, %17 ]
%21 = phi double [ %61, %46 ], [ 0.000000e+00, %17 ]
%22 = getelementptr inbounds double, double* %3, i64 %20
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %10, i64 %20
store double %23, double* %24
%25 = tail call i32 (...) @omp_get_thread_num()
%26 = mul i32 %25, %11
br i1 %16, label %30, label %27
27: ; preds = %19
%28 = getelementptr inbounds double*, double** %2, i64 %20
%29 = load double*, double** %28
br label %46
30: ; preds = %19
%31 = add nsw i32 %26, %11
%32 = getelementptr inbounds double*, double** %2, i64 %20
%33 = load double*, double** %32
%34 = sext i32 %26 to i64
%35 = sext i32 %31 to i64
br label %36
36: ; preds = %30, %36
%37 = phi i64 [ %34, %30 ], [ %44, %36 ]
%38 = phi double [ 0.000000e+00, %30 ], [ %43, %36 ]
%39 = getelementptr inbounds double, double* %33, i64 %37
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %7, i64 %37
%42 = load double, double* %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %38)
%44 = add nsw i64 %37, 1
%45 = icmp slt i64 %44, %35
br i1 %45, label %36, label %46
46: ; preds = %36, %27
%47 = phi double* [ %29, %27 ], [ %33, %36 ]
%48 = phi double [ 0.000000e+00, %27 ], [ %43, %36 ]
%49 = load double, double* %24
%50 = fsub double %49, %48
store double %50, double* %24
%51 = getelementptr inbounds double, double* %47, i64 %20
%52 = load double, double* %51
%53 = fdiv double %50, %52
store double %53, double* %24
%54 = getelementptr inbounds double, double* %7, i64 %20
%55 = load double, double* %54
%56 = fadd double %53, %55
store double %56, double* %54
%57 = load double, double* %24
%58 = fcmp ult double %57, 0.000000e+00
%59 = fneg double %57
%60 = select i1 %58, double %59, double %57
%61 = fadd double %21, %60
%62 = add nuw nsw i64 %20, 1
%63 = icmp eq i64 %62, %15
br i1 %63, label %64, label %19
64: ; preds = %46, %17
%65 = phi double [ 0.000000e+00, %17 ], [ %61, %46 ]
%66 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18, double %65)
%67 = fcmp ugt double %65, %4
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = add nuw nsw i32 %18, 1
%70 = icmp eq i32 %69, %5
br i1 %70, label %71, label %17
71: ; preds = %68, %64, %8
%72 = phi i32 [ 0, %8 ], [ %18, %64 ], [ %5, %68 ]
%73 = add nuw nsw i32 %72, 1
store i32 %73, i32* %6
%74 = tail call i32 @free(double* %10)
ret void
}