#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 inv_q_norm4(float *q) {
  float mag;
  mag = sqrtf(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
  if (mag) {
    q[0] /= mag;
    q[1] /= mag;
    q[2] /= mag;
    q[3] /= mag;
  } else {
    q[0] = 1.f;
    q[1] = 0.f;
    q[2] = 0.f;
    q[3] = 0.f;
  }
}


x86 assembly (clang, -O0):
<inv_q_norm4>:
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 <sqrtf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a0 <inv_q_norm4+0x90>
jp     11a0 <inv_q_norm4+0x90>
jmp    11ff <inv_q_norm4+0xef>
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x4(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x8(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0xc(%rax)
jmp    1233 <inv_q_norm4+0x123>
mov    -0x8(%rbp),%rax
movss  0xdf5(%rip),%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
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_q_norm4>:
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 <inv_q_norm4+0x41>
sqrtss %xmm0,%xmm0
jmp    1159 <inv_q_norm4+0x49>
call   1030 <sqrtf@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1160 <inv_q_norm4+0x50>
jnp    1193 <inv_q_norm4+0x83>
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
divss  %xmm0,%xmm2
movss  %xmm2,0x4(%rbx)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%rbx)
movss  0xc(%rbx),%xmm1
divss  %xmm0,%xmm1
jmp    11a4 <inv_q_norm4+0x94>
movq   $0x3f800000,(%rbx)
movl   $0x0,0x8(%rbx)
xorps  %xmm1,%xmm1
movss  %xmm1,0xc(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @inv_q_norm4(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 @sqrtf(float %12)
%14 = fcmp une float %13, 0.000000e+00
br i1 %14, label %15, label %24
15: ; preds = %1
%16 = load float, float* %0
%17 = fdiv float %16, %13
store float %17, float* %0
%18 = load float, float* %3
%19 = fdiv float %18, %13
store float %19, float* %3
%20 = load float, float* %7
%21 = fdiv float %20, %13
store float %21, float* %7
%22 = load float, float* %10
%23 = fdiv float %22, %13
br label %25
24: ; preds = %1
store float 1.000000e+00, float* %0
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %7
br label %25
25: ; preds = %24, %15
%26 = phi float [ 0.000000e+00, %24 ], [ %23, %15 ]
store float %26, float* %10
ret void
}