#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 get_xyz(const double *x, double *xyz) {
  double sinth = sin(x[2]);
  xyz[0] = x[0] * cos(x[1]) * sinth;
  xyz[1] = x[0] * sin(x[1]) * sinth;
  xyz[2] = x[0] * cos(x[2]);
}


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

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

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

LLVM IR (-O2):
define void @get_xyz(double* nocapture %0, double* nocapture writeonly %1) {
%3 = getelementptr inbounds double, double* %0, i64 2
%4 = load double, double* %3
%5 = tail call double @sin(double %4)
%6 = load double, double* %0
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = tail call double @cos(double %8)
%10 = fmul double %6, %9
%11 = fmul double %5, %10
store double %11, double* %1
%12 = load double, double* %0
%13 = load double, double* %7
%14 = tail call double @sin(double %13)
%15 = fmul double %12, %14
%16 = fmul double %5, %15
%17 = getelementptr inbounds double, double* %1, i64 1
store double %16, double* %17
%18 = load double, double* %0
%19 = load double, double* %3
%20 = tail call double @cos(double %19)
%21 = fmul double %18, %20
%22 = getelementptr inbounds double, double* %1, i64 2
store double %21, double* %22
ret void
}