#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 sqrtf(float);
void vec4_ClampQuaternionRotation(float q[4], float cos_abs) {
  if (q[3] < cos_abs) {
    float k = sqrtf((1.0f - cos_abs * cos_abs) / (1.0f - q[3] * q[3]));
    q[0] *= k;
    q[1] *= k;
    q[2] *= k;
    q[3] = cos_abs;
  }
}


x86 assembly (clang, -O0):
<vec4_ClampQuaternionRotation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11e1 <vec4_ClampQuaternionRotation+0xd1>
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm1,%xmm0
movss  0xea5(%rip),%xmm1
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm2
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm1
movss  0xe76(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
call   1030 <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)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec4_ClampQuaternionRotation>:
push   %rbx
sub    $0x10,%rsp
movss  0xc(%rdi),%xmm1
ucomiss %xmm1,%xmm0
jbe    118f <vec4_ClampQuaternionRotation+0x7f>
movaps %xmm0,%xmm4
mov    %rdi,%rbx
movaps %xmm0,%xmm2
mulss  %xmm4,%xmm2
movss  0xecc(%rip),%xmm3
movaps %xmm3,%xmm0
subss  %xmm2,%xmm0
mulss  %xmm1,%xmm1
subss  %xmm1,%xmm3
divss  %xmm3,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1155 <vec4_ClampQuaternionRotation+0x45>
sqrtss %xmm0,%xmm0
jmp    1166 <vec4_ClampQuaternionRotation+0x56>
movss  %xmm4,0xc(%rsp)
call   1030 <sqrtf@plt>
movss  0xc(%rsp),%xmm4
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  %xmm4,0xc(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

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