#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 const cos(double const);
double const sin(double const);
void sphe_to_rect(const double lng, const double lat, const double r, double *x,
                  double *y, double *z) {
  const double cosLat = cos(lat);
  (*x) = r * cos(lng) * cosLat;
  (*y) = r * sin(lng) * cosLat;
  (*z) = r * sin(lat);
}


x86 assembly (clang, -O0):
<sphe_to_rect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sphe_to_rect>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  %xmm2,(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r15)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sphe_to_rect(double %0, double %1, double %2, double* %3, double* %4, double* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%14 = load double, double* %8
%15 = call double @cos(double %14)
store double %15, double* %13
%16 = load double, double* %9
%17 = load double, double* %7
%18 = call double @cos(double %17)
%19 = fmul double %16, %18
%20 = load double, double* %13
%21 = fmul double %19, %20
%22 = load double*, double** %10
store double %21, double* %22
%23 = load double, double* %9
%24 = load double, double* %7
%25 = call double @sin(double %24)
%26 = fmul double %23, %25
%27 = load double, double* %13
%28 = fmul double %26, %27
%29 = load double*, double** %11
store double %28, double* %29
%30 = load double, double* %9
%31 = load double, double* %8
%32 = call double @sin(double %31)
%33 = fmul double %30, %32
%34 = load double*, double** %12
store double %33, double* %34
ret void
}

LLVM IR (-O2):
define void @sphe_to_rect(double %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = tail call double @cos(double %1)
%8 = tail call double @cos(double %0)
%9 = fmul double %8, %2
%10 = fmul double %7, %9
store double %10, double* %3
%11 = tail call double @sin(double %0)
%12 = fmul double %11, %2
%13 = fmul double %7, %12
store double %13, double* %4
%14 = tail call double @sin(double %1)
%15 = fmul double %14, %2
store double %15, double* %5
ret void
}