#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 acos(double);
double atof(char *);
int atoi(char *);
double cpu_time();
double **dalloc_matrix(int, int);
int /*<<< orphan*/ dfree_matrix(double **, int);
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,
                          int);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int main(int argc, char **argv) {
  int n, m, mits;
  double tol, relax;
  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 = acos(-1.0);
  relax = 2.0 / (1.0 + sin(pi * dx));
  printf("relax parameter: %f \n", relax);
  start = cpu_time();
  jacobi(n, dx, 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, n);
  dfree_matrix(f, n);
  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  0xe29(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe14(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x3e8,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1239 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <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   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    127f <main+0xcf>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe45(%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    0xe5f(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <dalloc_matrix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <dalloc_matrix@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1090 <initialize@plt>
movsd  0xd4d(%rip),%xmm0
call   1080 <acos@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
call   10a0 <sin@plt>
movsd  0xd0c(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xd18(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdeb(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10d0 <cpu_time@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x14(%rbp),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
movsd  -0x28(%rbp),%xmm2
mov    -0x1c(%rbp),%ecx
call   1030 <jacobi@plt>
mov    $0x0,%al
call   10d0 <cpu_time@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
lea    0xda5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xc8b(%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  0xc5b(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
movsd  -0x58(%rbp),%xmm1
lea    0xd59(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x38(%rbp),%rsi
call   10c0 <error_check@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <dfree_matrix@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
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    0xeb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf0b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x64,%ebx
mov    $0x3e8,%r14d
movsd  0xdc8(%rip),%xmm0
movsd  %xmm0,(%rsp)
lea    0xdf4(%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    0x20(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rcx
mov    %rax,%r8
call   1090 <initialize@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0xd70(%rip),%xmm0
call   10a0 <sin@plt>
addsd  0xd5b(%rip),%xmm0
movsd  0xd63(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xd85(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
call   10d0 <cpu_time@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
movsd  0x10(%rsp),%xmm1
mov    %rbp,%rsi
mov    %r15,%rdx
movsd  (%rsp),%xmm2
mov    %r14d,%ecx
call   1030 <jacobi@plt>
xor    %eax,%eax
call   10d0 <cpu_time@plt>
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0xd49(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  0xcf1(%rip),%xmm1
mulsd  0xcf1(%rip),%xmm1
lea    -0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xce3(%rip),%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
lea    0xd1c(%rip),%rdi
mov    %r14d,%esi
mov    $0x64,%edx
mov    %ebx,%ecx
mov    $0x2,%al
call   1060 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <error_check@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1080 <dfree_matrix@plt>
mov    %r15,%rdi
mov    %ebx,%esi
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"
@.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
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
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %35
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call double @atof(i8* %29)
store double %30, double* %9
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %8
br label %41
35: ; preds = %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %35, %22
%42 = load i32, i32* %6
%43 = load double, double* %10
%44 = load double, double* %9
%45 = load i32, i32* %8
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %42, double %43, double %44, i32 %45)
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call double** @dalloc_matrix(i32 %47, i32 %48)
store double** %49, double*** %11
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call double** @dalloc_matrix(i32 %50, i32 %51)
store double** %52, double*** %12
%53 = load i32, i32* %6
%54 = load double**, double*** %11
%55 = load double**, double*** %12
%56 = call i32 @initialize(i32 %53, double* %13, double* %14, double** %54, double** %55)
%57 = call double @acos(double -1.000000e+00)
store double %57, double* %19
%58 = load double, double* %19
%59 = load double, double* %13
%60 = fmul double %58, %59
%61 = call double @sin(double %60)
%62 = fadd double 1.000000e+00, %61
%63 = fdiv double 2.000000e+00, %62
store double %63, double* %10
%64 = load double, double* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), double %64)
%66 = call double (...) @cpu_time()
store double %66, double* %16
%67 = load i32, i32* %6
%68 = load double, double* %13
%69 = load double, double* %10
%70 = load double**, double*** %11
%71 = load double**, double*** %12
%72 = load double, double* %9
%73 = load i32, i32* %8
%74 = call i32 @jacobi(i32 %67, double %68, double %69, double** %70, double** %71, double %72, i32 %73)
%75 = call double (...) @cpu_time()
store double %75, double* %17
%76 = load double, double* %17
%77 = load double, double* %16
%78 = fsub double %76, %77
store double %78, double* %15
%79 = load double, double* %15
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %79)
%81 = load i32, i32* %8
%82 = sitofp i32 %81 to double
%83 = fmul double 0x3EB0C6F7A0B5ED8D, %82
%84 = load i32, i32* %7
%85 = sub nsw i32 %84, 2
%86 = sitofp i32 %85 to double
%87 = fmul double %83, %86
%88 = load i32, i32* %6
%89 = sub nsw i32 %88, 2
%90 = sitofp i32 %89 to double
%91 = fmul double %87, %90
%92 = fmul double %91, 1.300000e+01
%93 = load double, double* %15
%94 = fdiv double %92, %93
store double %94, double* %18
%95 = load double, double* %18
%96 = load i32, i32* %8
%97 = load i32, i32* %7
%98 = load i32, i32* %6
%99 = load double, double* %15
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %95, i32 %96, i32 %97, i32 %98, double %99)
%101 = load i32, i32* %6
%102 = load double, double* %13
%103 = load double, double* %14
%104 = load double**, double*** %11
%105 = call i32 @error_check(i32 %101, double %102, double %103, double** %104)
%106 = load double**, double*** %11
%107 = load i32, i32* %6
%108 = call i32 @dfree_matrix(double** %106, i32 %107)
%109 = load double**, double*** %12
%110 = load i32, i32* %6
%111 = call i32 @dfree_matrix(double** %109, i32 %110)
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [19 x i8] c"-> %d, %g, %g, %d\0A\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* %3
%33 = fmul double %32, 0x400921FB54442D18
%34 = call double @sin(double %33)
%35 = fadd double %34, 1.000000e+00
%36 = fdiv double 2.000000e+00, %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), double %36)
%38 = call double (...) @cpu_time()
%39 = load double, double* %3
%40 = call i32 @jacobi(i32 %27, double %39, double %36, double** %29, double** %30, double %25, i32 %26)
%41 = call double (...) @cpu_time()
%42 = fsub double %41, %38
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %42)
%44 = sitofp i32 %26 to double
%45 = fmul double %44, 0x3EB0C6F7A0B5ED8D
%46 = fmul double %45, 9.800000e+01
%47 = add nsw i32 %27, -2
%48 = sitofp i32 %47 to double
%49 = fmul double %46, %48
%50 = fmul double %49, 1.300000e+01
%51 = fdiv double %50, %42
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %51, i32 %26, i32 100, i32 %27, double %42)
%53 = load double, double* %3
%54 = load double, double* %4
%55 = call i32 @error_check(i32 %27, double %53, double %54, double** %29)
%56 = call i32 @dfree_matrix(double** %29, i32 %27)
%57 = call i32 @dfree_matrix(double** %30, i32 %27)
ret i32 0
}