#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 */
double sqrt(double);
void normalize_vect(double *e) {
  double pdot;
  int k;
  pdot = e[0] * e[0] + e[1] * e[1] + e[2] * e[2];
  pdot = sqrt(pdot);
  for (k = 0; k < 3; k++)
    e[k] /= pdot;
}


x86 assembly (clang, -O0):
<normalize_vect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11ae <normalize_vect+0x9e>
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <normalize_vect+0x6b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_vect>:
push   %rbx
mov    %rdi,%rbx
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1146 <normalize_vect+0x36>
sqrtsd %xmm0,%xmm0
jmp    114b <normalize_vect+0x3b>
call   1030 <sqrt@plt>
movupd (%rbx),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,(%rbx)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rbx)
pop    %rbx
ret

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

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