#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 */
scalar_t__ pow(float, int);
float sqrt(scalar_t__);
void quat_normalize(float *quat) {
  float norm =
      sqrt(pow(*((float *)(quat)), 2) + pow(*((float *)(quat + 1)), 2) +
           pow(*((float *)(quat + 2)), 2) + pow(*((float *)(quat + 3)), 2));
  *quat = *quat / norm;
  *(quat + 1) = *(quat + 1) / norm;
  *(quat + 2) = *(quat + 2) / norm;
  *(quat + 3) = *(quat + 3) / norm;
}


x86 assembly (clang, -O0):
<quat_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
call   1040 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
divss  -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movss  (%rdi),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
movss  0x4(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
add    %rax,%rbx
movss  0x8(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
add    %rax,%rbx
movss  0xc(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1040 <sqrt@plt>
movups (%r14),%xmm1
shufps $0x0,%xmm0,%xmm0
divps  %xmm0,%xmm1
movups %xmm1,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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