#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 normalize_quat(float q[4]) {
  int i;
  float mag;
  mag = sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
  for (i = 0; i < 4; i++)
    q[i] /= mag;
}


x86 assembly (clang, -O0):
<normalize_quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%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
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    11be <normalize_quat+0xae>
movss  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <normalize_quat+0x7b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_quat>:
push   %rbx
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  0x8(%rdi),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0xc(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1151 <normalize_quat+0x41>
sqrtss %xmm0,%xmm0
jmp    1156 <normalize_quat+0x46>
call   1030 <sqrt@plt>
movups (%rbx),%xmm1
shufps $0x0,%xmm0,%xmm0
divps  %xmm0,%xmm1
movups %xmm1,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @normalize_quat(float* %0) {
%2 = alloca float*
%3 = alloca i32
%4 = alloca float
store float* %0, float** %2
%5 = load float*, float** %2
%6 = getelementptr inbounds float, float* %5, i64 0
%7 = load float, float* %6
%8 = load float*, float** %2
%9 = getelementptr inbounds float, float* %8, i64 0
%10 = load float, float* %9
%11 = load float*, float** %2
%12 = getelementptr inbounds float, float* %11, i64 1
%13 = load float, float* %12
%14 = load float*, float** %2
%15 = getelementptr inbounds float, float* %14, i64 1
%16 = load float, float* %15
%17 = fmul float %13, %16
%18 = call float @llvm.fmuladd.f32(float %7, float %10, float %17)
%19 = load float*, float** %2
%20 = getelementptr inbounds float, float* %19, i64 2
%21 = load float, float* %20
%22 = load float*, float** %2
%23 = getelementptr inbounds float, float* %22, i64 2
%24 = load float, float* %23
%25 = call float @llvm.fmuladd.f32(float %21, float %24, float %18)
%26 = load float*, float** %2
%27 = getelementptr inbounds float, float* %26, i64 3
%28 = load float, float* %27
%29 = load float*, float** %2
%30 = getelementptr inbounds float, float* %29, i64 3
%31 = load float, float* %30
%32 = call float @llvm.fmuladd.f32(float %28, float %31, float %25)
%33 = call float @sqrt(float %32)
store float %33, float* %4
store i32 0, i32* %3
br label %34
34: ; preds = %45, %1
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 4
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load float, float* %4
%39 = load float*, float** %2
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %39, i64 %41
%43 = load float, float* %42
%44 = fdiv float %43, %38
store float %44, float* %42
br label %45
45: ; preds = %37
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %34
48: ; preds = %34
ret void
}

LLVM IR (-O2):
define void @normalize_quat(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fmul float %4, %4
%6 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %5)
%7 = getelementptr inbounds float, float* %0, i64 2
%8 = load float, float* %7
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %6)
%10 = getelementptr inbounds float, float* %0, i64 3
%11 = load float, float* %10
%12 = tail call float @llvm.fmuladd.f32(float %11, float %11, float %9)
%13 = tail call float @sqrt(float %12)
%14 = bitcast float* %0 to <4 x float>*
%15 = load <4 x float>, <4 x float>* %14
%16 = insertelement <4 x float> poison, float %13, i64 0
%17 = shufflevector <4 x float> %16, <4 x float> poison, <4 x i32> zeroinitializer
%18 = fdiv <4 x float> %15, %17
%19 = bitcast float* %0 to <4 x float>*
store <4 x float> %18, <4 x float>* %19
ret void
}