#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 spher_to_cart(double cart[3], double spher[3]) {
  cart[0] = spher[2] * cos(spher[1]) * sin(spher[0]);
  cart[1] = spher[2] * sin(spher[1]) * sin(spher[0]);
  cart[2] = spher[2] * cos(spher[0]);
}


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

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

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

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