#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 check_convergence(double **, double *, double *);
int /*<<< orphan*/ print_vector(double *, int);
int /*<<< orphan*/ printf(char *, ...);
void jacobi() {
  double A[3][3] = {{1.0, 1.0, 2.0}, {2.0, 3.0, 5.0}, {3.0, 3.0, 6.0}};
  double b[3] = {12.0, 27.0, 36.0};
  double D[3][3] = {0};
  double D_1[3][3] = {0};
  double R[3][3] = {0};
  double x[3] = {0.0, 0.0, 0.0};
  double temp1[3] = {0};
  double temp2[3] = {0};
  double temp3[3] = {0};
  double b_check[3] = {0};
  int check = 0;
  int count = 0;
  int i, j;
  printf("\n----------Question1_Jacobi : ----------\n\n");
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      if (i == j) {
        D[i][j] = A[i][j];
        D_1[i][j] = 1.0 / A[i][j];
      } else {
        R[i][j] = A[i][j];
      }
    }
  }
  while ((check == 0) && (count < 250)) {
    for (i = 0; i < 3; i++) {
      temp1[i] = 0.0;
      temp2[i] = 0.0;
      temp3[i] = 0.0;
    }
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 3; j++) {
        temp1[i] = temp1[i] + R[i][j] * x[j];
      }
      temp2[i] = b[i] - temp1[i];
    }
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 3; j++) {
        temp3[i] = temp3[i] + D_1[i][j] * temp2[j];
      }
      x[i] = temp3[i];
    }
    count = count + 1;
    check = check_convergence(A, x, b);
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      b_check[i] = b_check[i] + A[i][j] * x[j];
    }
  }
  if (count == 250) {
    printf(
        "Jacobi Method is failed! (Maximum number of iterations is reached)\n");
  } else {
    printf("Jacobi Method is converged in %d iterations.", count);
    printf("Solution,  x: \n");
    print_vector(x, 3);
  }
  printf("\n----------EndOfJacobiMethod----------\n\n");
}


