#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);
int quatNormalizef(float *q, float *qout) {
  float mag = 0.0, sign, eps = 1.e-12;
  int i;
  sign = (float)(q[0] >= 0.0) - (float)(q[0] < 0.0);
  for (i = 0; i < 4; ++i) {
    mag += q[i] * q[i];
    qout[i] = q[i];
  }
  mag = sign / sqrt(mag + eps);
  for (i = 0; i < 4; ++i) {
    qout[i] *= mag;
  }
}


x86 assembly (clang, -O0):
<quatNormalizef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  0xed0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2ss %eax,%xmm0
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm2
xorps  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
seta   %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    11e1 <quatNormalizef+0xd1>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1183 <quatNormalizef+0x73>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    1241 <quatNormalizef+0x131>
movss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1212 <quatNormalizef+0x102>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quatNormalizef>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movss  (%rdi),%xmm0
xorps  %xmm1,%xmm1
movaps %xmm0,%xmm2
movss  %xmm0,(%rsi)
xorps  %xmm5,%xmm5
cmpless %xmm0,%xmm5
movaps %xmm0,%xmm3
cmpltss %xmm1,%xmm3
movss  0xec2(%rip),%xmm4
andps  %xmm4,%xmm3
mulss  %xmm0,%xmm2
addss  %xmm1,%xmm2
movss  0x4(%rdi),%xmm0
movss  %xmm0,0x4(%rsi)
mulss  %xmm0,%xmm0
addss  %xmm2,%xmm0
movss  0x8(%rdi),%xmm2
movss  %xmm2,0x8(%rsi)
mulss  %xmm2,%xmm2
addss  %xmm0,%xmm2
movss  0xc(%rdi),%xmm0
movss  %xmm0,0xc(%rsi)
mulss  %xmm0,%xmm0
addss  %xmm2,%xmm0
andps  %xmm4,%xmm5
subss  %xmm3,%xmm5
addss  0xe76(%rip),%xmm0
ucomiss %xmm1,%xmm0
jb     1199 <quatNormalizef+0x89>
sqrtss %xmm0,%xmm0
jmp    11a6 <quatNormalizef+0x96>
movaps %xmm5,(%rsp)
call   1030 <sqrt@plt>
movaps (%rsp),%xmm5
divss  %xmm0,%xmm5
movups (%rbx),%xmm0
shufps $0x0,%xmm5,%xmm5
mulps  %xmm0,%xmm5
movups %xmm5,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @quatNormalizef(float* nocapture %0, float* nocapture %1) {
%3 = load float, float* %0
%4 = fcmp oge float %3, 0.000000e+00
%5 = fcmp olt float %3, 0.000000e+00
%6 = uitofp i1 %5 to float
%7 = tail call float @llvm.fmuladd.f32(float %3, float %3, float 0.000000e+00)
store float %3, float* %1
%8 = getelementptr inbounds float, float* %0, i64 1
%9 = load float, float* %8
%10 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %7)
%11 = getelementptr inbounds float, float* %1, i64 1
store float %9, float* %11
%12 = getelementptr inbounds float, float* %0, i64 2
%13 = load float, float* %12
%14 = tail call float @llvm.fmuladd.f32(float %13, float %13, float %10)
%15 = getelementptr inbounds float, float* %1, i64 2
store float %13, float* %15
%16 = getelementptr inbounds float, float* %0, i64 3
%17 = load float, float* %16
%18 = tail call float @llvm.fmuladd.f32(float %17, float %17, float %14)
%19 = getelementptr inbounds float, float* %1, i64 3
store float %17, float* %19
%20 = uitofp i1 %4 to float
%21 = fsub float %20, %6
%22 = fadd float %18, 0x3D71979980000000
%23 = tail call float @sqrt(float %22)
%24 = fdiv float %21, %23
%25 = bitcast float* %1 to <4 x float>*
%26 = load <4 x float>, <4 x float>* %25
%27 = insertelement <4 x float> poison, float %24, i64 0
%28 = shufflevector <4 x float> %27, <4 x float> poison, <4 x i32> zeroinitializer
%29 = fmul <4 x float> %28, %26
%30 = bitcast float* %1 to <4 x float>*
store <4 x float> %29, <4 x float>* %30
ret i32 undef
}