#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*/ __assume_aligned(double *, int);
int /*<<< orphan*/ memcpy(double *, double *, int const);
void apply_tri_special(double *restrict u, double *restrict u_temp,
                       const double a, const double b, const int n) {
  __assume_aligned(u, 64);
  __assume_aligned(u_temp, 64);
  memcpy(u_temp, u, n * sizeof(double));
  int N = n - 1;
  for (int i = 1; i < N; i++)
    u[i] = a * (u_temp[i - 1] + u_temp[i + 1]) + b * u_temp[i];
  u[0] = 0.0;
  u[N] = 0.0;
}


x86 assembly (clang, -O0):
<apply_tri_special>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x40,%esi
call   1030 <__assume_aligned@plt>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1030 <__assume_aligned@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11ea <apply_tri_special+0xca>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1180 <apply_tri_special+0x60>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_tri_special>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x40,%esi
call   1030 <__assume_aligned@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <__assume_aligned@plt>
lea    0x0(,%r15,8),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
lea    -0x1(%r15),%eax
cmp    $0x3,%r15d
jl     1240 <apply_tri_special+0x120>
mov    %eax,%r8d
movsd  (%rbx),%xmm3
movsd  0x8(%rbx),%xmm1
add    $0xffffffffffffffff,%r8
mov    $0x1,%edx
cmp    $0x2,%eax
jne    119c <apply_tri_special+0x7c>
movapd %xmm1,%xmm2
movapd %xmm3,%xmm0
jmp    121b <apply_tri_special+0xfb>
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
neg    %rsi
mov    $0x1,%edi
movsd  0x8(%rsp),%xmm4
movsd  (%rsp),%xmm5
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rbx,%rdi,8),%xmm0
addsd  %xmm0,%xmm3
movapd %xmm1,%xmm2
mulsd  %xmm5,%xmm2
mulsd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,(%r14,%rdi,8)
lea    0x2(%rdi),%rdx
movsd  0x10(%rbx,%rdi,8),%xmm2
addsd  %xmm2,%xmm1
movapd %xmm0,%xmm3
mulsd  %xmm5,%xmm3
mulsd  %xmm4,%xmm1
addsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%r14,%rdi,8)
lea    0x2(%rsi,%rdi,1),%rcx
movapd %xmm2,%xmm1
movapd %xmm0,%xmm3
mov    %rdx,%rdi
cmp    $0x1,%rcx
jne    11c0 <apply_tri_special+0xa0>
test   $0x1,%r8b
je     1240 <apply_tri_special+0x120>
addsd  0x8(%rbx,%rdx,8),%xmm0
mulsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,(%r14,%rdx,8)
movq   $0x0,(%r14)
cltq
movq   $0x0,(%r14,%rax,8)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @apply_tri_special(double* noalias %0, double* noalias %1, double %2, double %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store double %3, double* %9
store i32 %4, i32* %10
%13 = load double*, double** %6
%14 = call i32 @__assume_aligned(double* %13, i32 64)
%15 = load double*, double** %7
%16 = call i32 @__assume_aligned(double* %15, i32 64)
%17 = load double*, double** %7
%18 = load double*, double** %6
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 8
%22 = trunc i64 %21 to i32
%23 = call i32 @memcpy(double* %17, double* %18, i32 %22)
%24 = load i32, i32* %10
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %11
store i32 1, i32* %12
br label %26
26: ; preds = %57, %5
%27 = load i32, i32* %12
%28 = load i32, i32* %11
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %60
30: ; preds = %26
%31 = load double, double* %8
%32 = load double*, double** %7
%33 = load i32, i32* %12
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %7
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = load double, double* %42
%44 = fadd double %37, %43
%45 = load double, double* %9
%46 = load double*, double** %7
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = fmul double %45, %50
%52 = call double @llvm.fmuladd.f64(double %31, double %44, double %51)
%53 = load double*, double** %6
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
br label %57
57: ; preds = %30
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
br label %26
60: ; preds = %26
%61 = load double*, double** %6
%62 = getelementptr inbounds double, double* %61, i64 0
store double 0.000000e+00, double* %62
%63 = load double*, double** %6
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double 0.000000e+00, double* %66
ret void
}

LLVM IR (-O2):
define void @apply_tri_special(double* noalias %0, double* noalias %1, double %2, double %3, i32 %4) {
%6 = tail call i32 @__assume_aligned(double* %0, i32 64)
%7 = tail call i32 @__assume_aligned(double* %1, i32 64)
%8 = shl i32 %4, 3
%9 = tail call i32 @memcpy(double* %1, double* %0, i32 %8)
%10 = add i32 %4, -1
%11 = icmp sgt i32 %4, 2
br i1 %11, label %12, label %35
12: ; preds = %5
%13 = zext i32 %10 to i64
%14 = load double, double* %1
%15 = getelementptr inbounds double, double* %1, i64 1
%16 = load double, double* %15
%17 = add nsw i64 %13, -1
%18 = and i64 %17, 1
%19 = icmp eq i32 %10, 2
br i1 %19, label %22, label %20
20: ; preds = %12
%21 = and i64 %17, -2
br label %38
22: ; preds = %38, %12
%23 = phi double [ %16, %12 ], [ %52, %38 ]
%24 = phi double [ %14, %12 ], [ %45, %38 ]
%25 = phi i64 [ 1, %12 ], [ %50, %38 ]
%26 = icmp eq i64 %18, 0
br i1 %26, label %35, label %27
27: ; preds = %22
%28 = add nuw nsw i64 %25, 1
%29 = getelementptr inbounds double, double* %1, i64 %28
%30 = load double, double* %29
%31 = fadd double %24, %30
%32 = fmul double %23, %3
%33 = tail call double @llvm.fmuladd.f64(double %2, double %31, double %32)
%34 = getelementptr inbounds double, double* %0, i64 %25
store double %33, double* %34
br label %35
35: ; preds = %27, %22, %5
store double 0.000000e+00, double* %0
%36 = sext i32 %10 to i64
%37 = getelementptr inbounds double, double* %0, i64 %36
store double 0.000000e+00, double* %37
ret void
38: ; preds = %38, %20
%39 = phi double [ %16, %20 ], [ %52, %38 ]
%40 = phi double [ %14, %20 ], [ %45, %38 ]
%41 = phi i64 [ 1, %20 ], [ %50, %38 ]
%42 = phi i64 [ 0, %20 ], [ %57, %38 ]
%43 = add nuw nsw i64 %41, 1
%44 = getelementptr inbounds double, double* %1, i64 %43
%45 = load double, double* %44
%46 = fadd double %40, %45
%47 = fmul double %39, %3
%48 = tail call double @llvm.fmuladd.f64(double %2, double %46, double %47)
%49 = getelementptr inbounds double, double* %0, i64 %41
store double %48, double* %49
%50 = add nuw nsw i64 %41, 2
%51 = getelementptr inbounds double, double* %1, i64 %50
%52 = load double, double* %51
%53 = fadd double %39, %52
%54 = fmul double %45, %3
%55 = tail call double @llvm.fmuladd.f64(double %2, double %53, double %54)
%56 = getelementptr inbounds double, double* %0, i64 %43
store double %55, double* %56
%57 = add i64 %42, 2
%58 = icmp eq i64 %57, %21
br i1 %58, label %22, label %38
}