#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 cos(double);
int /*<<< orphan*/ r3add(double *, double *);
int /*<<< orphan*/ r3adds(double *, double *, double);
int /*<<< orphan*/ r3cp(double *, double *);
int /*<<< orphan*/ r3diff(double *, double *, double *);
double r3dot(double *, double *);
int /*<<< orphan*/ r3min(double *, double *);
int /*<<< orphan*/ r3mx(double *, double *, double *);
int /*<<< orphan*/ r3scal(double *, double);
int /*<<< orphan*/ r3x(double *, double *, double *);
int /*<<< orphan*/ rotmx(double *, double *, double);
double sqrt(double);
int zmat2cart(int n, double *mr, double r[3], int a1, int a2, int a3, double R,
              double phi, double theta) {
  if (n == 0) {
    r[0] = r[1] = r[2] = 0.0;
  } else if (n == 1) {
    r[0] = mr[a1 * 3];
    r[1] = mr[a1 * 3 + 1];
    r[2] = mr[a1 * 3 + 2] + R;
  } else if (n == 2) {
    r[0] = mr[a1 * 3] + R * sqrt(1 - cos(phi) * cos(phi));
    r[1] = mr[a1 * 3 + 1];
    r[2] = mr[a1 * 3 + 2] +
           ((mr[a2 * 3 + 2] < mr[a1 * 3 + 2]) ? -1.0 : +1.0) * R * cos(phi);
  } else {
    double ab[3], bc[3];
    double r1[3], r2[3];
    double perp[3];
    double rot[9];
    double t;
    double *a = mr + 3 * a1;
    double *b = mr + 3 * a2;
    double *c = mr + 3 * a3;
    r3diff(ab, b, a);
    t = r3dot(ab, ab);
    if (t < 1e-15) {
      return 1;
    }
    r3scal(ab, 1.0 / sqrt(t));
    r3cp(r1, a);
    r3adds(r1, ab, R);
    r3diff(bc, b, c);
    r3x(perp, ab, bc);
    t = r3dot(perp, perp);
    if (t < 1e-15) {
      return 1;
    }
    r3scal(perp, 1.0 / sqrt(t));
    r3min(r1, a);
    rotmx(rot, perp, -phi);
    r3mx(r2, r1, rot);
    rotmx(rot, ab, theta);
    r3mx(r, r2, rot);
    r3add(r, a);
  }
  return 0;
}


