#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);
double sin(double);
void sph2rec(double lon, double lat, double *v) {
  double theta;
  theta = 1.5707963267948966 - lat;
  v[0] = sin(theta) * cos(lon);
  v[1] = sin(theta) * sin(lon);
  v[2] = cos(theta);
}


x86 assembly (clang, -O0):
<sph2rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xec2(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sph2rec>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x10(%rsp)
movsd  0xeca(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rbx)
movsd  0x18(%rsp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @sph2rec(double %0, double %1, double* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double*
%7 = alloca double
store double %0, double* %4
store double %1, double* %5
store double* %2, double** %6
%8 = load double, double* %5
%9 = fsub double 0x3FF921FB54442D18, %8
store double %9, double* %7
%10 = load double, double* %7
%11 = call double @sin(double %10)
%12 = load double, double* %4
%13 = call double @cos(double %12)
%14 = fmul double %11, %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 0
store double %14, double* %16
%17 = load double, double* %7
%18 = call double @sin(double %17)
%19 = load double, double* %4
%20 = call double @sin(double %19)
%21 = fmul double %18, %20
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 1
store double %21, double* %23
%24 = load double, double* %7
%25 = call double @cos(double %24)
%26 = load double*, double** %6
%27 = getelementptr inbounds double, double* %26, i64 2
store double %25, double* %27
ret void
}

LLVM IR (-O2):
define void @sph2rec(double %0, double %1, double* nocapture writeonly %2) {
%4 = fsub double 0x3FF921FB54442D18, %1
%5 = tail call double @sin(double %4)
%6 = tail call double @cos(double %0)
%7 = fmul double %5, %6
store double %7, double* %2
%8 = tail call double @sin(double %4)
%9 = tail call double @sin(double %0)
%10 = fmul double %8, %9
%11 = getelementptr inbounds double, double* %2, i64 1
store double %10, double* %11
%12 = tail call double @cos(double %4)
%13 = getelementptr inbounds double, double* %2, i64 2
store double %12, double* %13
ret void
}