#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 fabs(float);
float sqrtf(float);
void vec4_clampw(float q[4], float w) {
  if ((fabs(w) < 0.999f) && (fabs(q[3]) < 0.999f)) {
    float k = 1.0f - w * w;
    k /= (((q)[0] * (q)[0] + (q)[1] * (q)[1] + (q)[2] * (q)[2]));
    k = sqrtf(k);
    q[0] *= k;
    q[1] *= k;
    q[2] *= k;
    q[3] = w;
  } else {
    {
      (q)[0] = 0.0;
      (q)[1] = 0.0;
      (q)[2] = 0.0;
      (q)[3] = 1.0;
    };
  }
}


x86 assembly (clang, -O0):
<vec4_clampw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movss  0xeba(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    1248 <vec4_clampw+0x128>
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movss  0xe98(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    1248 <vec4_clampw+0x128>
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm1,%xmm0
movss  0xe70(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
call   1040 <sqrtf@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
movss  %xmm0,0x4(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm0
movss  %xmm0,0x8(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
jmp    127c <vec4_clampw+0x15c>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movss  0xd8d(%rip),%xmm0
movss  %xmm0,0xc(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec4_clampw>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,%xmm3
mov    %rdi,%rbx
movaps 0xede(%rip),%xmm1
andps  %xmm0,%xmm1
movss  0xef3(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    118a <vec4_clampw+0x7a>
movss  0xc(%rbx),%xmm1
andps  0xec2(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    118a <vec4_clampw+0x7a>
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
movss  0xed2(%rip),%xmm0
subss  %xmm1,%xmm0
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
mulss  %xmm2,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
movss  0x8(%rbx),%xmm2
mulss  %xmm2,%xmm2
addss  %xmm1,%xmm2
divss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1196 <vec4_clampw+0x86>
sqrtss %xmm0,%xmm0
jmp    11a3 <vec4_clampw+0x93>
movaps 0xe7f(%rip),%xmm0
movups %xmm0,(%rbx)
jmp    11cc <vec4_clampw+0xbc>
movaps %xmm3,(%rsp)
call   1030 <sqrtf@plt>
movaps (%rsp),%xmm3
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  0x4(%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rbx)
mulss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%rbx)
movss  %xmm3,0xc(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @vec4_clampw(float* %0, float %1) {
%3 = alloca float*
%4 = alloca float
%5 = alloca float
store float* %0, float** %3
store float %1, float* %4
%6 = load float, float* %4
%7 = call float @fabs(float %6)
%8 = fcmp olt float %7, 0x3FEFF7CEE0000000
br i1 %8, label %9, label %63
9: ; preds = %2
%10 = load float*, float** %3
%11 = getelementptr inbounds float, float* %10, i64 3
%12 = load float, float* %11
%13 = call float @fabs(float %12)
%14 = fcmp olt float %13, 0x3FEFF7CEE0000000
br i1 %14, label %15, label %63
15: ; preds = %9
%16 = load float, float* %4
%17 = load float, float* %4
%18 = fneg float %16
%19 = call float @llvm.fmuladd.f32(float %18, float %17, float 1.000000e+00)
store float %19, float* %5
%20 = load float*, float** %3
%21 = getelementptr inbounds float, float* %20, i64 0
%22 = load float, float* %21
%23 = load float*, float** %3
%24 = getelementptr inbounds float, float* %23, i64 0
%25 = load float, float* %24
%26 = load float*, float** %3
%27 = getelementptr inbounds float, float* %26, i64 1
%28 = load float, float* %27
%29 = load float*, float** %3
%30 = getelementptr inbounds float, float* %29, i64 1
%31 = load float, float* %30
%32 = fmul float %28, %31
%33 = call float @llvm.fmuladd.f32(float %22, float %25, float %32)
%34 = load float*, float** %3
%35 = getelementptr inbounds float, float* %34, i64 2
%36 = load float, float* %35
%37 = load float*, float** %3
%38 = getelementptr inbounds float, float* %37, i64 2
%39 = load float, float* %38
%40 = call float @llvm.fmuladd.f32(float %36, float %39, float %33)
%41 = load float, float* %5
%42 = fdiv float %41, %40
store float %42, float* %5
%43 = load float, float* %5
%44 = call float @sqrtf(float %43)
store float %44, float* %5
%45 = load float, float* %5
%46 = load float*, float** %3
%47 = getelementptr inbounds float, float* %46, i64 0
%48 = load float, float* %47
%49 = fmul float %48, %45
store float %49, float* %47
%50 = load float, float* %5
%51 = load float*, float** %3
%52 = getelementptr inbounds float, float* %51, i64 1
%53 = load float, float* %52
%54 = fmul float %53, %50
store float %54, float* %52
%55 = load float, float* %5
%56 = load float*, float** %3
%57 = getelementptr inbounds float, float* %56, i64 2
%58 = load float, float* %57
%59 = fmul float %58, %55
store float %59, float* %57
%60 = load float, float* %4
%61 = load float*, float** %3
%62 = getelementptr inbounds float, float* %61, i64 3
store float %60, float* %62
br label %72
63: ; preds = %9, %2
%64 = load float*, float** %3
%65 = getelementptr inbounds float, float* %64, i64 0
store float 0.000000e+00, float* %65
%66 = load float*, float** %3
%67 = getelementptr inbounds float, float* %66, i64 1
store float 0.000000e+00, float* %67
%68 = load float*, float** %3
%69 = getelementptr inbounds float, float* %68, i64 2
store float 0.000000e+00, float* %69
%70 = load float*, float** %3
%71 = getelementptr inbounds float, float* %70, i64 3
store float 1.000000e+00, float* %71
br label %72
72: ; preds = %63, %15
ret void
}

LLVM IR (-O2):
define void @vec4_clampw(float* nocapture %0, float %1) {
%3 = tail call float @llvm.fabs.f32(float %1)
%4 = fcmp olt float %3, 0x3FEFF7CEE0000000
br i1 %4, label %5, label %29
5: ; preds = %2
%6 = getelementptr inbounds float, float* %0, i64 3
%7 = load float, float* %6
%8 = tail call float @llvm.fabs.f32(float %7)
%9 = fcmp olt float %8, 0x3FEFF7CEE0000000
br i1 %9, label %10, label %29
10: ; preds = %5
%11 = fneg float %1
%12 = tail call float @llvm.fmuladd.f32(float %11, float %1, float 1.000000e+00)
%13 = load float, float* %0
%14 = getelementptr inbounds float, float* %0, i64 1
%15 = load float, float* %14
%16 = fmul float %15, %15
%17 = tail call float @llvm.fmuladd.f32(float %13, float %13, float %16)
%18 = getelementptr inbounds float, float* %0, i64 2
%19 = load float, float* %18
%20 = tail call float @llvm.fmuladd.f32(float %19, float %19, float %17)
%21 = fdiv float %12, %20
%22 = tail call float @sqrtf(float %21)
%23 = load float, float* %0
%24 = fmul float %22, %23
store float %24, float* %0
%25 = load float, float* %14
%26 = fmul float %22, %25
store float %26, float* %14
%27 = load float, float* %18
%28 = fmul float %22, %27
store float %28, float* %18
store float %1, float* %6
br label %31
29: ; preds = %5, %2
%30 = bitcast float* %0 to <4 x float>*
store <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00>, <4 x float>* %30
br label %31
31: ; preds = %29, %10
ret void
}