#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 point_product(double *, double *);
double sqrt(double);
void normalize(double *vec) {
  double norm;
  int i;
  norm = 0.0;
  norm = point_product(vec, vec);
  norm = sqrt(norm);
  for (i = 0; i < 3; i++) {
    vec[i] = vec[i] / norm;
  }
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <point_product@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1193 <normalize+0x73>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <normalize+0x3c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%rsi
call   1030 <point_product@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     113c <normalize+0x1c>
sqrtsd %xmm0,%xmm0
jmp    1141 <normalize+0x21>
call   1040 <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(double* %0) {
%2 = alloca double*
%3 = alloca double
%4 = alloca i32
store double* %0, double** %2
store double 0.000000e+00, double* %3
%5 = load double*, double** %2
%6 = load double*, double** %2
%7 = call double @point_product(double* %5, double* %6)
store double %7, double* %3
%8 = load double, double* %3
%9 = call double @sqrt(double %8)
store double %9, double* %3
store i32 0, i32* %4
br label %10
10: ; preds = %25, %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load double*, double** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double, double* %3
%20 = fdiv double %18, %19
%21 = load double*, double** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
store double %20, double* %24
br label %25
25: ; preds = %13
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %10
28: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @normalize(double* %0) {
%2 = tail call double @point_product(double* %0, double* %0)
%3 = tail call double @sqrt(double %2)
%4 = bitcast double* %0 to <2 x double>*
%5 = load <2 x double>, <2 x double>* %4
%6 = insertelement <2 x double> poison, double %3, i64 0
%7 = shufflevector <2 x double> %6, <2 x double> poison, <2 x i32> zeroinitializer
%8 = fdiv <2 x double> %5, %7
%9 = bitcast double* %0 to <2 x double>*
store <2 x double> %8, <2 x double>* %9
%10 = getelementptr inbounds double, double* %0, i64 2
%11 = load double, double* %10
%12 = fdiv double %11, %3
store double %12, double* %10
ret void
}