#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 lonlat_to_xyz(double lon, double lat, double *xyz) {
  double coslat = cos(lat);
  xyz[0] = coslat * cos(lon);
  xyz[1] = coslat * sin(lon);
  xyz[2] = sin(lat);
}


x86 assembly (clang, -O0):
<lonlat_to_xyz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
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
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  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @lonlat_to_xyz(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 = call double @cos(double %8)
store double %9, double* %7
%10 = load double, double* %7
%11 = load double, double* %4
%12 = call double @cos(double %11)
%13 = fmul double %10, %12
%14 = load double*, double** %6
%15 = getelementptr inbounds double, double* %14, i64 0
store double %13, double* %15
%16 = load double, double* %7
%17 = load double, double* %4
%18 = call double @sin(double %17)
%19 = fmul double %16, %18
%20 = load double*, double** %6
%21 = getelementptr inbounds double, double* %20, i64 1
store double %19, double* %21
%22 = load double, double* %5
%23 = call double @sin(double %22)
%24 = load double*, double** %6
%25 = getelementptr inbounds double, double* %24, i64 2
store double %23, double* %25
ret void
}

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