int tpd2(int inverse, const int i[], const double p[], int Nhat,
         const double rawcrd[], double *discrd) {
  double r, s, u, v;
  if (i[4 + inverse] != 7 || 2 < Nhat) {
    return 1;
  }
  u = rawcrd[0];
  v = rawcrd[1];
  if (i[6]) {
    r = p[0] + p[1] * u + p[2] * v;
    v = p[3] + p[4] * u + p[5] * v;
    u = r;
    p += 6;
  }
  if (inverse)
    p += i[4];
  *discrd = p[0] + u * (p[1] + u * (p[4]));
  if (Nhat == 1)
    return 0;
  *discrd += v * (p[2] + v * (p[6])) + u * (p[5]) * v;
  if (i[7]) {
    s = u * u + v * v;
    r = sqrt(s);
    *discrd += r * p[3];
  }
  return 0;
}


x86 assembly (clang, -O0):
<tpd2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
cmpl   $0x7,(%rax,%rcx,4)
jne    1153 <tpd2+0x43>
mov    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jge    115f <tpd2+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    1338 <tpd2+0x228>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x18(%rax)
je     1211 <tpd2+0x101>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x20(%rax),%xmm1
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x28(%rax),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1234 <tpd2+0x124>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm3
movsd  -0x48(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x20(%rax),%xmm4
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x1,-0x1c(%rbp)
jne    1286 <tpd2+0x176>
movl   $0x0,-0x4(%rbp)
jmp    1338 <tpd2+0x228>
movsd  -0x50(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  -0x50(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x30(%rax),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x48(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mulsd  0x28(%rax),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x1c(%rax)
je     1331 <tpd2+0x221>
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tpd2>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebp
cmp    $0x2,%ecx
jg     1216 <tpd2+0x106>
movslq %edi,%rax
cmpl   $0x7,0x10(%rsi,%rax,4)
jne    1216 <tpd2+0x106>
mov    %r9,%r14
mov    %rdx,%rbx
movupd (%r8),%xmm0
cmpl   $0x0,0x18(%rsi)
je     117e <tpd2+0x6e>
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm2
movhpd 0x20(%rbx),%xmm2
movsd  0x10(%rbx),%xmm3
movapd %xmm0,%xmm4
unpcklpd %xmm0,%xmm4
movhpd 0x18(%rbx),%xmm1
mulpd  %xmm2,%xmm4
addpd  %xmm4,%xmm1
movhpd 0x28(%rbx),%xmm3
unpckhpd %xmm0,%xmm0
mulpd  %xmm3,%xmm0
addpd  %xmm1,%xmm0
add    $0x30,%rbx
test   %edi,%edi
je     118a <tpd2+0x7a>
movslq 0x10(%rsi),%rax
lea    (%rbx,%rax,8),%rbx
movsd  0x20(%rbx),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rbx),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rbx),%xmm1
movsd  %xmm1,(%r14)
xor    %ebp,%ebp
cmp    $0x1,%ecx
je     1216 <tpd2+0x106>
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
movsd  0x30(%rbx),%xmm3
mulsd  %xmm2,%xmm3
addsd  0x10(%rbx),%xmm3
movsd  0x28(%rbx),%xmm4
mulsd  %xmm0,%xmm4
mulsd  %xmm2,%xmm4
mulsd  %xmm2,%xmm3
addsd  %xmm4,%xmm3
addsd  %xmm3,%xmm1
movsd  %xmm1,(%r14)
cmpl   $0x0,0x1c(%rsi)
je     1216 <tpd2+0x106>
mulsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1202 <tpd2+0xf2>
sqrtsd %xmm0,%xmm0
jmp    1207 <tpd2+0xf7>
call   1030 <sqrt@plt>
mulsd  0x18(%rbx),%xmm0
addsd  (%r14),%xmm0
movsd  %xmm0,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @tpd2(i32 %0, i32* nocapture %1, double* nocapture %2, i32 %3, double* nocapture %4, double* nocapture %5) {
%7 = add nsw i32 %0, 4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 7
%12 = icmp sgt i32 %3, 2
%13 = or i1 %12, %11
br i1 %13, label %87, label %14
14: ; preds = %6
%15 = bitcast double* %4 to <2 x double>*
%16 = load <2 x double>, <2 x double>* %15
%17 = getelementptr inbounds i32, i32* %1, i64 6
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %43, label %20
20: ; preds = %14
%21 = load double, double* %2
%22 = getelementptr inbounds double, double* %2, i64 1
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %2, i64 2
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %2, i64 3
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %2, i64 4
%29 = load double, double* %28
%30 = insertelement <2 x double> poison, double %23, i64 0
%31 = insertelement <2 x double> %30, double %29, i64 1
%32 = shufflevector <2 x double> %16, <2 x double> undef, <2 x i32> zeroinitializer
%33 = insertelement <2 x double> poison, double %21, i64 0
%34 = insertelement <2 x double> %33, double %27, i64 1
%35 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %32, <2 x double> %34)
%36 = getelementptr inbounds double, double* %2, i64 5
%37 = load double, double* %36
%38 = insertelement <2 x double> poison, double %25, i64 0
%39 = insertelement <2 x double> %38, double %37, i64 1
%40 = shufflevector <2 x double> %16, <2 x double> undef, <2 x i32> <i32 1, i32 1>
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> %40, <2 x double> %35)
%42 = getelementptr inbounds double, double* %2, i64 6
br label %43
43: ; preds = %20, %14
%44 = phi double* [ %42, %20 ], [ %2, %14 ]
%45 = phi <2 x double> [ %41, %20 ], [ %16, %14 ]
%46 = icmp eq i32 %0, 0
br i1 %46, label %52, label %47
47: ; preds = %43
%48 = getelementptr inbounds i32, i32* %1, i64 4
%49 = load i32, i32* %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %44, i64 %50
br label %52
52: ; preds = %47, %43
%53 = phi double* [ %51, %47 ], [ %44, %43 ]
%54 = load double, double* %53
%55 = getelementptr inbounds double, double* %53, i64 1
%56 = load double, double* %55
%57 = getelementptr inbounds double, double* %53, i64 4
%58 = load double, double* %57
%59 = extractelement <2 x double> %45, i64 0
%60 = tail call double @llvm.fmuladd.f64(double %59, double %58, double %56)
%61 = tail call double @llvm.fmuladd.f64(double %59, double %60, double %54)
store double %61, double* %5
%62 = icmp eq i32 %3, 1
br i1 %62, label %87, label %63
63: ; preds = %52
%64 = getelementptr inbounds double, double* %53, i64 2
%65 = load double, double* %64
%66 = getelementptr inbounds double, double* %53, i64 6
%67 = load double, double* %66
%68 = extractelement <2 x double> %45, i64 1
%69 = tail call double @llvm.fmuladd.f64(double %68, double %67, double %65)
%70 = getelementptr inbounds double, double* %53, i64 5
%71 = load double, double* %70
%72 = fmul double %59, %71
%73 = fmul double %68, %72
%74 = tail call double @llvm.fmuladd.f64(double %68, double %69, double %73)
%75 = fadd double %61, %74
store double %75, double* %5
%76 = getelementptr inbounds i32, i32* %1, i64 7
%77 = load i32, i32* %76
%78 = icmp eq i32 %77, 0
br i1 %78, label %87, label %79
79: ; preds = %63
%80 = fmul double %68, %68
%81 = tail call double @llvm.fmuladd.f64(double %59, double %59, double %80)
%82 = tail call double @sqrt(double %81)
%83 = getelementptr inbounds double, double* %53, i64 3
%84 = load double, double* %83
%85 = load double, double* %5
%86 = tail call double @llvm.fmuladd.f64(double %82, double %84, double %85)
store double %86, double* %5
br label %87
87: ; preds = %63, %79, %52, %6
%88 = phi i32 [ 1, %6 ], [ 0, %52 ], [ 0, %79 ], [ 0, %63 ]
ret i32 %88
}