#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 M_PI;
double atof(char *);
int atoi(char *);
double cpu_time();
double *dalloc_matrix(int, int);
int /*<<< orphan*/ dfree_matrix(double *);
int /*<<< orphan*/ error_check(int, double, double, double *);
int /*<<< orphan*/ initialize(int, double *, double *, double *, double *);
int /*<<< orphan*/ jacobi(int, double, double, double, double *, double *,
                          double, int);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int main(int argc, char **argv) {
  int n, m, mits;
  double tol, relax, alpha;
  double *u, *f, dx, dy;
  double dt, start, end, mflops;
  m = n = 100;
  relax = 1.0;
  tol = 1.0e-5;
  mits = 1000;
  if (argc == 4) {
    n = atoi(argv[1]);
    tol = atof(argv[2]);
    mits = atoi(argv[3]);
  } else {
    printf("Use: ./jacobi <n> <tol> <mits>\n");
    printf("where\n");
    printf("   <n>     : numero de pontos em X e Y (default 100)\n");
    printf("   <tol>   : tolerancia do erro (default 1e-5)\n");
    printf("   <mits>  : numero maximo de iteracoes (default 1000)\n");
  }
  printf("-> %d, %g, %g, %d\n", n, relax, tol, mits);
  u = dalloc_matrix(n, m);
  f = dalloc_matrix(n, m);
  initialize(n, &dx, &dy, u, f);
  double pi = M_PI;
  relax = 2.0 / (1.0 + sin(pi * dx));
  printf("relax parameter: %f \n", relax);
  start = cpu_time();
  jacobi(n, dx, dy, relax, u, f, tol, mits);
  end = cpu_time();
  dt = end - start;
  printf(" elapsed time : %12.6f\n", dt);
  mflops = (0.000001 * mits * (m - 2) * (n - 2) * 13) / dt;
  printf(" MFlops       : %12.6g (%d, %d, %d, %g)\n", mflops, mits, m, n, dt);
  error_check(n, dx, dy, u);
  dfree_matrix(u);
  dfree_matrix(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x64,-0x18(%rbp)
movsd  0xe39(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe24(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x3e8,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1229 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    126f <main+0xcf>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x1c(%rbp),%edx
lea    0xe67(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <dalloc_matrix@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <dalloc_matrix@plt>
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1080 <initialize@plt>
mov    0x2d1e(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
call   1090 <sin@plt>
movsd  0xd1e(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xd2a(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10c0 <cpu_time@plt>
movsd  %xmm0,-0x68(%rbp)
mov    -0x14(%rbp),%edi
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
movsd  -0x28(%rbp),%xmm3
mov    -0x1c(%rbp),%ecx
call   1030 <jacobi@plt>
mov    $0x0,%al
call   10c0 <cpu_time@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xdaa(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xc98(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc68(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
movsd  -0x60(%rbp),%xmm1
lea    0xd5e(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
mov    -0x40(%rbp),%rsi
call   10b0 <error_check@plt>
mov    -0x40(%rbp),%rdi
call   1070 <dfree_matrix@plt>
mov    -0x48(%rbp),%rdi
call   1070 <dfree_matrix@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x4,%edi
jne    11e9 <main+0x39>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1050 <atof@plt>
movsd  %xmm0,(%rsp)
mov    0x18(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
jmp    123d <main+0x8d>
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xebd(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xee0(%rip),%rdi
call   1040 <puts@plt>
lea    0xf03(%rip),%rdi
call   1040 <puts@plt>
mov    $0x64,%ebx
mov    $0x3e8,%r14d
movsd  0xdc8(%rip),%xmm0
movsd  %xmm0,(%rsp)
lea    0xdec(%rip),%rdi
movsd  0xdbc(%rip),%xmm0
mov    %ebx,%esi
movsd  (%rsp),%xmm1
mov    %r14d,%edx
mov    $0x2,%al
call   1060 <printf@plt>
mov    %ebx,%edi
mov    $0x64,%esi
call   1070 <dalloc_matrix@plt>
mov    %rax,%rbp
mov    %ebx,%edi
mov    $0x64,%esi
call   1070 <dalloc_matrix@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rcx
mov    %rax,%r8
call   1090 <initialize@plt>
mov    0x2d4f(%rip),%rax
movsd  (%rax),%xmm0
mulsd  0x8(%rsp),%xmm0
call   10a0 <sin@plt>
addsd  0xd58(%rip),%xmm0
movsd  0xd58(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
lea    0xd7a(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   10d0 <cpu_time@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm2
mov    %rbp,%rsi
mov    %r15,%rdx
movsd  (%rsp),%xmm3
mov    %r14d,%ecx
call   1030 <jacobi@plt>
xor    %eax,%eax
call   10d0 <cpu_time@plt>
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0xd38(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  0xce0(%rip),%xmm1
mulsd  0xce0(%rip),%xmm1
lea    -0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xcd2(%rip),%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
lea    0xd0b(%rip),%rdi
mov    %r14d,%esi
mov    $0x64,%edx
mov    %ebx,%ecx
mov    $0x2,%al
call   1060 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <error_check@plt>
mov    %rbp,%rdi
call   1080 <dfree_matrix@plt>
mov    %r15,%rdi
call   1080 <dfree_matrix@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Use: ./jacobi <n> <tol> <mits>\0A\00"
@.str.1 = [7 x i8] c"where\0A\00"
@.str.2 = [54 x i8] c" <n> : numero de pontos em X e Y (default 100)\0A\00"
@.str.3 = [48 x i8] c" <tol> : tolerancia do erro (default 1e-5)\0A\00"
@.str.4 = [56 x i8] c" <mits> : numero maximo de iteracoes (default 1000)\0A\00"
@.str.5 = [19 x i8] c"-> %d, %g, %g, %d\0A\00"
@M_PI = global double 0.000000e+00
@.str.6 = [22 x i8] c"relax parameter: %f \0A\00"
@.str.7 = [24 x i8] c" elapsed time : %12.6f\0A\00"
@.str.8 = [41 x i8] c" MFlops : %12.6g (%d, %d, %d, %g)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double*
%13 = alloca double*
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %6
store i32 100, i32* %7
store double 1.000000e+00, double* %10
store double 1.000000e-05, double* %9
store i32 1000, i32* %8
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %36
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call double @atof(i8* %30)
store double %31, double* %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %8
br label %42
36: ; preds = %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %36, %23
%43 = load i32, i32* %6
%44 = load double, double* %10
%45 = load double, double* %9
%46 = load i32, i32* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %43, double %44, double %45, i32 %46)
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = call double* @dalloc_matrix(i32 %48, i32 %49)
store double* %50, double** %12
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call double* @dalloc_matrix(i32 %51, i32 %52)
store double* %53, double** %13
%54 = load i32, i32* %6
%55 = load double*, double** %12
%56 = load double*, double** %13
%57 = call i32 @initialize(i32 %54, double* %14, double* %15, double* %55, double* %56)
%58 = load double, double* @M_PI
store double %58, double* %20
%59 = load double, double* %20
%60 = load double, double* %14
%61 = fmul double %59, %60
%62 = call double @sin(double %61)
%63 = fadd double 1.000000e+00, %62
%64 = fdiv double 2.000000e+00, %63
store double %64, double* %10
%65 = load double, double* %10
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), double %65)
%67 = call double (...) @cpu_time()
store double %67, double* %17
%68 = load i32, i32* %6
%69 = load double, double* %14
%70 = load double, double* %15
%71 = load double, double* %10
%72 = load double*, double** %12
%73 = load double*, double** %13
%74 = load double, double* %9
%75 = load i32, i32* %8
%76 = call i32 @jacobi(i32 %68, double %69, double %70, double %71, double* %72, double* %73, double %74, i32 %75)
%77 = call double (...) @cpu_time()
store double %77, double* %18
%78 = load double, double* %18
%79 = load double, double* %17
%80 = fsub double %78, %79
store double %80, double* %16
%81 = load double, double* %16
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %81)
%83 = load i32, i32* %8
%84 = sitofp i32 %83 to double
%85 = fmul double 0x3EB0C6F7A0B5ED8D, %84
%86 = load i32, i32* %7
%87 = sub nsw i32 %86, 2
%88 = sitofp i32 %87 to double
%89 = fmul double %85, %88
%90 = load i32, i32* %6
%91 = sub nsw i32 %90, 2
%92 = sitofp i32 %91 to double
%93 = fmul double %89, %92
%94 = fmul double %93, 1.300000e+01
%95 = load double, double* %16
%96 = fdiv double %94, %95
store double %96, double* %19
%97 = load double, double* %19
%98 = load i32, i32* %8
%99 = load i32, i32* %7
%100 = load i32, i32* %6
%101 = load double, double* %16
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %97, i32 %98, i32 %99, i32 %100, double %101)
%103 = load i32, i32* %6
%104 = load double, double* %14
%105 = load double, double* %15
%106 = load double*, double** %12
%107 = call i32 @error_check(i32 %103, double %104, double %105, double* %106)
%108 = load double*, double** %12
%109 = call i32 @dfree_matrix(double* %108)
%110 = load double*, double** %13
%111 = call i32 @dfree_matrix(double* %110)
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [19 x i8] c"-> %d, %g, %g, %d\0A\00"
@M_PI = global double 0.000000e+00
@.str.6 = [22 x i8] c"relax parameter: %f \0A\00"
@.str.7 = [24 x i8] c" elapsed time : %12.6f\0A\00"
@.str.8 = [41 x i8] c" MFlops : %12.6g (%d, %d, %d, %g)\0A\00"
@str = [31 x i8] c"Use: ./jacobi <n> <tol> <mits>\00"
@str.9 = [6 x i8] c"where\00"
@str.10 = [53 x i8] c" <n> : numero de pontos em X e Y (default 100)\00"
@str.11 = [47 x i8] c" <tol> : tolerancia do erro (default 1e-5)\00"
@str.12 = [55 x i8] c" <mits> : numero maximo de iteracoes (default 1000)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %3 to i8*
%6 = bitcast double* %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call double @atof(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
br label %24
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.11, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.12, i64 0, i64 0))
br label %24
24: ; preds = %18, %8
%25 = phi double [ %14, %8 ], [ 1.000000e-05, %18 ]
%26 = phi i32 [ %17, %8 ], [ 1000, %18 ]
%27 = phi i32 [ %11, %8 ], [ 100, %18 ]
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %27, double 1.000000e+00, double %25, i32 %26)
%29 = tail call double* @dalloc_matrix(i32 %27, i32 100)
%30 = tail call double* @dalloc_matrix(i32 %27, i32 100)
%31 = call i32 @initialize(i32 %27, double* %3, double* %4, double* %29, double* %30)
%32 = load double, double* @M_PI
%33 = load double, double* %3
%34 = fmul double %32, %33
%35 = call double @sin(double %34)
%36 = fadd double %35, 1.000000e+00
%37 = fdiv double 2.000000e+00, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), double %37)
%39 = call double (...) @cpu_time()
%40 = load double, double* %3
%41 = load double, double* %4
%42 = call i32 @jacobi(i32 %27, double %40, double %41, double %37, double* %29, double* %30, double %25, i32 %26)
%43 = call double (...) @cpu_time()
%44 = fsub double %43, %39
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %44)
%46 = sitofp i32 %26 to double
%47 = fmul double %46, 0x3EB0C6F7A0B5ED8D
%48 = fmul double %47, 9.800000e+01
%49 = add nsw i32 %27, -2
%50 = sitofp i32 %49 to double
%51 = fmul double %48, %50
%52 = fmul double %51, 1.300000e+01
%53 = fdiv double %52, %44
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %53, i32 %26, i32 100, i32 %27, double %44)
%55 = load double, double* %3
%56 = load double, double* %4
%57 = call i32 @error_check(i32 %27, double %55, double %56, double* %29)
%58 = call i32 @dfree_matrix(double* %29)
%59 = call i32 @dfree_matrix(double* %30)
ret i32 0
}