x86 assembly (clang, -O0):
<zmat2cart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  %xmm2,-0x40(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1222 <zmat2cart+0x62>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    1620 <zmat2cart+0x460>
cmpl   $0x1,-0x8(%rbp)
jne    1286 <zmat2cart+0xc6>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    161b <zmat2cart+0x45b>
cmpl   $0x2,-0x8(%rbp)
jne    13ec <zmat2cart+0x22c>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x170(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x168(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   10b0 <cos@plt>
movsd  %xmm0,-0x178(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   10b0 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x178(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd09(%rip),%xmm1
addsd  %xmm1,%xmm0
call   10d0 <sqrt@plt>
movsd  -0x170(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x168(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x160(%rbp)
ff
mov    -0x10(%rbp),%rax
imul   $0x3,-0x20(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xc80(%rip),%xmm3
movsd  0xc70(%rip),%xmm2
cmpltsd %xmm1,%xmm0
movaps %xmm0,%xmm1
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x158(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   10b0 <cos@plt>
movsd  -0x160(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x158(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    1616 <zmat2cart+0x456>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x20(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x148(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x24(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x150(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    -0x140(%rbp),%rdx
call   10c0 <r3diff@plt>
lea    -0x60(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <r3dot@plt>
movsd  %xmm0,-0x138(%rbp)
ff
movsd  0xb95(%rip),%xmm0
ucomisd -0x138(%rbp),%xmm0
ff
jbe    1485 <zmat2cart+0x2c5>
movl   $0x1,-0x4(%rbp)
jmp    1627 <zmat2cart+0x467>
lea    -0x60(%rbp),%rax
mov    %rax,-0x180(%rbp)
movsd  -0x138(%rbp),%xmm0
ff
call   10d0 <sqrt@plt>
mov    -0x180(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  0xb59(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1070 <r3scal@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   10a0 <r3cp@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
movsd  -0x30(%rbp),%xmm0
call   1040 <r3adds@plt>
lea    -0x80(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    -0x150(%rbp),%rdx
call   10c0 <r3diff@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1060 <r3x@plt>
lea    -0xe0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <r3dot@plt>
movsd  %xmm0,-0x138(%rbp)
ff
movsd  0xad2(%rip),%xmm0
ucomisd -0x138(%rbp),%xmm0
ff
jbe    1548 <zmat2cart+0x388>
movl   $0x1,-0x4(%rbp)
jmp    1627 <zmat2cart+0x467>
lea    -0xe0(%rbp),%rax
mov    %rax,-0x188(%rbp)
movsd  -0x138(%rbp),%xmm0
ff
call   10d0 <sqrt@plt>
mov    -0x188(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  0xa93(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1070 <r3scal@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1090 <r3min@plt>
lea    -0x130(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <rotmx@plt>
lea    -0xc0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
lea    -0x130(%rbp),%rdx
call   10e0 <r3mx@plt>
lea    -0x130(%rbp),%rdi
lea    -0x60(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
call   1050 <rotmx@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
lea    -0x130(%rbp),%rdx
call   10e0 <r3mx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1080 <r3add@plt>
jmp    161b <zmat2cart+0x45b>
jmp    1620 <zmat2cart+0x460>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zmat2cart>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r8d,%r12d
mov    %rdx,%r15
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1202 <zmat2cart+0x42>
cmp    $0x1,%edi
je     1263 <zmat2cart+0xa3>
test   %edi,%edi
jne    128f <zmat2cart+0xcf>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r15)
movq   $0x0,0x10(%r15)
jmp    14c3 <zmat2cart+0x303>
movaps %xmm0,0x10(%rsp)
lea    (%rcx,%rcx,2),%eax
movslq %eax,%rbp
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
movaps %xmm1,0x20(%rsp)
call   10b0 <cos@plt>
movsd  %xmm0,0x38(%rsp)
movapd 0x20(%rsp),%xmm0
call   10b0 <cos@plt>
movapd %xmm0,%xmm1
mulsd  0x38(%rsp),%xmm1
movsd  0xdb8(%rip),%xmm0
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1308 <zmat2cart+0x148>
sqrtsd %xmm0,%xmm0
jmp    130d <zmat2cart+0x14d>
lea    (%rcx,%rcx,2),%eax
cltq
movsd  (%rbx,%rax,8),%xmm1
movsd  %xmm1,(%r15)
movsd  0x8(%rbx,%rax,8),%xmm1
movsd  %xmm1,0x8(%r15)
addsd  0x10(%rbx,%rax,8),%xmm0
movsd  %xmm0,0x10(%r15)
jmp    14c3 <zmat2cart+0x303>
mov    %r9d,%r13d
movapd %xmm0,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movaps %xmm1,0x20(%rsp)
lea    (%rcx,%rcx,2),%eax
cltq
lea    (%rbx,%rax,8),%r14
lea    (%r12,%r12,2),%eax
cltq
lea    (%rbx,%rax,8),%r12
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10c0 <r3diff@plt>
mov    %rbp,%rdi
mov    %rbp,%rsi
call   1030 <r3dot@plt>
movsd  0xd2c(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1413 <zmat2cart+0x253>
lea    0x0(%r13,%r13,2),%eax
cltq
lea    (%rbx,%rax,8),%rbp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     138b <zmat2cart+0x1cb>
sqrtsd %xmm0,%xmm0
jmp    1390 <zmat2cart+0x1d0>
call   10d0 <sqrt@plt>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15)
movsd  0x8(%rbx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%r15)
movsd  0x10(%rbx,%rbp,8),%xmm2
movsd  %xmm2,0x8(%rsp)
lea    (%r12,%r12,2),%eax
cltq
movsd  0x10(%rbx,%rax,8),%xmm3
movapd 0xcc2(%rip),%xmm0
xorpd  %xmm1,%xmm0
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm1,%xmm3
orpd   %xmm0,%xmm3
movapd %xmm3,0x10(%rsp)
movapd 0x20(%rsp),%xmm0
call   10b0 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%r15)
jmp    14c3 <zmat2cart+0x303>
call   10d0 <sqrt@plt>
movsd  0xc68(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0x40(%rsp),%r13
mov    %r13,%rdi
movapd %xmm1,%xmm0
call   1070 <r3scal@plt>
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <r3cp@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
movapd 0x10(%rsp),%xmm0
call   1040 <r3adds@plt>
lea    0xc0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10c0 <r3diff@plt>
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <r3x@plt>
mov    %rbp,%rdi
mov    %rbp,%rsi
call   1030 <r3dot@plt>
movsd  0xbfb(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    141d <zmat2cart+0x25d>
mov    $0x1,%eax
jmp    14c5 <zmat2cart+0x305>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     142d <zmat2cart+0x26d>
sqrtsd %xmm0,%xmm0
jmp    1432 <zmat2cart+0x272>
call   10d0 <sqrt@plt>
movsd  0xbc6(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
movapd %xmm1,%xmm0
call   1070 <r3scal@plt>
lea    0x80(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <r3min@plt>
movaps 0x20(%rsp),%xmm0
xorps  0xba2(%rip),%xmm0
lea    0xe0(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <rotmx@plt>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10e0 <r3mx@plt>
lea    0x40(%rsp),%rsi
mov    %rbp,%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <rotmx@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10e0 <r3mx@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <r3add@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @zmat2cart(i32 %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, double %6, double %7, double %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca [3 x double]
%21 = alloca [3 x double]
%22 = alloca [3 x double]
%23 = alloca [3 x double]
%24 = alloca [3 x double]
%25 = alloca [9 x double]
%26 = alloca double
%27 = alloca double*
%28 = alloca double*
%29 = alloca double*
store i32 %0, i32* %11
store double* %1, double** %12
store double* %2, double** %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store double %6, double* %17
store double %7, double* %18
store double %8, double* %19
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %9
%33 = load double*, double** %13
%34 = getelementptr inbounds double, double* %33, i64 2
store double 0.000000e+00, double* %34
%35 = load double*, double** %13
%36 = getelementptr inbounds double, double* %35, i64 1
store double 0.000000e+00, double* %36
%37 = load double*, double** %13
%38 = getelementptr inbounds double, double* %37, i64 0
store double 0.000000e+00, double* %38
br label %216
39: ; preds = %9
%40 = load i32, i32* %11
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %71
42: ; preds = %39
%43 = load double*, double** %12
%44 = load i32, i32* %14
%45 = mul nsw i32 %44, 3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %13
%50 = getelementptr inbounds double, double* %49, i64 0
store double %48, double* %50
%51 = load double*, double** %12
%52 = load i32, i32* %14
%53 = mul nsw i32 %52, 3
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %51, i64 %55
%57 = load double, double* %56
%58 = load double*, double** %13
%59 = getelementptr inbounds double, double* %58, i64 1
store double %57, double* %59
%60 = load double*, double** %12
%61 = load i32, i32* %14
%62 = mul nsw i32 %61, 3
%63 = add nsw i32 %62, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %60, i64 %64
%66 = load double, double* %65
%67 = load double, double* %17
%68 = fadd double %66, %67
%69 = load double*, double** %13
%70 = getelementptr inbounds double, double* %69, i64 2
store double %68, double* %70
br label %215
71: ; preds = %39
%72 = load i32, i32* %11
%73 = icmp eq i32 %72, 2
br i1 %73, label %74, label %132
74: ; preds = %71
%75 = load double*, double** %12
%76 = load i32, i32* %14
%77 = mul nsw i32 %76, 3
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %75, i64 %78
%80 = load double, double* %79
%81 = load double, double* %17
%82 = load double, double* %18
%83 = call double @cos(double %82)
%84 = load double, double* %18
%85 = call double @cos(double %84)
%86 = fneg double %83
%87 = call double @llvm.fmuladd.f64(double %86, double %85, double 1.000000e+00)
%88 = call double @sqrt(double %87)
%89 = call double @llvm.fmuladd.f64(double %81, double %88, double %80)
%90 = load double*, double** %13
%91 = getelementptr inbounds double, double* %90, i64 0
store double %89, double* %91
%92 = load double*, double** %12
%93 = load i32, i32* %14
%94 = mul nsw i32 %93, 3
%95 = add nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double, double* %92, i64 %96
%98 = load double, double* %97
%99 = load double*, double** %13
%100 = getelementptr inbounds double, double* %99, i64 1
store double %98, double* %100
%101 = load double*, double** %12
%102 = load i32, i32* %14
%103 = mul nsw i32 %102, 3
%104 = add nsw i32 %103, 2
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double, double* %101, i64 %105
%107 = load double, double* %106
%108 = load double*, double** %12
%109 = load i32, i32* %15
%110 = mul nsw i32 %109, 3
%111 = add nsw i32 %110, 2
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds double, double* %108, i64 %112
%114 = load double, double* %113
%115 = load double*, double** %12
%116 = load i32, i32* %14
%117 = mul nsw i32 %116, 3
%118 = add nsw i32 %117, 2
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %115, i64 %119
%121 = load double, double* %120
%122 = fcmp olt double %114, %121
%123 = zext i1 %122 to i64
%124 = select i1 %122, double -1.000000e+00, double 1.000000e+00
%125 = load double, double* %17
%126 = fmul double %124, %125
%127 = load double, double* %18
%128 = call double @cos(double %127)
%129 = call double @llvm.fmuladd.f64(double %126, double %128, double %107)
%130 = load double*, double** %13
%131 = getelementptr inbounds double, double* %130, i64 2
store double %129, double* %131
br label %214
132: ; preds = %71
%133 = load double*, double** %12
%134 = load i32, i32* %14
%135 = mul nsw i32 3, %134
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds double, double* %133, i64 %136
store double* %137, double** %27
%138 = load double*, double** %12
%139 = load i32, i32* %15
%140 = mul nsw i32 3, %139
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %138, i64 %141
store double* %142, double** %28
%143 = load double*, double** %12
%144 = load i32, i32* %16
%145 = mul nsw i32 3, %144
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds double, double* %143, i64 %146
store double* %147, double** %29
%148 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%149 = load double*, double** %28
%150 = load double*, double** %27
%151 = call i32 @r3diff(double* %148, double* %149, double* %150)
%152 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%153 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%154 = call double @r3dot(double* %152, double* %153)
store double %154, double* %26
%155 = load double, double* %26
%156 = fcmp olt double %155, 1.000000e-15
br i1 %156, label %157, label %158
157: ; preds = %132
store i32 1, i32* %10
br label %217
158: ; preds = %132
%159 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%160 = load double, double* %26
%161 = call double @sqrt(double %160)
%162 = fdiv double 1.000000e+00, %161
%163 = call i32 @r3scal(double* %159, double %162)
%164 = getelementptr inbounds [3 x double], [3 x double]* %22, i64 0, i64 0
%165 = load double*, double** %27
%166 = call i32 @r3cp(double* %164, double* %165)
%167 = getelementptr inbounds [3 x double], [3 x double]* %22, i64 0, i64 0
%168 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%169 = load double, double* %17
%170 = call i32 @r3adds(double* %167, double* %168, double %169)
%171 = getelementptr inbounds [3 x double], [3 x double]* %21, i64 0, i64 0
%172 = load double*, double** %28
%173 = load double*, double** %29
%174 = call i32 @r3diff(double* %171, double* %172, double* %173)
%175 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 0
%176 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%177 = getelementptr inbounds [3 x double], [3 x double]* %21, i64 0, i64 0
%178 = call i32 @r3x(double* %175, double* %176, double* %177)
%179 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 0
%180 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 0
%181 = call double @r3dot(double* %179, double* %180)
store double %181, double* %26
%182 = load double, double* %26
%183 = fcmp olt double %182, 1.000000e-15
br i1 %183, label %184, label %185
184: ; preds = %158
store i32 1, i32* %10
br label %217
185: ; preds = %158
%186 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 0
%187 = load double, double* %26
%188 = call double @sqrt(double %187)
%189 = fdiv double 1.000000e+00, %188
%190 = call i32 @r3scal(double* %186, double %189)
%191 = getelementptr inbounds [3 x double], [3 x double]* %22, i64 0, i64 0
%192 = load double*, double** %27
%193 = call i32 @r3min(double* %191, double* %192)
%194 = getelementptr inbounds [9 x double], [9 x double]* %25, i64 0, i64 0
%195 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 0, i64 0
%196 = load double, double* %18
%197 = fneg double %196
%198 = call i32 @rotmx(double* %194, double* %195, double %197)
%199 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 0
%200 = getelementptr inbounds [3 x double], [3 x double]* %22, i64 0, i64 0
%201 = getelementptr inbounds [9 x double], [9 x double]* %25, i64 0, i64 0
%202 = call i32 @r3mx(double* %199, double* %200, double* %201)
%203 = getelementptr inbounds [9 x double], [9 x double]* %25, i64 0, i64 0
%204 = getelementptr inbounds [3 x double], [3 x double]* %20, i64 0, i64 0
%205 = load double, double* %19
%206 = call i32 @rotmx(double* %203, double* %204, double %205)
%207 = load double*, double** %13
%208 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 0
%209 = getelementptr inbounds [9 x double], [9 x double]* %25, i64 0, i64 0
%210 = call i32 @r3mx(double* %207, double* %208, double* %209)
%211 = load double*, double** %13
%212 = load double*, double** %27
%213 = call i32 @r3add(double* %211, double* %212)
br label %214
214: ; preds = %185, %74
br label %215
215: ; preds = %214, %42
br label %216
216: ; preds = %215, %32
store i32 0, i32* %10
br label %217
217: ; preds = %216, %184, %157
%218 = load i32, i32* %10
ret i32 %218
}

LLVM IR (-O2):
define i32 @zmat2cart(i32 %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, double %6, double %7, double %8) {
%10 = alloca [3 x double]
%11 = alloca [3 x double]
%12 = alloca [3 x double]
%13 = alloca [3 x double]
%14 = alloca [3 x double]
%15 = alloca [9 x double]
switch i32 %0, label %65 [
i32 0, label %16
i32 1, label %18
i32 2, label %34
]
16: ; preds = %9
%17 = bitcast double* %2 to i8*
br label %112
18: ; preds = %9
%19 = mul nsw i32 %3, 3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
store double %22, double* %2
%23 = add nsw i32 %19, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %2, i64 1
store double %26, double* %27
%28 = add nsw i32 %19, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %1, i64 %29
%31 = load double, double* %30
%32 = fadd double %31, %6
%33 = getelementptr inbounds double, double* %2, i64 2
store double %32, double* %33
br label %112
34: ; preds = %9
%35 = mul nsw i32 %3, 3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %1, i64 %36
%38 = load double, double* %37
%39 = tail call double @cos(double %7)
%40 = tail call double @cos(double %7)
%41 = fneg double %39
%42 = tail call double @llvm.fmuladd.f64(double %41, double %40, double 1.000000e+00)
%43 = tail call double @sqrt(double %42)
%44 = tail call double @llvm.fmuladd.f64(double %6, double %43, double %38)
store double %44, double* %2
%45 = add nsw i32 %35, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %1, i64 %46
%48 = load double, double* %47
%49 = getelementptr inbounds double, double* %2, i64 1
store double %48, double* %49
%50 = add nsw i32 %35, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %1, i64 %51
%53 = load double, double* %52
%54 = mul nsw i32 %4, 3
%55 = add nsw i32 %54, 2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %1, i64 %56
%58 = load double, double* %57
%59 = fcmp olt double %58, %53
%60 = fneg double %6
%61 = select i1 %59, double %60, double %6
%62 = tail call double @cos(double %7)
%63 = tail call double @llvm.fmuladd.f64(double %61, double %62, double %53)
%64 = getelementptr inbounds double, double* %2, i64 2
store double %63, double* %64
br label %112
65: ; preds = %9
%66 = bitcast [3 x double]* %10 to i8*
%67 = bitcast [3 x double]* %11 to i8*
%68 = bitcast [3 x double]* %12 to i8*
%69 = bitcast [3 x double]* %13 to i8*
%70 = bitcast [3 x double]* %14 to i8*
%71 = bitcast [9 x double]* %15 to i8*
%72 = mul nsw i32 %3, 3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %1, i64 %73
%75 = mul nsw i32 %4, 3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %1, i64 %76
%78 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%79 = call i32 @r3diff(double* %78, double* %77, double* %74)
%80 = call double @r3dot(double* %78, double* %78)
%81 = fcmp olt double %80, 1.000000e-15
br i1 %81, label %98, label %82
82: ; preds = %65
%83 = mul nsw i32 %5, 3
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %1, i64 %84
%86 = call double @sqrt(double %80)
%87 = fdiv double 1.000000e+00, %86
%88 = call i32 @r3scal(double* %78, double %87)
%89 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%90 = call i32 @r3cp(double* %89, double* %74)
%91 = call i32 @r3adds(double* %89, double* %78, double %6)
%92 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%93 = call i32 @r3diff(double* %92, double* %77, double* %85)
%94 = getelementptr inbounds [3 x double], [3 x double]* %14, i64 0, i64 0
%95 = call i32 @r3x(double* %94, double* %78, double* %92)
%96 = call double @r3dot(double* %94, double* %94)
%97 = fcmp olt double %96, 1.000000e-15
br i1 %97, label %98, label %99
98: ; preds = %65, %82
br label %112
99: ; preds = %82
%100 = call double @sqrt(double %96)
%101 = fdiv double 1.000000e+00, %100
%102 = call i32 @r3scal(double* %94, double %101)
%103 = call i32 @r3min(double* %89, double* %74)
%104 = getelementptr inbounds [9 x double], [9 x double]* %15, i64 0, i64 0
%105 = fneg double %7
%106 = call i32 @rotmx(double* %104, double* %94, double %105)
%107 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%108 = call i32 @r3mx(double* %107, double* %89, double* %104)
%109 = call i32 @rotmx(double* %104, double* %78, double %8)
%110 = call i32 @r3mx(double* %2, double* %107, double* %104)
%111 = call i32 @r3add(double* %2, double* %74)
br label %112
112: ; preds = %16, %34, %18, %99, %98
%113 = phi i32 [ 1, %98 ], [ 0, %99 ], [ 0, %18 ], [ 0, %34 ], [ 0, %16 ]
ret i32 %113
}