#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 */
int sqrt(float);
void rvec2st(float v[3], float st[2]) {
  double m;
  m = 2 * sqrt(v[0] * v[0] + v[1] * v[1] + (v[2] + 1) * (v[2] + 1));
  st[0] = v[0] / m + 0.5;
  st[1] = v[1] / m + 0.5;
}


x86 assembly (clang, -O0):
<rvec2st>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0xeb2(%rip),%xmm0
addss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0xea1(%rip),%xmm2
addss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rvec2st>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rdi),%xmm0
addss  0xec4(%rip),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movss  (%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm0,%xmm1
movsd  0xea2(%rip),%xmm2
addsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x4(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @rvec2st(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca double
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %3
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = load float*, float** %3
%10 = getelementptr inbounds float, float* %9, i64 0
%11 = load float, float* %10
%12 = load float*, float** %3
%13 = getelementptr inbounds float, float* %12, i64 1
%14 = load float, float* %13
%15 = load float*, float** %3
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float, float* %16
%18 = fmul float %14, %17
%19 = call float @llvm.fmuladd.f32(float %8, float %11, float %18)
%20 = load float*, float** %3
%21 = getelementptr inbounds float, float* %20, i64 2
%22 = load float, float* %21
%23 = fadd float %22, 1.000000e+00
%24 = load float*, float** %3
%25 = getelementptr inbounds float, float* %24, i64 2
%26 = load float, float* %25
%27 = fadd float %26, 1.000000e+00
%28 = call float @llvm.fmuladd.f32(float %23, float %27, float %19)
%29 = call i32 @sqrt(float %28)
%30 = mul nsw i32 2, %29
%31 = sitofp i32 %30 to double
store double %31, double* %5
%32 = load float*, float** %3
%33 = getelementptr inbounds float, float* %32, i64 0
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = load double, double* %5
%37 = fdiv double %35, %36
%38 = fadd double %37, 5.000000e-01
%39 = fptrunc double %38 to float
%40 = load float*, float** %4
%41 = getelementptr inbounds float, float* %40, i64 0
store float %39, float* %41
%42 = load float*, float** %3
%43 = getelementptr inbounds float, float* %42, i64 1
%44 = load float, float* %43
%45 = fpext float %44 to double
%46 = load double, double* %5
%47 = fdiv double %45, %46
%48 = fadd double %47, 5.000000e-01
%49 = fptrunc double %48 to float
%50 = load float*, float** %4
%51 = getelementptr inbounds float, float* %50, i64 1
store float %49, float* %51
ret void
}

LLVM IR (-O2):
define void @rvec2st(float* nocapture %0, float* nocapture writeonly %1) {
%3 = load float, float* %0
%4 = getelementptr inbounds float, float* %0, i64 1
%5 = load float, float* %4
%6 = fmul float %5, %5
%7 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %6)
%8 = getelementptr inbounds float, float* %0, i64 2
%9 = load float, float* %8
%10 = fadd float %9, 1.000000e+00
%11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %7)
%12 = tail call i32 @sqrt(float %11)
%13 = shl nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = load float, float* %0
%16 = fpext float %15 to double
%17 = fdiv double %16, %14
%18 = fadd double %17, 5.000000e-01
%19 = fptrunc double %18 to float
store float %19, float* %1
%20 = load float, float* %4
%21 = fpext float %20 to double
%22 = fdiv double %21, %14
%23 = fadd double %22, 5.000000e-01
%24 = fptrunc double %23 to float
%25 = getelementptr inbounds float, float* %1, i64 1
store float %24, float* %25
ret void
}