#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(int, double *, int, double *, int);
int jacobi(double *, int, double *, double *, double *, double *);
int /*<<< orphan*/ matmult(int, int, int, double *, double *, double *);
int /*<<< orphan*/ matmult_tn(int, int, int, double *, double *, double *);
double sqrt(double);
int gjacobi(double *a, double *s, int n, double d[], double *v, double *b,
            double *z) {
  int info, i, j;
  info = jacobi(s, n, d, v, b, z);
  for (j = 0; j < n; j++) {
    for (i = 0; i < n; i++)
      s[i + j * n] = v[i + j * n] / sqrt(d[j]);
  }
  matmult(n, n, n, a, s, v);
  matmult_tn(n, n, n, s, v, a);
  info = jacobi(a, n, d, v, b, z);
  copy(n * n, v, 1, a, 1);
  matmult(n, n, n, s, a, v);
  return info;
}


x86 assembly (clang, -O0):
<gjacobi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9
call   1030 <jacobi@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122c <gjacobi+0xdc>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1219 <gjacobi+0xc9>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ac <gjacobi+0x5c>
jmp    121e <gjacobi+0xce>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1199 <gjacobi+0x49>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1050 <matmult@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x8(%rbp),%r9
call   1060 <matmult_tn@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9
call   1030 <jacobi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%r8d
mov    %r8d,%edx
call   1040 <copy@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1050 <matmult@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gjacobi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,%rax
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rdi,0x38(%rsp)
mov    0x80(%rsp),%r9
mov    %rsi,0x18(%rsp)
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rcx,%rdx
mov    %r8,0x20(%rsp)
mov    %r8,%rcx
mov    %rax,0x30(%rsp)
mov    %rax,%r8
call   1030 <jacobi@plt>
mov    %ebp,0xc(%rsp)
test   %ebp,%ebp
jle    12fd <gjacobi+0x1ad>
mov    0xc(%rsp),%ecx
mov    %rcx,0x28(%rsp)
mov    %ecx,%r12d
and    $0xfffffffe,%r12d
mov    0x18(%rsp),%rax
lea    0x8(%rax),%r15
lea    0x0(,%rcx,8),%rax
mov    %rax,0x40(%rsp)
mov    0x20(%rsp),%rax
lea    0x8(%rax),%rbp
xor    %r13d,%r13d
xorpd  %xmm1,%xmm1
jmp    1221 <gjacobi+0xd1>
nopl   0x0(%rax)
movsd  %xmm2,0x10(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
divsd  %xmm0,%xmm2
mov    0x18(%rsp),%rax
movsd  %xmm2,(%rax,%r14,8)
mov    0x28(%rsp),%rcx
add    $0x1,%r13
mov    0x40(%rsp),%rax
add    %rax,%r15
add    %rax,%rbp
cmp    %rcx,%r13
je     12fd <gjacobi+0x1ad>
cmpl   $0x1,0xc(%rsp)
jne    1260 <gjacobi+0x110>
xor    %r14d,%r14d
mov    0x28(%rsp),%rcx
test   $0x1,%cl
je     1209 <gjacobi+0xb9>
mov    %r13,%rax
imul   %rcx,%rax
add    %rax,%r14
mov    0x20(%rsp),%rax
movsd  (%rax,%r14,8),%xmm2
movsd  (%rbx,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11e0 <gjacobi+0x90>
sqrtsd %xmm0,%xmm0
jmp    11f5 <gjacobi+0xa5>
nopl   0x0(%rax)
xor    %r14d,%r14d
jmp    1298 <gjacobi+0x148>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm2,0x10(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,(%r15,%r14,8)
add    $0x2,%r14
cmp    %r14,%r12
je     122b <gjacobi+0xdb>
movsd  -0x8(%rbp,%r14,8),%xmm2
movsd  (%rbx,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     12c0 <gjacobi+0x170>
sqrtsd %xmm0,%xmm0
jmp    12d5 <gjacobi+0x185>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x10(%rsp)
call   1070 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,-0x8(%r15,%r14,8)
movsd  0x0(%rbp,%r14,8),%xmm2
movsd  (%rbx,%r13,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1270 <gjacobi+0x120>
sqrtsd %xmm0,%xmm0
jmp    1285 <gjacobi+0x135>
mov    0xc(%rsp),%ebp
mov    %ebp,%edi
mov    %ebp,%esi
mov    %ebp,%edx
mov    0x38(%rsp),%r14
mov    %r14,%rcx
mov    0x18(%rsp),%r15
mov    %r15,%r8
mov    0x20(%rsp),%r12
mov    %r12,%r9
call   1050 <matmult@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1060 <matmult_tn@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    0x30(%rsp),%r8
mov    0x80(%rsp),%r9
call   1030 <jacobi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
imul   %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1040 <copy@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r14,%r8
mov    %r12,%r9
call   1050 <matmult@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gjacobi(double* %0, double* %1, i32 %2, double* %3, double* %4, double* %5, double* %6) {
%8 = tail call i32 @jacobi(double* %1, i32 %2, double* %3, double* %4, double* %5, double* %6)
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %55
10: ; preds = %7
%11 = zext i32 %2 to i64
%12 = zext i32 %2 to i64
%13 = and i64 %12, 1
%14 = icmp eq i32 %2, 1
%15 = and i64 %12, 4294967294
%16 = icmp eq i64 %13, 0
br label %17
17: ; preds = %52, %10
%18 = phi i64 [ 0, %10 ], [ %53, %52 ]
%19 = mul nsw i64 %18, %11
%20 = getelementptr inbounds double, double* %3, i64 %18
br i1 %14, label %42, label %21
21: ; preds = %17, %21
%22 = phi i64 [ %39, %21 ], [ 0, %17 ]
%23 = phi i64 [ %40, %21 ], [ 0, %17 ]
%24 = add nuw nsw i64 %22, %19
%25 = getelementptr inbounds double, double* %4, i64 %24
%26 = load double, double* %25
%27 = load double, double* %20
%28 = tail call double @sqrt(double %27)
%29 = fdiv double %26, %28
%30 = getelementptr inbounds double, double* %1, i64 %24
store double %29, double* %30
%31 = or i64 %22, 1
%32 = add nuw nsw i64 %31, %19
%33 = getelementptr inbounds double, double* %4, i64 %32
%34 = load double, double* %33
%35 = load double, double* %20
%36 = tail call double @sqrt(double %35)
%37 = fdiv double %34, %36
%38 = getelementptr inbounds double, double* %1, i64 %32
store double %37, double* %38
%39 = add nuw nsw i64 %22, 2
%40 = add i64 %23, 2
%41 = icmp eq i64 %40, %15
br i1 %41, label %42, label %21
42: ; preds = %21, %17
%43 = phi i64 [ 0, %17 ], [ %39, %21 ]
br i1 %16, label %52, label %44
44: ; preds = %42
%45 = add nuw nsw i64 %43, %19
%46 = getelementptr inbounds double, double* %4, i64 %45
%47 = load double, double* %46
%48 = load double, double* %20
%49 = tail call double @sqrt(double %48)
%50 = fdiv double %47, %49
%51 = getelementptr inbounds double, double* %1, i64 %45
store double %50, double* %51
br label %52
52: ; preds = %42, %44
%53 = add nuw nsw i64 %18, 1
%54 = icmp eq i64 %53, %12
br i1 %54, label %55, label %17
55: ; preds = %52, %7
%56 = tail call i32 @matmult(i32 %2, i32 %2, i32 %2, double* %0, double* %1, double* %4)
%57 = tail call i32 @matmult_tn(i32 %2, i32 %2, i32 %2, double* %1, double* %4, double* %0)
%58 = tail call i32 @jacobi(double* %0, i32 %2, double* %3, double* %4, double* %5, double* %6)
%59 = mul nsw i32 %2, %2
%60 = tail call i32 @copy(i32 %59, double* %4, i32 1, double* %0, i32 1)
%61 = tail call i32 @matmult(i32 %2, i32 %2, i32 %2, double* %1, double* %0, double* %4)
ret i32 %58
}