#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 /*<<< orphan*/ fabs(double);
float sqrtf(int /*<<< orphan*/);
void quat_calculateW(float *dst) {
  float x = dst[0], y = dst[1], z = dst[2];
  dst[0] = x;
  dst[1] = y;
  dst[2] = z;
  dst[3] = sqrtf(fabs(1.0 - x * x - y * y - z * z));
}


x86 assembly (clang, -O0):
<quat_calculateW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0xc(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe6c(%rip),%xmm0
subsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
movss  -0x14(%rbp),%xmm1
mulss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
call   1040 <sqrtf@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_calculateW>:
push   %rbx
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
movss  0x8(%rdi),%xmm2
mulss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm3
movsd  0xebe(%rip),%xmm0
subsd  %xmm3,%xmm0
mulss  %xmm1,%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
mulss  %xmm2,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%edi
call   1040 <sqrtf@plt>
movss  %xmm0,0xc(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @quat_calculateW(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = getelementptr inbounds float, float* %0, i64 2
%6 = load float, float* %5
%7 = fmul float %2, %2
%8 = fpext float %7 to double
%9 = fsub double 1.000000e+00, %8
%10 = fmul float %4, %4
%11 = fpext float %10 to double
%12 = fsub double %9, %11
%13 = fmul float %6, %6
%14 = fpext float %13 to double
%15 = fsub double %12, %14
%16 = tail call i32 @fabs(double %15)
%17 = tail call float @sqrtf(i32 %16)
%18 = getelementptr inbounds float, float* %0, i64 3
store float %17, float* %18
ret void
}