#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 */
float sqrt(float);
void quaternion_w(float orientation[4]) {
  float t = 1.0f;
  t -= orientation[0] * orientation[0];
  t -= orientation[1] * orientation[1];
  t -= orientation[2] * orientation[2];
  if (t < 0.0f) {
    orientation[3] = 0.0f;
  } else {
    orientation[3] = -sqrt(t);
  }
}


x86 assembly (clang, -O0):
<quaternion_w>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movss  0xedc(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
movss  -0xc(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm2
movss  -0xc(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
movss  -0xc(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    11d8 <quaternion_w+0xc8>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
jmp    11f8 <quaternion_w+0xe8>
movss  -0xc(%rbp),%xmm0
call   1030 <sqrt@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quaternion_w>:
push   %rbx
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm2
mulss  %xmm1,%xmm1
movss  0xed7(%rip),%xmm0
subss  %xmm1,%xmm0
mulss  %xmm2,%xmm2
subss  %xmm2,%xmm0
movss  0x8(%rdi),%xmm1
mulss  %xmm1,%xmm1
subss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     116a <quaternion_w+0x5a>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     115b <quaternion_w+0x4b>
xorps  %xmm1,%xmm1
sqrtss %xmm0,%xmm1
jmp    1163 <quaternion_w+0x53>
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
xorps  0xea6(%rip),%xmm1
movss  %xmm1,0xc(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @quaternion_w(float* %0) {
%2 = alloca float*
%3 = alloca float
store float* %0, float** %2
store float 1.000000e+00, float* %3
%4 = load float*, float** %2
%5 = getelementptr inbounds float, float* %4, i64 0
%6 = load float, float* %5
%7 = load float*, float** %2
%8 = getelementptr inbounds float, float* %7, i64 0
%9 = load float, float* %8
%10 = load float, float* %3
%11 = fneg float %6
%12 = call float @llvm.fmuladd.f32(float %11, float %9, float %10)
store float %12, float* %3
%13 = load float*, float** %2
%14 = getelementptr inbounds float, float* %13, i64 1
%15 = load float, float* %14
%16 = load float*, float** %2
%17 = getelementptr inbounds float, float* %16, i64 1
%18 = load float, float* %17
%19 = load float, float* %3
%20 = fneg float %15
%21 = call float @llvm.fmuladd.f32(float %20, float %18, float %19)
store float %21, float* %3
%22 = load float*, float** %2
%23 = getelementptr inbounds float, float* %22, i64 2
%24 = load float, float* %23
%25 = load float*, float** %2
%26 = getelementptr inbounds float, float* %25, i64 2
%27 = load float, float* %26
%28 = load float, float* %3
%29 = fneg float %24
%30 = call float @llvm.fmuladd.f32(float %29, float %27, float %28)
store float %30, float* %3
%31 = load float, float* %3
%32 = fcmp olt float %31, 0.000000e+00
br i1 %32, label %33, label %36
33: ; preds = %1
%34 = load float*, float** %2
%35 = getelementptr inbounds float, float* %34, i64 3
store float 0.000000e+00, float* %35
br label %42
36: ; preds = %1
%37 = load float, float* %3
%38 = call float @sqrt(float %37)
%39 = fneg float %38
%40 = load float*, float** %2
%41 = getelementptr inbounds float, float* %40, i64 3
store float %39, float* %41
br label %42
42: ; preds = %36, %33
ret void
}

LLVM IR (-O2):
define void @quaternion_w(float* nocapture %0) {
%2 = load float, float* %0
%3 = fneg float %2
%4 = tail call float @llvm.fmuladd.f32(float %3, float %2, float 1.000000e+00)
%5 = getelementptr inbounds float, float* %0, i64 1
%6 = load float, float* %5
%7 = fneg float %6
%8 = tail call float @llvm.fmuladd.f32(float %7, float %6, float %4)
%9 = getelementptr inbounds float, float* %0, i64 2
%10 = load float, float* %9
%11 = fneg float %10
%12 = tail call float @llvm.fmuladd.f32(float %11, float %10, float %8)
%13 = fcmp olt float %12, 0.000000e+00
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = tail call float @sqrt(float %12)
%16 = fneg float %15
br label %17
17: ; preds = %1, %14
%18 = phi float [ %16, %14 ], [ 0.000000e+00, %1 ]
%19 = getelementptr inbounds float, float* %0, i64 3
store float %18, float* %19
ret void
}