#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 */
double *calloc(int, int);
int /*<<< orphan*/ free(double *);
double get_norm(double *, double *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ show_vector(double *, int);
double summation(int, int, double **, double *);
double *jacobi(double **a, double *b, double *x, double delta, int N,
               int MAX_ITE) {
  int s = 0, i = 0, m = 0;
  double norm = 0.00;
  double *u = calloc(N, sizeof(double));
  bool flag = true;
  for (s = 0; s < MAX_ITE && flag; s++) {
    for (i = 0; i < N; i++) {
      u[i] = (b[i] - summation(i, N, a, x)) / a[i][i];
    }
    norm = get_norm(u, x, N);
    flag = norm > delta;
    for (m = 0; m < N; m++) {
      x[m] = u[m];
    }
    printf("The %dº approximation is: \n", (s + 1));
    show_vector(u, N);
    printf("The norm is: %lf\n", norm);
    printf("\n");
  }
  free(u);
  return (x);
}


x86 assembly (clang, -O0):
<jacobi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x28(%rbp),%ecx
mov    %al,-0x4d(%rbp)
jge    11d7 <jacobi+0x77>
cmpl   $0x0,-0x4c(%rbp)
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    11e7 <jacobi+0x87>
jmp    130f <jacobi+0x1af>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125b <jacobi+0xfb>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1080 <summation@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ee <jacobi+0x8e>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <get_norm@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12c0 <jacobi+0x160>
mov    -0x48(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    128c <jacobi+0x12c>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <show_vector@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xd31(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bc <jacobi+0x5c>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jacobi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r12d
mov    %ecx,%r13d
movsd  %xmm0,0x18(%rsp)
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %ecx,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %r12d,0xc(%rsp)
test   %r12d,%r12d
mov    %rax,%r12
jle    12e5 <jacobi+0x165>
mov    %r13d,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
test   %r13d,%r13d
jle    1280 <jacobi+0x100>
mov    %ebp,0x8(%rsp)
mov    %r12,%rbp
mov    %r15,%r12
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12,%r15,8),%xmm0
movsd  %xmm0,(%rsp)
mov    %r15d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10a0 <summation@plt>
mov    0x20(%rsp),%rdx
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mov    (%rbx,%r15,8),%rax
divsd  (%rax,%r15,8),%xmm1
movsd  %xmm1,0x0(%rbp,%r15,8)
add    $0x1,%r15
cmp    %r15,%rdx
jne    1200 <jacobi+0x80>
mov    %r12,%r15
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <get_norm@plt>
movsd  %xmm0,(%rsp)
mov    %r13d,%r12d
test   %r13d,%r13d
jle    126f <jacobi+0xef>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rdx
call   1080 <memcpy@plt>
mov    %r12d,%r13d
mov    %rbp,%r12
mov    0x8(%rsp),%ebp
jmp    1293 <jacobi+0x113>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1050 <get_norm@plt>
movsd  %xmm0,(%rsp)
add    $0x1,%ebp
lea    0xd63(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13d,%esi
call   1090 <show_vector@plt>
lea    0xd65(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    0xc(%rsp),%ebp
jge    12e5 <jacobi+0x165>
movsd  (%rsp),%xmm0
ucomisd 0x18(%rsp),%xmm0
ja     11e0 <jacobi+0x60>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [29 x i8] c"The %d\C2\BA approximation is: \0A\00"
@.str.1 = [18 x i8] c"The norm is: %lf\0A\00"
define double* @jacobi(double** %0, double* nocapture %1, double* returned %2, double %3, i32 %4, i32 %5) {
%7 = bitcast double* %2 to i8*
%8 = tail call double* @calloc(i32 %4, i32 8)
%9 = bitcast double* %8 to i8*
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %47
11: ; preds = %6
%12 = icmp sgt i32 %4, 0
%13 = zext i32 %4 to i64
%14 = shl nuw nsw i64 %13, 3
br label %15
15: ; preds = %11, %37
%16 = phi i32 [ 0, %11 ], [ %40, %37 ]
br i1 %12, label %19, label %17
17: ; preds = %15
%18 = tail call double @get_norm(double* %8, double* %2, i32 %4)
br label %37
19: ; preds = %15, %19
%20 = phi i64 [ %32, %19 ], [ 0, %15 ]
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = trunc i64 %20 to i32
%24 = tail call double @summation(i32 %23, i32 %4, double** %0, double* %2)
%25 = fsub double %22, %24
%26 = getelementptr inbounds double*, double** %0, i64 %20
%27 = load double*, double** %26
%28 = getelementptr inbounds double, double* %27, i64 %20
%29 = load double, double* %28
%30 = fdiv double %25, %29
%31 = getelementptr inbounds double, double* %8, i64 %20
store double %30, double* %31
%32 = add nuw nsw i64 %20, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %34, label %19
34: ; preds = %19
%35 = tail call double @get_norm(double* %8, double* %2, i32 %4)
br i1 %12, label %36, label %37
36: ; preds = %34
br label %37
37: ; preds = %17, %36, %34
%38 = phi double [ %18, %17 ], [ %35, %36 ], [ %35, %34 ]
%39 = fcmp ogt double %38, %3
%40 = add nuw nsw i32 %16, 1
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = tail call i32 @show_vector(double* %8, i32 %4)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %38)
%44 = tail call i32 @putchar(i32 10)
%45 = icmp slt i32 %40, %5
%46 = select i1 %45, i1 %39, i1 false
br i1 %46, label %15, label %47
47: ; preds = %37, %6
%48 = tail call i32 @free(double* %8)
ret double* %2
}