void tridiag(double a[], double b[], double c[], double r[], unsigned n) {
  int j;
  double factor;
  factor = b[0];
  b[0] = 1.0;
  c[0] = c[0] / factor;
  r[0] = r[0] / factor;
  for (j = 1; j < n; j++) {
    factor = a[j];
    a[j] = a[j] - b[j - 1] * factor;
    b[j] = b[j] - c[j - 1] * factor;
    r[j] = r[j] - r[j - 1] * factor;
    factor = b[j];
    b[j] = 1.0;
    c[j] = c[j] / factor;
    r[j] = r[j] / factor;
  }
  for (j = n - 2; j >= 0; j--) {
    factor = c[j];
    c[j] = c[j] - b[j + 1] * factor;
    r[j] = r[j] - r[j + 1] * factor;
    factor = b[j];
    r[j] = r[j] / factor;
  }
}


x86 assembly (clang, -O0):
<tridiag>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0xecf(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    12e7 <tridiag+0x1e7>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  0xd6a(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1166 <tridiag+0x66>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     13eb <tridiag+0x2eb>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    12f0 <tridiag+0x1f0>
pop    %rbp
ret

x86 assembly (clang, -O2):
<tridiag>:
movsd  (%rsi),%xmm0
movabs $0x3ff0000000000000,%r9
mov    %r9,(%rsi)
movsd  (%rdx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx)
movsd  (%rcx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rcx)
cmp    $0x2,%r8d
jb     1200 <tridiag+0x100>
mov    %r8d,%r10d
mov    $0x1,%eax
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rax,8),%xmm0
movsd  -0x8(%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,(%rdi,%rax,8)
movsd  (%rsi,%rax,8),%xmm1
movsd  -0x8(%rdx,%rax,8),%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,(%rsi,%rax,8)
movsd  (%rcx,%rax,8),%xmm1
mulsd  -0x8(%rcx,%rax,8),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rcx,%rax,8)
movsd  (%rsi,%rax,8),%xmm0
mov    %r9,(%rsi,%rax,8)
movsd  (%rdx,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rdx,%rax,8)
movsd  (%rcx,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rcx,%rax,8)
add    $0x1,%rax
cmp    %rax,%r10
jne    1140 <tridiag+0x40>
add    $0xfffffffe,%r8d
js     1200 <tridiag+0x100>
mov    %r8d,%eax
nop
movsd  (%rdx,%rax,8),%xmm0
movsd  0x8(%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,(%rdx,%rax,8)
movsd  (%rcx,%rax,8),%xmm1
mulsd  0x8(%rcx,%rax,8),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rcx,%rax,8)
divsd  (%rsi,%rax,8),%xmm1
movsd  %xmm1,(%rcx,%rax,8)
add    $0xffffffffffffffff,%rax
jb     11c0 <tridiag+0xc0>
ret

LLVM IR (-O0):
define void @tridiag(double* %0, double* %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 double
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** %7
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
store double %15, double* %12
%16 = load double*, double** %7
%17 = getelementptr inbounds double, double* %16, i64 0
store double 1.000000e+00, double* %17
%18 = load double*, double** %8
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = load double, double* %12
%22 = fdiv double %20, %21
%23 = load double*, double** %8
%24 = getelementptr inbounds double, double* %23, i64 0
store double %22, double* %24
%25 = load double*, double** %9
%26 = getelementptr inbounds double, double* %25, i64 0
%27 = load double, double* %26
%28 = load double, double* %12
%29 = fdiv double %27, %28
%30 = load double*, double** %9
%31 = getelementptr inbounds double, double* %30, i64 0
store double %29, double* %31
store i32 1, i32* %11
br label %32
32: ; preds = %127, %5
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = icmp ult i32 %33, %34
br i1 %35, label %36, label %130
36: ; preds = %32
%37 = load double*, double** %6
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
store double %41, double* %12
%42 = load double*, double** %6
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %7
%48 = load i32, i32* %11
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %47, i64 %50
%52 = load double, double* %51
%53 = load double, double* %12
%54 = fneg double %52
%55 = call double @llvm.fmuladd.f64(double %54, double %53, double %46)
%56 = load double*, double** %6
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
store double %55, double* %59
%60 = load double*, double** %7
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = load double*, double** %8
%66 = load i32, i32* %11
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %65, i64 %68
%70 = load double, double* %69
%71 = load double, double* %12
%72 = fneg double %70
%73 = call double @llvm.fmuladd.f64(double %72, double %71, double %64)
%74 = load double*, double** %7
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
store double %73, double* %77
%78 = load double*, double** %9
%79 = load i32, i32* %11
%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* %11
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %83, i64 %86
%88 = load double, double* %87
%89 = load double, double* %12
%90 = fneg double %88
%91 = call double @llvm.fmuladd.f64(double %90, double %89, double %82)
%92 = load double*, double** %9
%93 = load i32, i32* %11
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double, double* %92, i64 %94
store double %91, double* %95
%96 = load double*, double** %7
%97 = load i32, i32* %11
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
store double %100, double* %12
%101 = load double*, double** %7
%102 = load i32, i32* %11
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %101, i64 %103
store double 1.000000e+00, double* %104
%105 = load double*, double** %8
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %105, i64 %107
%109 = load double, double* %108
%110 = load double, double* %12
%111 = fdiv double %109, %110
%112 = load double*, double** %8
%113 = load i32, i32* %11
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %112, i64 %114
store double %111, double* %115
%116 = load double*, double** %9
%117 = load i32, i32* %11
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %116, i64 %118
%120 = load double, double* %119
%121 = load double, double* %12
%122 = fdiv double %120, %121
%123 = load double*, double** %9
%124 = load i32, i32* %11
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds double, double* %123, i64 %125
store double %122, double* %126
br label %127
127: ; preds = %36
%128 = load i32, i32* %11
%129 = add nsw i32 %128, 1
store i32 %129, i32* %11
br label %32
130: ; preds = %32
%131 = load i32, i32* %10
%132 = sub i32 %131, 2
store i32 %132, i32* %11
br label %133
133: ; preds = %194, %130
%134 = load i32, i32* %11
%135 = icmp sge i32 %134, 0
br i1 %135, label %136, label %197
136: ; preds = %133
%137 = load double*, double** %8
%138 = load i32, i32* %11
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds double, double* %137, i64 %139
%141 = load double, double* %140
store double %141, double* %12
%142 = load double*, double** %8
%143 = load i32, i32* %11
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds double, double* %142, i64 %144
%146 = load double, double* %145
%147 = load double*, double** %7
%148 = load i32, i32* %11
%149 = add nsw i32 %148, 1
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds double, double* %147, i64 %150
%152 = load double, double* %151
%153 = load double, double* %12
%154 = fneg double %152
%155 = call double @llvm.fmuladd.f64(double %154, double %153, double %146)
%156 = load double*, double** %8
%157 = load i32, i32* %11
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds double, double* %156, i64 %158
store double %155, double* %159
%160 = load double*, double** %9
%161 = load i32, i32* %11
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds double, double* %160, i64 %162
%164 = load double, double* %163
%165 = load double*, double** %9
%166 = load i32, i32* %11
%167 = add nsw i32 %166, 1
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds double, double* %165, i64 %168
%170 = load double, double* %169
%171 = load double, double* %12
%172 = fneg double %170
%173 = call double @llvm.fmuladd.f64(double %172, double %171, double %164)
%174 = load double*, double** %9
%175 = load i32, i32* %11
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds double, double* %174, i64 %176
store double %173, double* %177
%178 = load double*, double** %7
%179 = load i32, i32* %11
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds double, double* %178, i64 %180
%182 = load double, double* %181
store double %182, double* %12
%183 = load double*, double** %9
%184 = load i32, i32* %11
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds double, double* %183, i64 %185
%187 = load double, double* %186
%188 = load double, double* %12
%189 = fdiv double %187, %188
%190 = load double*, double** %9
%191 = load i32, i32* %11
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds double, double* %190, i64 %192
store double %189, double* %193
br label %194
194: ; preds = %136
%195 = load i32, i32* %11
%196 = add nsw i32 %195, -1
store i32 %196, i32* %11
br label %133
197: ; preds = %133
ret void
}

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