#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 sqrtf(float);
void vec4_normalize(float *dst) {
  float x = dst[0];
  float y = dst[1];
  float z = dst[2];
  float w = dst[3];
  float len = x * x + y * y + z * z + w * w;
  if (len > 0) {
    len = 1 / sqrtf(len);
    dst[0] = x * len;
    dst[1] = y * len;
    dst[2] = z * len;
    dst[3] = w * len;
  }
}


x86 assembly (clang, -O0):
<vec4_normalize>:
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)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x14(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1211 <vec4_normalize+0x101>
movss  -0x1c(%rbp),%xmm0
call   1030 <sqrtf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x14(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x18(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec4_normalize>:
push   %rbx
sub    $0x10,%rsp
movups (%rdi),%xmm3
movaps %xmm3,%xmm0
mulps  %xmm3,%xmm0
shufps $0x55,%xmm0,%xmm0
movaps %xmm3,%xmm1
mulss  %xmm3,%xmm1
addss  %xmm0,%xmm1
movaps %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
mulss  %xmm2,%xmm2
addss  %xmm1,%xmm2
movaps %xmm3,%xmm0
shufps $0xff,%xmm3,%xmm0
mulss  %xmm0,%xmm0
addss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    117f <vec4_normalize+0x6f>
mov    %rdi,%rbx
movaps %xmm3,(%rsp)
call   1030 <sqrtf@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
shufps $0x0,%xmm0,%xmm0
movaps (%rsp),%xmm1
mulps  %xmm0,%xmm1
movups %xmm1,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @vec4_normalize(float* %0) {
%2 = alloca float*
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float* %0, float** %2
%8 = load float*, float** %2
%9 = getelementptr inbounds float, float* %8, i64 0
%10 = load float, float* %9
store float %10, float* %3
%11 = load float*, float** %2
%12 = getelementptr inbounds float, float* %11, i64 1
%13 = load float, float* %12
store float %13, float* %4
%14 = load float*, float** %2
%15 = getelementptr inbounds float, float* %14, i64 2
%16 = load float, float* %15
store float %16, float* %5
%17 = load float*, float** %2
%18 = getelementptr inbounds float, float* %17, i64 3
%19 = load float, float* %18
store float %19, float* %6
%20 = load float, float* %3
%21 = load float, float* %3
%22 = load float, float* %4
%23 = load float, float* %4
%24 = fmul float %22, %23
%25 = call float @llvm.fmuladd.f32(float %20, float %21, float %24)
%26 = load float, float* %5
%27 = load float, float* %5
%28 = call float @llvm.fmuladd.f32(float %26, float %27, float %25)
%29 = load float, float* %6
%30 = load float, float* %6
%31 = call float @llvm.fmuladd.f32(float %29, float %30, float %28)
store float %31, float* %7
%32 = load float, float* %7
%33 = fcmp ogt float %32, 0.000000e+00
br i1 %33, label %34, label %59
34: ; preds = %1
%35 = load float, float* %7
%36 = call i32 @sqrtf(float %35)
%37 = sdiv i32 1, %36
%38 = sitofp i32 %37 to float
store float %38, float* %7
%39 = load float, float* %3
%40 = load float, float* %7
%41 = fmul float %39, %40
%42 = load float*, float** %2
%43 = getelementptr inbounds float, float* %42, i64 0
store float %41, float* %43
%44 = load float, float* %4
%45 = load float, float* %7
%46 = fmul float %44, %45
%47 = load float*, float** %2
%48 = getelementptr inbounds float, float* %47, i64 1
store float %46, float* %48
%49 = load float, float* %5
%50 = load float, float* %7
%51 = fmul float %49, %50
%52 = load float*, float** %2
%53 = getelementptr inbounds float, float* %52, i64 2
store float %51, float* %53
%54 = load float, float* %6
%55 = load float, float* %7
%56 = fmul float %54, %55
%57 = load float*, float** %2
%58 = getelementptr inbounds float, float* %57, i64 3
store float %56, float* %58
br label %59
59: ; preds = %34, %1
ret void
}

LLVM IR (-O2):
define void @vec4_normalize(float* nocapture %0) {
%2 = bitcast float* %0 to <4 x float>*
%3 = load <4 x float>, <4 x float>* %2
%4 = fmul <4 x float> %3, %3
%5 = extractelement <4 x float> %4, i64 1
%6 = extractelement <4 x float> %3, i64 0
%7 = tail call float @llvm.fmuladd.f32(float %6, float %6, float %5)
%8 = extractelement <4 x float> %3, i64 2
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %7)
%10 = extractelement <4 x float> %3, i64 3
%11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %9)
%12 = fcmp ogt float %11, 0.000000e+00
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = tail call i32 @sqrtf(float %11)
%15 = add i32 %14, 1
%16 = icmp ult i32 %15, 3
%17 = select i1 %16, i32 %14, i32 0
%18 = sitofp i32 %17 to float
%19 = insertelement <4 x float> poison, float %18, i64 0
%20 = shufflevector <4 x float> %19, <4 x float> poison, <4 x i32> zeroinitializer
%21 = fmul <4 x float> %3, %20
%22 = bitcast float* %0 to <4 x float>*
store <4 x float> %21, <4 x float>* %22
br label %23
23: ; preds = %13, %1
ret void
}