#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 cos(double);
int sin(double);
void geom_CM2_sph_rtp_B(double xm[], double xp[], double xc[], int dir) {
  double r1 = xm[0];
  double r2 = xp[0];
  double th1 = xm[1];
  double th2 = xp[1];
  double ct1 = cos(th1);
  double ct2 = cos(th2);
  double dcost = 2 * sin(0.5 * (th1 + th2)) * sin(0.5 * (th2 - th1));
  double dsint = 2 * cos(0.5 * (th1 + th2)) * sin(0.5 * (th2 - th1));
  xc[0] = 3.0 * (r1 * r1 * r1 + r1 * r1 * r2 + r1 * r2 * r2 + r2 * r2 * r2) /
          (4.0 * (r1 * r1 + r1 * r2 + r2 * r2));
  if (dir == 0)
    xc[1] = (th1 * ct1 - th2 * ct2 + dsint) / dcost;
  else if (dir == 1)
    xc[1] = th1;
}


x86 assembly (clang, -O0):
<geom_CM2_sph_rtp_B>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xe6b(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
shl    $0x1,%eax
mov    %eax,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xe4a(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  0xe1e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
shl    $0x1,%eax
mov    %eax,-0x64(%rbp)
movsd  -0x40(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xdfd(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd7f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  0xd3d(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jne    1328 <geom_CM2_sph_rtp_B+0x208>
movsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x60(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    1345 <geom_CM2_sph_rtp_B+0x225>
cmpl   $0x1,-0x1c(%rbp)
jne    1340 <geom_CM2_sph_rtp_B+0x220>
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    1345 <geom_CM2_sph_rtp_B+0x225>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_CM2_sph_rtp_B>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%ebp
mov    %rdx,%r12
movsd  (%rdi),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rdi),%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsi),%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsi),%xmm0
movsd  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
call   1040 <cos@plt>
mov    %eax,0x14(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0xe77(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
call   1030 <sin@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
mulsd  0xe57(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1030 <sin@plt>
mov    %eax,%r13d
movsd  0x20(%rsp),%xmm0
call   1040 <cos@plt>
mov    %eax,%r14d
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x28(%rsp),%xmm4
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm0,%xmm1
movsd  0x30(%rsp),%xmm3
mulsd  %xmm3,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm4
addsd  %xmm4,%xmm0
mulsd  %xmm3,%xmm4
addsd  %xmm2,%xmm4
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm3
addsd  %xmm4,%xmm3
mulsd  0xde8(%rip),%xmm3
addsd  %xmm0,%xmm1
mulsd  0xde4(%rip),%xmm1
divsd  %xmm1,%xmm3
movsd  %xmm3,(%r12)
cmp    $0x1,%ebp
je     128d <geom_CM2_sph_rtp_B+0x16d>
test   %ebp,%ebp
jne    1299 <geom_CM2_sph_rtp_B+0x179>
imul   %eax,%r14d
add    %r14d,%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
imul   %r13d,%ebx
add    %ebx,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %r15d,%xmm2
xorps  %xmm3,%xmm3
cvtsi2sdl 0x14(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
mulsd  %xmm2,%xmm4
movsd  (%rsp),%xmm2
mulsd  %xmm3,%xmm2
subsd  %xmm4,%xmm2
addsd  %xmm0,%xmm2
divsd  %xmm1,%xmm2
jmp    1292 <geom_CM2_sph_rtp_B+0x172>
movsd  (%rsp),%xmm2
movsd  %xmm2,0x8(%r12)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @geom_CM2_sph_rtp_B(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
store double %19, double* %9
%20 = load double*, double** %6
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
store double %22, double* %10
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
store double %25, double* %11
%26 = load double*, double** %6
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
store double %28, double* %12
%29 = load double, double* %11
%30 = call i32 @cos(double %29)
%31 = sitofp i32 %30 to double
store double %31, double* %13
%32 = load double, double* %12
%33 = call i32 @cos(double %32)
%34 = sitofp i32 %33 to double
store double %34, double* %14
%35 = load double, double* %11
%36 = load double, double* %12
%37 = fadd double %35, %36
%38 = fmul double 5.000000e-01, %37
%39 = call i32 @sin(double %38)
%40 = mul nsw i32 2, %39
%41 = load double, double* %12
%42 = load double, double* %11
%43 = fsub double %41, %42
%44 = fmul double 5.000000e-01, %43
%45 = call i32 @sin(double %44)
%46 = mul nsw i32 %40, %45
%47 = sitofp i32 %46 to double
store double %47, double* %15
%48 = load double, double* %11
%49 = load double, double* %12
%50 = fadd double %48, %49
%51 = fmul double 5.000000e-01, %50
%52 = call i32 @cos(double %51)
%53 = mul nsw i32 2, %52
%54 = load double, double* %12
%55 = load double, double* %11
%56 = fsub double %54, %55
%57 = fmul double 5.000000e-01, %56
%58 = call i32 @sin(double %57)
%59 = mul nsw i32 %53, %58
%60 = sitofp i32 %59 to double
store double %60, double* %16
%61 = load double, double* %9
%62 = load double, double* %9
%63 = fmul double %61, %62
%64 = load double, double* %9
%65 = load double, double* %9
%66 = load double, double* %9
%67 = fmul double %65, %66
%68 = load double, double* %10
%69 = fmul double %67, %68
%70 = call double @llvm.fmuladd.f64(double %63, double %64, double %69)
%71 = load double, double* %9
%72 = load double, double* %10
%73 = fmul double %71, %72
%74 = load double, double* %10
%75 = call double @llvm.fmuladd.f64(double %73, double %74, double %70)
%76 = load double, double* %10
%77 = load double, double* %10
%78 = fmul double %76, %77
%79 = load double, double* %10
%80 = call double @llvm.fmuladd.f64(double %78, double %79, double %75)
%81 = fmul double 3.000000e+00, %80
%82 = load double, double* %9
%83 = load double, double* %9
%84 = load double, double* %9
%85 = load double, double* %10
%86 = fmul double %84, %85
%87 = call double @llvm.fmuladd.f64(double %82, double %83, double %86)
%88 = load double, double* %10
%89 = load double, double* %10
%90 = call double @llvm.fmuladd.f64(double %88, double %89, double %87)
%91 = fmul double 4.000000e+00, %90
%92 = fdiv double %81, %91
%93 = load double*, double** %7
%94 = getelementptr inbounds double, double* %93, i64 0
store double %92, double* %94
%95 = load i32, i32* %8
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %111
97: ; preds = %4
%98 = load double, double* %11
%99 = load double, double* %13
%100 = load double, double* %12
%101 = load double, double* %14
%102 = fmul double %100, %101
%103 = fneg double %102
%104 = call double @llvm.fmuladd.f64(double %98, double %99, double %103)
%105 = load double, double* %16
%106 = fadd double %104, %105
%107 = load double, double* %15
%108 = fdiv double %106, %107
%109 = load double*, double** %7
%110 = getelementptr inbounds double, double* %109, i64 1
store double %108, double* %110
br label %119
111: ; preds = %4
%112 = load i32, i32* %8
%113 = icmp eq i32 %112, 1
br i1 %113, label %114, label %118
114: ; preds = %111
%115 = load double, double* %11
%116 = load double*, double** %7
%117 = getelementptr inbounds double, double* %116, i64 1
store double %115, double* %117
br label %118
118: ; preds = %114, %111
br label %119
119: ; preds = %118, %97
ret void
}

LLVM IR (-O2):
define void @geom_CM2_sph_rtp_B(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2, i32 %3) {
%5 = load double, double* %0
%6 = load double, double* %1
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %1, i64 1
%10 = load double, double* %9
%11 = tail call i32 @cos(double %8)
%12 = tail call i32 @cos(double %10)
%13 = fadd double %8, %10
%14 = fmul double %13, 5.000000e-01
%15 = tail call i32 @sin(double %14)
%16 = fsub double %10, %8
%17 = fmul double %16, 5.000000e-01
%18 = tail call i32 @sin(double %17)
%19 = tail call i32 @cos(double %14)
%20 = tail call i32 @sin(double %17)
%21 = fmul double %5, %5
%22 = fmul double %21, %6
%23 = tail call double @llvm.fmuladd.f64(double %21, double %5, double %22)
%24 = fmul double %5, %6
%25 = tail call double @llvm.fmuladd.f64(double %24, double %6, double %23)
%26 = fmul double %6, %6
%27 = tail call double @llvm.fmuladd.f64(double %26, double %6, double %25)
%28 = fmul double %27, 3.000000e+00
%29 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %24)
%30 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %29)
%31 = fmul double %30, 4.000000e+00
%32 = fdiv double %28, %31
store double %32, double* %2
switch i32 %3, label %50 [
i32 0, label %33
i32 1, label %47
]
33: ; preds = %4
%34 = shl nsw i32 %19, 1
%35 = mul nsw i32 %34, %20
%36 = sitofp i32 %35 to double
%37 = shl nsw i32 %15, 1
%38 = mul nsw i32 %37, %18
%39 = sitofp i32 %38 to double
%40 = sitofp i32 %12 to double
%41 = sitofp i32 %11 to double
%42 = fneg double %10
%43 = fmul double %42, %40
%44 = tail call double @llvm.fmuladd.f64(double %8, double %41, double %43)
%45 = fadd double %44, %36
%46 = fdiv double %45, %39
br label %47
47: ; preds = %4, %33
%48 = phi double [ %46, %33 ], [ %8, %4 ]
%49 = getelementptr inbounds double, double* %2, i64 1
store double %48, double* %49
br label %50
50: ; preds = %47, %4
ret void
}