void calc_polar_base_at_theta_phi(theta, phi, polar_base) double theta;
double phi;
double *polar_base;
{
  double cp, sp, ct, st;
  ct = cos((double)theta);
  cp = cos((double)phi);
  st = sin((double)theta);
  sp = sin((double)phi);
  polar_base[0] = st * cp;
  polar_base[1] = st * sp;
  polar_base[2] = ct;
  polar_base[3] = ct * cp;
  polar_base[4] = ct * sp;
  polar_base[5] = -st;
  polar_base[6] = -sp;
  polar_base[7] = cp;
  polar_base[8] = 0.0;
}


x86 assembly (clang, -O0):
<calc_polar_base_at_theta_phi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x20(%rax)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x28(%rax)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x30(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x38(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x40(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_polar_base_at_theta_phi>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <cos@plt>
movaps %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movapd 0x10(%rsp),%xmm4
movapd %xmm4,%xmm1
unpcklpd %xmm4,%xmm1
movapd 0x20(%rsp),%xmm3
movapd %xmm3,%xmm2
unpcklpd %xmm0,%xmm2
mulpd  %xmm2,%xmm1
movupd %xmm1,(%rbx)
movapd 0x30(%rsp),%xmm1
movsd  %xmm1,0x10(%rbx)
unpcklpd %xmm1,%xmm1
mulpd  %xmm2,%xmm1
movapd %xmm4,%xmm2
unpcklpd %xmm0,%xmm2
xorpd  0xe50(%rip),%xmm2
movupd %xmm1,0x18(%rbx)
movupd %xmm2,0x28(%rbx)
movsd  %xmm3,0x38(%rbx)
movq   $0x0,0x40(%rbx)
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @calc_polar_base_at_theta_phi(double %0, double %1, double* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store double* %2, double** %6
%11 = load double, double* %4
%12 = call double @cos(double %11)
store double %12, double* %9
%13 = load double, double* %5
%14 = call double @cos(double %13)
store double %14, double* %7
%15 = load double, double* %4
%16 = call double @sin(double %15)
store double %16, double* %10
%17 = load double, double* %5
%18 = call double @sin(double %17)
store double %18, double* %8
%19 = load double, double* %10
%20 = load double, double* %7
%21 = fmul double %19, %20
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 0
store double %21, double* %23
%24 = load double, double* %10
%25 = load double, double* %8
%26 = fmul double %24, %25
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 1
store double %26, double* %28
%29 = load double, double* %9
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 2
store double %29, double* %31
%32 = load double, double* %9
%33 = load double, double* %7
%34 = fmul double %32, %33
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i64 3
store double %34, double* %36
%37 = load double, double* %9
%38 = load double, double* %8
%39 = fmul double %37, %38
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i64 4
store double %39, double* %41
%42 = load double, double* %10
%43 = fneg double %42
%44 = load double*, double** %6
%45 = getelementptr inbounds double, double* %44, i64 5
store double %43, double* %45
%46 = load double, double* %8
%47 = fneg double %46
%48 = load double*, double** %6
%49 = getelementptr inbounds double, double* %48, i64 6
store double %47, double* %49
%50 = load double, double* %7
%51 = load double*, double** %6
%52 = getelementptr inbounds double, double* %51, i64 7
store double %50, double* %52
%53 = load double*, double** %6
%54 = getelementptr inbounds double, double* %53, i64 8
store double 0.000000e+00, double* %54
ret void
}

LLVM IR (-O2):
define void @calc_polar_base_at_theta_phi(double %0, double %1, double* nocapture writeonly %2) {
%4 = tail call double @cos(double %0)
%5 = tail call double @cos(double %1)
%6 = tail call double @sin(double %0)
%7 = tail call double @sin(double %1)
%8 = insertelement <2 x double> poison, double %6, i64 0
%9 = shufflevector <2 x double> %8, <2 x double> poison, <2 x i32> zeroinitializer
%10 = insertelement <2 x double> poison, double %5, i64 0
%11 = insertelement <2 x double> %10, double %7, i64 1
%12 = fmul <2 x double> %9, %11
%13 = bitcast double* %2 to <2 x double>*
store <2 x double> %12, <2 x double>* %13
%14 = getelementptr inbounds double, double* %2, i64 2
store double %4, double* %14
%15 = getelementptr inbounds double, double* %2, i64 3
%16 = insertelement <2 x double> poison, double %4, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = fmul <2 x double> %17, %11
%19 = bitcast double* %15 to <2 x double>*
store <2 x double> %18, <2 x double>* %19
%20 = getelementptr inbounds double, double* %2, i64 5
%21 = insertelement <2 x double> %8, double %7, i64 1
%22 = fneg <2 x double> %21
%23 = bitcast double* %20 to <2 x double>*
store <2 x double> %22, <2 x double>* %23
%24 = getelementptr inbounds double, double* %2, i64 7
store double %5, double* %24
%25 = getelementptr inbounds double, double* %2, i64 8
store double 0.000000e+00, double* %25
ret void
}