#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*/ free(double *);
scalar_t__ malloc(int);
void jacobi(int nsweeps, int n, double *u, double *f) {
  int i, sweep;
  double h = 1.0 / n;
  double h2 = h * h;
  double *utmp = (double *)malloc((n + 1) * sizeof(double));
  utmp[0] = u[0];
  utmp[n] = u[n];
#pragma omp parallel for
  for (sweep = 0; sweep < nsweeps; sweep += 2) {
#pragma omp parallel for
    for (i = 1; i < n; i++) {
      utmp[i] = (u[i - 1] + u[i + 1] + h2 * f[i]) / 2;
      if (i > 1) {
        u[i - 1] = (utmp[i - 2] + utmp[i] + h2 * f[i - 1]) / 2;
        if (i == n - 1) {
          u[i] = (utmp[i - 1] + utmp[i + 1] + h2 * f[i]) / 2;
        }
      }
    }
  }
  free(utmp);
}


x86 assembly (clang, -O0):
<jacobi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xebd(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1312 <jacobi+0x1f2>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ff <jacobi+0x1df>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe00(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cmpl   $0x1,-0x1c(%rbp)
jle    12ec <jacobi+0x1cc>
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd9f(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12e7 <jacobi+0x1c7>
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd32(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12ec <jacobi+0x1cc>
jmp    12f1 <jacobi+0x1d1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <jacobi+0x96>
jmp    1304 <jacobi+0x1e4>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11a3 <jacobi+0x83>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jacobi>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r12d
lea    0x8(,%r15,8),%edi
call   1040 <malloc@plt>
movsd  (%rbx),%xmm0
movsd  %xmm0,(%rax)
movslq %r15d,%rcx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
test   %r12d,%r12d
jle    124a <jacobi+0x12a>
cvtsi2sd %r15d,%xmm1
movsd  0xe94(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
lea    -0x1(%r15),%r8d
mov    %r15d,%edx
lea    -0x2(%r8),%rsi
add    $0xfffffffffffffffe,%rdx
xor    %edi,%edi
movsd  0xe7b(%rip),%xmm1
jmp    119c <jacobi+0x7c>
nop
add    $0x2,%edi
cmp    %r12d,%edi
jge    124a <jacobi+0x12a>
cmp    $0x2,%r15d
jl     1190 <jacobi+0x70>
movsd  (%rbx),%xmm2
addsd  0x10(%rbx),%xmm2
movsd  0x8(%r14),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rax)
je     1190 <jacobi+0x70>
xor    %ebp,%ebp
jmp    11d9 <jacobi+0xb9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%rdx
je     1190 <jacobi+0x70>
movsd  0x8(%rbx,%rbp,8),%xmm2
addsd  0x18(%rbx,%rbp,8),%xmm2
movsd  0x10(%r14,%rbp,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x10(%rax,%rbp,8)
mov    %ebp,%ecx
addsd  (%rax,%rcx,8),%xmm3
movsd  0x8(%r14,%rbp,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rbx,%rbp,8)
cmp    %rbp,%rsi
jne    11d0 <jacobi+0xb0>
movsd  0x8(%rax,%rbp,8),%xmm2
addsd  0x18(%rax,%rbp,8),%xmm2
movsd  0x10(%r14,%rbp,8),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
movsd  %xmm3,(%rbx,%r8,8)
jmp    11d0 <jacobi+0xb0>
mov    %rax,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @jacobi(i32 %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double*
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %11
%17 = load double, double* %11
%18 = load double, double* %11
%19 = fmul double %17, %18
store double %19, double* %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %13
%27 = load double*, double** %7
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
%30 = load double*, double** %13
%31 = getelementptr inbounds double, double* %30, i64 0
store double %29, double* %31
%32 = load double*, double** %7
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %13
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
store double %36, double* %40
store i32 0, i32* %10
br label %41
41: ; preds = %141, %4
%42 = load i32, i32* %10
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %144
45: ; preds = %41
store i32 1, i32* %9
br label %46
46: ; preds = %137, %45
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %140
50: ; preds = %46
%51 = load double*, double** %7
%52 = load i32, i32* %9
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %7
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %57, i64 %60
%62 = load double, double* %61
%63 = fadd double %56, %62
%64 = load double, double* %12
%65 = load double*, double** %8
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = call double @llvm.fmuladd.f64(double %64, double %69, double %63)
%71 = fdiv double %70, 2.000000e+00
%72 = load double*, double** %13
%73 = load i32, i32* %9
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
store double %71, double* %75
%76 = load i32, i32* %9
%77 = icmp sgt i32 %76, 1
br i1 %77, label %78, label %136
78: ; preds = %50
%79 = load double*, double** %13
%80 = load i32, i32* %9
%81 = sub nsw i32 %80, 2
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %79, i64 %82
%84 = load double, double* %83
%85 = load double*, double** %13
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
%89 = load double, double* %88
%90 = fadd double %84, %89
%91 = load double, double* %12
%92 = load double*, double** %8
%93 = load i32, i32* %9
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %92, i64 %95
%97 = load double, double* %96
%98 = call double @llvm.fmuladd.f64(double %91, double %97, double %90)
%99 = fdiv double %98, 2.000000e+00
%100 = load double*, double** %7
%101 = load i32, i32* %9
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %100, i64 %103
store double %99, double* %104
%105 = load i32, i32* %9
%106 = load i32, i32* %6
%107 = sub nsw i32 %106, 1
%108 = icmp eq i32 %105, %107
br i1 %108, label %109, label %135
109: ; preds = %78
%110 = load double*, double** %13
%111 = load i32, i32* %9
%112 = sub nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds double, double* %110, i64 %113
%115 = load double, double* %114
%116 = load double*, double** %13
%117 = load i32, i32* %9
%118 = add nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %116, i64 %119
%121 = load double, double* %120
%122 = fadd double %115, %121
%123 = load double, double* %12
%124 = load double*, double** %8
%125 = load i32, i32* %9
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds double, double* %124, i64 %126
%128 = load double, double* %127
%129 = call double @llvm.fmuladd.f64(double %123, double %128, double %122)
%130 = fdiv double %129, 2.000000e+00
%131 = load double*, double** %7
%132 = load i32, i32* %9
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds double, double* %131, i64 %133
store double %130, double* %134
br label %135
135: ; preds = %109, %78
br label %136
136: ; preds = %135, %50
br label %137
137: ; preds = %136
%138 = load i32, i32* %9
%139 = add nsw i32 %138, 1
store i32 %139, i32* %9
br label %46
140: ; preds = %46
br label %141
141: ; preds = %140
%142 = load i32, i32* %10
%143 = add nsw i32 %142, 2
store i32 %143, i32* %10
br label %41
144: ; preds = %41
%145 = load double*, double** %13
%146 = call i32 @free(double* %145)
ret void
}

LLVM IR (-O2):
define void @jacobi(i32 %0, i32 %1, double* nocapture %2, double* nocapture %3) {
%5 = sitofp i32 %1 to double
%6 = fdiv double 1.000000e+00, %5
%7 = fmul double %6, %6
%8 = shl i32 %1, 3
%9 = add i32 %8, 8
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double*
%12 = load double, double* %2
store double %12, double* %11
%13 = sext i32 %1 to i64
%14 = getelementptr inbounds double, double* %2, i64 %13
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %11, i64 %13
store double %15, double* %16
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %75
18: ; preds = %4
%19 = icmp sgt i32 %1, 1
%20 = add nsw i32 %1, -1
%21 = zext i32 %20 to i64
%22 = zext i32 %1 to i64
%23 = getelementptr inbounds double, double* %2, i64 2
%24 = getelementptr inbounds double, double* %3, i64 1
%25 = getelementptr inbounds double, double* %11, i64 1
%26 = icmp eq i32 %1, 2
%27 = getelementptr inbounds double, double* %2, i64 %21
br label %28
28: ; preds = %18, %72
%29 = phi i32 [ 0, %18 ], [ %73, %72 ]
br i1 %19, label %30, label %72
30: ; preds = %28
%31 = load double, double* %2
%32 = load double, double* %23
%33 = fadd double %31, %32
%34 = load double, double* %24
%35 = tail call double @llvm.fmuladd.f64(double %7, double %34, double %33)
%36 = fmul double %35, 5.000000e-01
store double %36, double* %25
br i1 %26, label %72, label %37
37: ; preds = %30, %70
%38 = phi i64 [ %42, %70 ], [ 2, %30 ]
%39 = add nsw i64 %38, -1
%40 = getelementptr inbounds double, double* %2, i64 %39
%41 = load double, double* %40
%42 = add nuw nsw i64 %38, 1
%43 = getelementptr inbounds double, double* %2, i64 %42
%44 = load double, double* %43
%45 = fadd double %41, %44
%46 = getelementptr inbounds double, double* %3, i64 %38
%47 = load double, double* %46
%48 = tail call double @llvm.fmuladd.f64(double %7, double %47, double %45)
%49 = fmul double %48, 5.000000e-01
%50 = getelementptr inbounds double, double* %11, i64 %38
store double %49, double* %50
%51 = add nuw i64 %38, 4294967294
%52 = and i64 %51, 4294967295
%53 = getelementptr inbounds double, double* %11, i64 %52
%54 = load double, double* %53
%55 = fadd double %49, %54
%56 = getelementptr inbounds double, double* %3, i64 %39
%57 = load double, double* %56
%58 = tail call double @llvm.fmuladd.f64(double %7, double %57, double %55)
%59 = fmul double %58, 5.000000e-01
store double %59, double* %40
%60 = icmp eq i64 %38, %21
br i1 %60, label %61, label %70
61: ; preds = %37
%62 = getelementptr inbounds double, double* %11, i64 %39
%63 = load double, double* %62
%64 = getelementptr inbounds double, double* %11, i64 %42
%65 = load double, double* %64
%66 = fadd double %63, %65
%67 = load double, double* %46
%68 = tail call double @llvm.fmuladd.f64(double %7, double %67, double %66)
%69 = fmul double %68, 5.000000e-01
store double %69, double* %27
br label %70
70: ; preds = %61, %37
%71 = icmp eq i64 %42, %22
br i1 %71, label %72, label %37
72: ; preds = %70, %30, %28
%73 = add nuw nsw i32 %29, 2
%74 = icmp slt i32 %73, %0
br i1 %74, label %28, label %75
75: ; preds = %72, %4
%76 = tail call i32 @free(double* %11)
ret void
}