#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 sqrt(double const);
void get_vec_from_rpz(const double *x, const double *vrpz, double *v) {
  double r = sqrt(x[0] * x[0] + x[1] * x[1]);
  double cp = x[0] / r;
  double sp = x[1] / r;
  v[0] = cp * vrpz[0] - sp * vrpz[1];
  v[1] = sp * vrpz[0] + cp * vrpz[1];
  v[2] = vrpz[2];
}


x86 assembly (clang, -O0):
<get_vec_from_rpz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x30(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_vec_from_rpz>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1143 <get_vec_from_rpz+0x33>
sqrtsd %xmm0,%xmm0
jmp    1148 <get_vec_from_rpz+0x38>
call   1030 <sqrt@plt>
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm2
divsd  %xmm0,%xmm1
divsd  %xmm0,%xmm2
movsd  0x8(%r15),%xmm0
mulsd  %xmm2,%xmm0
movsd  (%r15),%xmm3
mulsd  %xmm1,%xmm3
subsd  %xmm0,%xmm3
movsd  %xmm3,(%r14)
mulsd  0x8(%r15),%xmm1
mulsd  (%r15),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%r14)
movsd  0x10(%r15),%xmm0
movsd  %xmm0,0x10(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @get_vec_from_rpz(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load double*, double** %4
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = load double*, double** %4
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = fmul double %18, %21
%23 = call double @llvm.fmuladd.f64(double %12, double %15, double %22)
%24 = call double @sqrt(double %23)
store double %24, double* %7
%25 = load double*, double** %4
%26 = getelementptr inbounds double, double* %25, i64 0
%27 = load double, double* %26
%28 = load double, double* %7
%29 = fdiv double %27, %28
store double %29, double* %8
%30 = load double*, double** %4
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
%33 = load double, double* %7
%34 = fdiv double %32, %33
store double %34, double* %9
%35 = load double, double* %8
%36 = load double*, double** %5
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = load double, double* %9
%40 = load double*, double** %5
%41 = getelementptr inbounds double, double* %40, i64 1
%42 = load double, double* %41
%43 = fmul double %39, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double %35, double %38, double %44)
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 0
store double %45, double* %47
%48 = load double, double* %9
%49 = load double*, double** %5
%50 = getelementptr inbounds double, double* %49, i64 0
%51 = load double, double* %50
%52 = load double, double* %8
%53 = load double*, double** %5
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = fmul double %52, %55
%57 = call double @llvm.fmuladd.f64(double %48, double %51, double %56)
%58 = load double*, double** %6
%59 = getelementptr inbounds double, double* %58, i64 1
store double %57, double* %59
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 2
%62 = load double, double* %61
%63 = load double*, double** %6
%64 = getelementptr inbounds double, double* %63, i64 2
store double %62, double* %64
ret void
}

LLVM IR (-O2):
define void @get_vec_from_rpz(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = tail call double @sqrt(double %8)
%10 = load double, double* %0
%11 = fdiv double %10, %9
%12 = load double, double* %5
%13 = fdiv double %12, %9
%14 = load double, double* %1
%15 = getelementptr inbounds double, double* %1, i64 1
%16 = load double, double* %15
%17 = fneg double %13
%18 = fmul double %16, %17
%19 = tail call double @llvm.fmuladd.f64(double %11, double %14, double %18)
store double %19, double* %2
%20 = load double, double* %1
%21 = load double, double* %15
%22 = fmul double %11, %21
%23 = tail call double @llvm.fmuladd.f64(double %13, double %20, double %22)
%24 = getelementptr inbounds double, double* %2, i64 1
store double %23, double* %24
%25 = getelementptr inbounds double, double* %1, i64 2
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %2, i64 2
store double %26, double* %27
ret void
}