x86 assembly (clang, -O0):
<jacobi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    -0x50(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x48,%edx
call   1060 <memcpy@plt>
mov    0xee9(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xee6(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xee3(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1050 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1050 <memset@plt>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1050 <memset@plt>
lea    -0x180(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x1c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x200(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
movl   $0x0,-0x204(%rbp)
movl   $0x0,-0x208(%rbp)
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20c(%rbp)
cmpl   $0x3,-0x20c(%rbp)
jge    1387 <jacobi+0x237>
movl   $0x0,-0x210(%rbp)
cmpl   $0x3,-0x210(%rbp)
jge    136e <jacobi+0x21e>
mov    -0x20c(%rbp),%eax
cmp    -0x210(%rbp),%eax
jne    1316 <jacobi+0x1c6>
movslq -0x20c(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x20c(%rbp),%rcx
lea    -0xc0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movslq -0x20c(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  0xd15(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
movslq -0x20c(%rbp),%rcx
lea    -0x110(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1355 <jacobi+0x205>
movslq -0x20c(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x20c(%rbp),%rcx
lea    -0x160(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    135a <jacobi+0x20a>
mov    -0x210(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp)
jmp    126c <jacobi+0x11c>
jmp    1373 <jacobi+0x223>
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    1255 <jacobi+0x105>
jmp    138c <jacobi+0x23c>
xor    %eax,%eax
cmpl   $0x0,-0x204(%rbp)
mov    %al,-0x211(%rbp)
jne    13b4 <jacobi+0x264>
cmpl   $0xfa,-0x208(%rbp)
setl   %al
mov    %al,-0x211(%rbp)
mov    -0x211(%rbp),%al
test   $0x1,%al
jne    13c7 <jacobi+0x277>
jmp    1604 <jacobi+0x4b4>
movl   $0x0,-0x20c(%rbp)
cmpl   $0x3,-0x20c(%rbp)
jge    142b <jacobi+0x2db>
movslq -0x20c(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1a0(%rbp,%rax,8)
ff ff
movslq -0x20c(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1c0(%rbp,%rax,8)
ff ff
movslq -0x20c(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1e0(%rbp,%rax,8)
ff ff
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    13d1 <jacobi+0x281>
movl   $0x0,-0x20c(%rbp)
cmpl   $0x3,-0x20c(%rbp)
jge    1507 <jacobi+0x3b7>
movl   $0x0,-0x210(%rbp)
cmpl   $0x3,-0x210(%rbp)
jge    14c6 <jacobi+0x376>
movslq -0x20c(%rbp),%rax
movsd  -0x1a0(%rbp,%rax,8),%xmm1
ff ff
movslq -0x20c(%rbp),%rcx
lea    -0x160(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x210(%rbp),%rax
movsd  -0x180(%rbp,%rax,8),%xmm2
ff ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movslq -0x20c(%rbp),%rax
movsd  %xmm0,-0x1a0(%rbp,%rax,8)
ff ff
mov    -0x210(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp)
jmp    144c <jacobi+0x2fc>
movslq -0x20c(%rbp),%rax
movsd  -0x70(%rbp,%rax,8),%xmm0
movslq -0x20c(%rbp),%rax
subsd  -0x1a0(%rbp,%rax,8),%xmm0
ff ff
movslq -0x20c(%rbp),%rax
movsd  %xmm0,-0x1c0(%rbp,%rax,8)
ff ff
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    1435 <jacobi+0x2e5>
movl   $0x0,-0x20c(%rbp)
cmpl   $0x3,-0x20c(%rbp)
jge    15d6 <jacobi+0x486>
movl   $0x0,-0x210(%rbp)
cmpl   $0x3,-0x210(%rbp)
jge    15a2 <jacobi+0x452>
movslq -0x20c(%rbp),%rax
movsd  -0x1e0(%rbp,%rax,8),%xmm1
ff ff
movslq -0x20c(%rbp),%rcx
lea    -0x110(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x210(%rbp),%rax
movsd  -0x1c0(%rbp,%rax,8),%xmm2
ff ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movslq -0x20c(%rbp),%rax
movsd  %xmm0,-0x1e0(%rbp,%rax,8)
ff ff
mov    -0x210(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp)
jmp    1528 <jacobi+0x3d8>
movslq -0x20c(%rbp),%rax
movsd  -0x1e0(%rbp,%rax,8),%xmm0
ff ff
movslq -0x20c(%rbp),%rax
movsd  %xmm0,-0x180(%rbp,%rax,8)
ff ff
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    1511 <jacobi+0x3c1>
mov    -0x208(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x208(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x180(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1030 <check_convergence@plt>
mov    %eax,-0x204(%rbp)
jmp    138c <jacobi+0x23c>
movl   $0x0,-0x20c(%rbp)
cmpl   $0x3,-0x20c(%rbp)
jge    16b5 <jacobi+0x565>
movl   $0x0,-0x210(%rbp)
cmpl   $0x3,-0x210(%rbp)
jge    169c <jacobi+0x54c>
movslq -0x20c(%rbp),%rax
movsd  -0x200(%rbp,%rax,8),%xmm1
ff ff
movslq -0x20c(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x210(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x210(%rbp),%rax
movsd  -0x180(%rbp,%rax,8),%xmm2
ff ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movslq -0x20c(%rbp),%rax
movsd  %xmm0,-0x200(%rbp,%rax,8)
ff ff
mov    -0x210(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp)
jmp    1625 <jacobi+0x4d5>
jmp    16a1 <jacobi+0x551>
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    160e <jacobi+0x4be>
cmpl   $0xfa,-0x208(%rbp)
jne    16d8 <jacobi+0x588>
lea    0x9d7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    170b <jacobi+0x5bb>
mov    -0x208(%rbp),%esi
lea    0xa02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xa21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x180(%rbp),%rdi
mov    $0x3,%esi
call   1070 <print_vector@plt>
lea    0xa12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jacobi>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    0xf2b(%rip),%rax
mov    %rax,0x90(%rsp)
movaps 0xf0c(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
mov    0xf09(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xf26(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
movsd  0xe42(%rip),%xmm2
movsd  0xe42(%rip),%xmm0
movsd  0xe42(%rip),%xmm1
xorpd  %xmm3,%xmm3
movhpd 0xe4e(%rip),%xmm3
movapd %xmm3,0x40(%rsp)
lea    0x50(%rsp),%r14
mov    %rsp,%r15
lea    0x20(%rsp),%r12
xorpd  %xmm3,%xmm3
xorpd  %xmm4,%xmm4
xorpd  %xmm5,%xmm5
nopl   0x0(%rax)
movapd %xmm5,%xmm6
xorpd  %xmm8,%xmm8
mulsd  %xmm8,%xmm6
addsd  %xmm8,%xmm6
addsd  %xmm4,%xmm6
movapd %xmm3,%xmm7
addsd  %xmm3,%xmm7
addsd  %xmm6,%xmm7
subsd  %xmm7,%xmm2
movapd %xmm5,%xmm6
addsd  %xmm5,%xmm6
addsd  %xmm8,%xmm6
movapd %xmm4,%xmm7
mulsd  %xmm8,%xmm7
addsd  %xmm6,%xmm7
movapd %xmm3,%xmm6
mulsd  0xdcb(%rip),%xmm6
addsd  %xmm7,%xmm6
subsd  %xmm6,%xmm0
movsd  0xdc3(%rip),%xmm6
mulsd  %xmm6,%xmm5
addsd  %xmm8,%xmm5
mulsd  %xmm6,%xmm4
addsd  %xmm5,%xmm4
mulsd  %xmm8,%xmm3
addsd  %xmm4,%xmm3
subsd  %xmm3,%xmm1
movapd %xmm2,%xmm3
addsd  %xmm8,%xmm3
mulsd  %xmm8,%xmm2
addsd  %xmm8,%xmm2
movapd %xmm0,%xmm4
unpcklpd %xmm0,%xmm4
mulpd  0x40(%rsp),%xmm4
unpcklpd %xmm2,%xmm3
addpd  %xmm4,%xmm3
movapd %xmm1,%xmm4
mulsd  %xmm8,%xmm4
unpcklpd %xmm4,%xmm4
addpd  %xmm3,%xmm4
movapd %xmm4,(%rsp)
mulsd  %xmm8,%xmm0
addsd  %xmm2,%xmm0
mulsd  0xd65(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <check_convergence@plt>
test   %eax,%eax
jne    131a <jacobi+0x1da>
cmp    $0xf8,%ebx
ja     131a <jacobi+0x1da>
movsd  (%rsp),%xmm5
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
add    $0x1,%ebx
jmp    1200 <jacobi+0xc0>
cmp    $0xf9,%ebx
jne    1330 <jacobi+0x1f0>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
jmp    135c <jacobi+0x21c>
add    $0x1,%ebx
lea    0xd6e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdb5(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x3,%esi
call   1060 <print_vector@plt>
lea    0xdab(%rip),%rdi
call   1030 <puts@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.jacobi.A = [3 x [3 x double]] [[3 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00], [3 x double] [double 2.000000e+00, double 3.000000e+00, double 5.000000e+00], [3 x double] [double 3.000000e+00, double 3.000000e+00, double 6.000000e+00]]
@__const.jacobi.b = [3 x double] [double 1.200000e+01, double 2.700000e+01, double 3.600000e+01]
@.str = [43 x i8] c"\0A----------Question1_Jacobi : ----------\0A\0A\00"
@.str.1 = [68 x i8] c"Jacobi Method is failed! (Maximum number of iterations is reached)\0A\00"
@.str.2 = [45 x i8] c"Jacobi Method is converged in %d iterations.\00"
@.str.3 = [16 x i8] c"Solution, x: \0A\00"
@.str.4 = [41 x i8] c"\0A----------EndOfJacobiMethod----------\0A\0A\00"
define void @jacobi() {
%1 = alloca [3 x [3 x double]]
%2 = alloca [3 x double]
%3 = alloca [3 x [3 x double]]
%4 = alloca [3 x [3 x double]]
%5 = alloca [3 x [3 x double]]
%6 = alloca [3 x double]
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = alloca [3 x double]
%10 = alloca [3 x double]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = bitcast [3 x [3 x double]]* %1 to i8*
%16 = bitcast [3 x double]* %2 to i8*
%17 = bitcast [3 x [3 x double]]* %3 to i8*
%18 = bitcast [3 x [3 x double]]* %4 to i8*
%19 = bitcast [3 x [3 x double]]* %5 to i8*
%20 = bitcast [3 x double]* %6 to i8*
%21 = bitcast [3 x double]* %7 to i8*
%22 = bitcast [3 x double]* %8 to i8*
%23 = bitcast [3 x double]* %9 to i8*
%24 = bitcast [3 x double]* %10 to i8*
store i32 0, i32* %11
store i32 0, i32* %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %13
br label %26
26: ; preds = %84, %0
%27 = load i32, i32* %13
%28 = icmp slt i32 %27, 3
br i1 %28, label %29, label %87
29: ; preds = %26
store i32 0, i32* %14
br label %30
30: ; preds = %80, %29
%31 = load i32, i32* %14
%32 = icmp slt i32 %31, 3
br i1 %32, label %33, label %83
33: ; preds = %30
%34 = load i32, i32* %13
%35 = load i32, i32* %14
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %65
37: ; preds = %33
%38 = load i32, i32* %13
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 0, i64 %39
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x double], [3 x double]* %40, i64 0, i64 %42
%44 = load double, double* %43
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 %46
%48 = load i32, i32* %14
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [3 x double], [3 x double]* %47, i64 0, i64 %49
store double %44, double* %50
%51 = load i32, i32* %13
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 0, i64 %52
%54 = load i32, i32* %14
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [3 x double], [3 x double]* %53, i64 0, i64 %55
%57 = load double, double* %56
%58 = fdiv double 1.000000e+00, %57
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 %60
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [3 x double], [3 x double]* %61, i64 0, i64 %63
store double %58, double* %64
br label %79
65: ; preds = %33
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 0, i64 %67
%69 = load i32, i32* %14
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [3 x double], [3 x double]* %68, i64 0, i64 %70
%72 = load double, double* %71
%73 = load i32, i32* %13
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 %74
%76 = load i32, i32* %14
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [3 x double], [3 x double]* %75, i64 0, i64 %77
store double %72, double* %78
br label %79
79: ; preds = %65, %37
br label %80
80: ; preds = %79
%81 = load i32, i32* %14
%82 = add nsw i32 %81, 1
store i32 %82, i32* %14
br label %30
83: ; preds = %30
br label %84
84: ; preds = %83
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %26
87: ; preds = %26
br label %88
88: ; preds = %202, %87
%89 = load i32, i32* %11
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32, i32* %12
%93 = icmp slt i32 %92, 250
br label %94
94: ; preds = %91, %88
%95 = phi i1 [ false, %88 ], [ %93, %91 ]
br i1 %95, label %96, label %210
96: ; preds = %94
store i32 0, i32* %13
br label %97
97: ; preds = %110, %96
%98 = load i32, i32* %13
%99 = icmp slt i32 %98, 3
br i1 %99, label %100, label %113
100: ; preds = %97
%101 = load i32, i32* %13
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 %102
store double 0.000000e+00, double* %103
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 %105
store double 0.000000e+00, double* %106
%107 = load i32, i32* %13
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %108
store double 0.000000e+00, double* %109
br label %110
110: ; preds = %100
%111 = load i32, i32* %13
%112 = add nsw i32 %111, 1
store i32 %112, i32* %13
br label %97
113: ; preds = %97
store i32 0, i32* %13
br label %114
114: ; preds = %157, %113
%115 = load i32, i32* %13
%116 = icmp slt i32 %115, 3
br i1 %116, label %117, label %160
117: ; preds = %114
store i32 0, i32* %14
br label %118
118: ; preds = %141, %117
%119 = load i32, i32* %14
%120 = icmp slt i32 %119, 3
br i1 %120, label %121, label %144
121: ; preds = %118
%122 = load i32, i32* %13
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 %123
%125 = load double, double* %124
%126 = load i32, i32* %13
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 %127
%129 = load i32, i32* %14
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [3 x double], [3 x double]* %128, i64 0, i64 %130
%132 = load double, double* %131
%133 = load i32, i32* %14
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %134
%136 = load double, double* %135
%137 = call double @llvm.fmuladd.f64(double %132, double %136, double %125)
%138 = load i32, i32* %13
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 %139
store double %137, double* %140
br label %141
141: ; preds = %121
%142 = load i32, i32* %14
%143 = add nsw i32 %142, 1
store i32 %143, i32* %14
br label %118
144: ; preds = %118
%145 = load i32, i32* %13
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 %146
%148 = load double, double* %147
%149 = load i32, i32* %13
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 %150
%152 = load double, double* %151
%153 = fsub double %148, %152
%154 = load i32, i32* %13
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 %155
store double %153, double* %156
br label %157
157: ; preds = %144
%158 = load i32, i32* %13
%159 = add nsw i32 %158, 1
store i32 %159, i32* %13
br label %114
160: ; preds = %114
store i32 0, i32* %13
br label %161
161: ; preds = %199, %160
%162 = load i32, i32* %13
%163 = icmp slt i32 %162, 3
br i1 %163, label %164, label %202
164: ; preds = %161
store i32 0, i32* %14
br label %165
165: ; preds = %188, %164
%166 = load i32, i32* %14
%167 = icmp slt i32 %166, 3
br i1 %167, label %168, label %191
168: ; preds = %165
%169 = load i32, i32* %13
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %170
%172 = load double, double* %171
%173 = load i32, i32* %13
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 %174
%176 = load i32, i32* %14
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds [3 x double], [3 x double]* %175, i64 0, i64 %177
%179 = load double, double* %178
%180 = load i32, i32* %14
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 %181
%183 = load double, double* %182
%184 = call double @llvm.fmuladd.f64(double %179, double %183, double %172)
%185 = load i32, i32* %13
%186 = sext i32 %185 to i64
%187 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %186
store double %184, double* %187
br label %188
188: ; preds = %168
%189 = load i32, i32* %14
%190 = add nsw i32 %189, 1
store i32 %190, i32* %14
br label %165
191: ; preds = %165
%192 = load i32, i32* %13
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %193
%195 = load double, double* %194
%196 = load i32, i32* %13
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %197
store double %195, double* %198
br label %199
199: ; preds = %191
%200 = load i32, i32* %13
%201 = add nsw i32 %200, 1
store i32 %201, i32* %13
br label %161
202: ; preds = %161
%203 = load i32, i32* %12
%204 = add nsw i32 %203, 1
store i32 %204, i32* %12
%205 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 0, i64 0
%206 = bitcast [3 x double]* %205 to double**
%207 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%208 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%209 = call i32 @check_convergence(double** %206, double* %207, double* %208)
store i32 %209, i32* %11
br label %88
210: ; preds = %94
store i32 0, i32* %13
br label %211
211: ; preds = %242, %210
%212 = load i32, i32* %13
%213 = icmp slt i32 %212, 3
br i1 %213, label %214, label %245
214: ; preds = %211
store i32 0, i32* %14
br label %215
215: ; preds = %238, %214
%216 = load i32, i32* %14
%217 = icmp slt i32 %216, 3
br i1 %217, label %218, label %241
218: ; preds = %215
%219 = load i32, i32* %13
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 %220
%222 = load double, double* %221
%223 = load i32, i32* %13
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 0, i64 %224
%226 = load i32, i32* %14
%227 = sext i32 %226 to i64
%228 = getelementptr inbounds [3 x double], [3 x double]* %225, i64 0, i64 %227
%229 = load double, double* %228
%230 = load i32, i32* %14
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 %231
%233 = load double, double* %232
%234 = call double @llvm.fmuladd.f64(double %229, double %233, double %222)
%235 = load i32, i32* %13
%236 = sext i32 %235 to i64
%237 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 %236
store double %234, double* %237
br label %238
238: ; preds = %218
%239 = load i32, i32* %14
%240 = add nsw i32 %239, 1
store i32 %240, i32* %14
br label %215
241: ; preds = %215
br label %242
242: ; preds = %241
%243 = load i32, i32* %13
%244 = add nsw i32 %243, 1
store i32 %244, i32* %13
br label %211
245: ; preds = %211
%246 = load i32, i32* %12
%247 = icmp eq i32 %246, 250
br i1 %247, label %248, label %250
248: ; preds = %245
%249 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %256
250: ; preds = %245
%251 = load i32, i32* %12
%252 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %251)
%253 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%254 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%255 = call i32 @print_vector(double* %254, i32 3)
br label %256
256: ; preds = %250, %248
%257 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.jacobi.A = [3 x [3 x double]] [[3 x double] [double 1.000000e+00, double 1.000000e+00, double 2.000000e+00], [3 x double] [double 2.000000e+00, double 3.000000e+00, double 5.000000e+00], [3 x double] [double 3.000000e+00, double 3.000000e+00, double 6.000000e+00]]
@__const.jacobi.b = [3 x double] [double 1.200000e+01, double 2.700000e+01, double 3.600000e+01]
@.str.2 = [45 x i8] c"Jacobi Method is converged in %d iterations.\00"
@str = [42 x i8] c"\0A----------Question1_Jacobi : ----------\0A\00"
@str.5 = [15 x i8] c"Solution, x: \00"
@str.6 = [40 x i8] c"\0A----------EndOfJacobiMethod----------\0A\00"
@str.7 = [67 x i8] c"Jacobi Method is failed! (Maximum number of iterations is reached)\00"
define void @jacobi() {
%1 = alloca [3 x [3 x double]]
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = bitcast [3 x [3 x double]]* %1 to i8*
%5 = bitcast [3 x double]* %2 to i8*
%6 = bitcast [3 x double]* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%8 = bitcast [3 x [3 x double]]* %1 to double**
%9 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%10 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%11 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 1
%12 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 2
%13 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 2
%14 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 1
%15 = bitcast [3 x double]* %3 to <2 x double>*
br label %16
16: ; preds = %53, %0
%17 = phi double [ 3.600000e+01, %0 ], [ %59, %53 ]
%18 = phi double [ 2.700000e+01, %0 ], [ %58, %53 ]
%19 = phi double [ 1.200000e+01, %0 ], [ %57, %53 ]
%20 = phi double [ 0.000000e+00, %0 ], [ %56, %53 ]
%21 = phi double [ 0.000000e+00, %0 ], [ %55, %53 ]
%22 = phi double [ 0.000000e+00, %0 ], [ %54, %53 ]
%23 = phi i32 [ 0, %0 ], [ %48, %53 ]
%24 = call double @llvm.fmuladd.f64(double %22, double 0.000000e+00, double 0.000000e+00)
%25 = fadd double %21, %24
%26 = call double @llvm.fmuladd.f64(double %20, double 2.000000e+00, double %25)
%27 = fsub double %19, %26
%28 = call double @llvm.fmuladd.f64(double %22, double 2.000000e+00, double 0.000000e+00)
%29 = call double @llvm.fmuladd.f64(double %21, double 0.000000e+00, double %28)
%30 = call double @llvm.fmuladd.f64(double %20, double 5.000000e+00, double %29)
%31 = fsub double %18, %30
%32 = call double @llvm.fmuladd.f64(double %22, double 3.000000e+00, double 0.000000e+00)
%33 = call double @llvm.fmuladd.f64(double %21, double 3.000000e+00, double %32)
%34 = call double @llvm.fmuladd.f64(double %20, double 0.000000e+00, double %33)
%35 = fsub double %17, %34
%36 = fadd double %27, 0.000000e+00
%37 = call double @llvm.fmuladd.f64(double %27, double 0.000000e+00, double 0.000000e+00)
%38 = insertelement <2 x double> poison, double %31, i64 0
%39 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
%40 = insertelement <2 x double> poison, double %36, i64 0
%41 = insertelement <2 x double> %40, double %37, i64 1
%42 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> <double 0.000000e+00, double 0x3FD5555555555555>, <2 x double> %41)
%43 = insertelement <2 x double> poison, double %35, i64 0
%44 = shufflevector <2 x double> %43, <2 x double> poison, <2 x i32> zeroinitializer
%45 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> zeroinitializer, <2 x double> %42)
store <2 x double> %45, <2 x double>* %15
%46 = call double @llvm.fmuladd.f64(double %31, double 0.000000e+00, double %37)
%47 = call double @llvm.fmuladd.f64(double %35, double 0x3FC5555555555555, double %46)
store double %47, double* %12
%48 = add nuw nsw i32 %23, 1
%49 = call i32 @check_convergence(double** %8, double* %9, double* %10)
%50 = icmp eq i32 %49, 0
%51 = icmp ult i32 %23, 249
%52 = select i1 %50, i1 %51, i1 false
br i1 %52, label %53, label %60
53: ; preds = %16
%54 = load double, double* %9
%55 = load double, double* %11
%56 = load double, double* %12
%57 = load double, double* %10
%58 = load double, double* %14
%59 = load double, double* %13
br label %16
60: ; preds = %16
%61 = icmp eq i32 %48, 250
br i1 %61, label %62, label %64
62: ; preds = %60
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.7, i64 0, i64 0))
br label %68
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%67 = call i32 @print_vector(double* %9, i32 3)
br label %68
68: ; preds = %64, %62
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.6, i64 0, i64 0))
ret void
}