#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 */
typedef double GLdouble;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
double sqrt(double);
void normalize(GLdouble v[3]) {
  GLdouble d;
  d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (d == 0.0) {
    error("normalize: zero length vector");
    v[0] = d = 1.0;
  }
  d = 1 / d;
  v[0] *= d;
  v[1] *= d;
  v[2] *= d;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bb <normalize+0x9b>
jp     11bb <normalize+0x9b>
lea    0xe6f(%rip),%rdi
call   1030 <error@plt>
movsd  0xe5a(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xe3d(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,0x10(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
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     1156 <normalize+0x36>
sqrtsd %xmm0,%xmm0
jmp    115f <normalize+0x3f>
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1181 <normalize+0x61>
jp     1181 <normalize+0x61>
lea    0xe9a(%rip),%rdi
call   1030 <error@plt>
movsd  0xe85(%rip),%xmm1
movapd %xmm1,%xmm0
jmp    1185 <normalize+0x65>
movsd  (%rbx),%xmm1
movsd  0xe73(%rip),%xmm2
divsd  %xmm0,%xmm2
movhpd 0x8(%rbx),%xmm1
movapd %xmm2,%xmm0
unpcklpd %xmm2,%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm0,(%rbx)
mulsd  0x10(%rbx),%xmm2
movsd  %xmm2,0x10(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"normalize: zero length vector\00"
define void @normalize(double* %0) {
%2 = alloca double*
%3 = alloca double
store double* %0, double** %2
%4 = load double*, double** %2
%5 = getelementptr inbounds double, double* %4, i64 0
%6 = load double, double* %5
%7 = load double*, double** %2
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = load double*, double** %2
%11 = getelementptr inbounds double, double* %10, i64 1
%12 = load double, double* %11
%13 = load double*, double** %2
%14 = getelementptr inbounds double, double* %13, i64 1
%15 = load double, double* %14
%16 = fmul double %12, %15
%17 = call double @llvm.fmuladd.f64(double %6, double %9, double %16)
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 2
%20 = load double, double* %19
%21 = load double*, double** %2
%22 = getelementptr inbounds double, double* %21, i64 2
%23 = load double, double* %22
%24 = call double @llvm.fmuladd.f64(double %20, double %23, double %17)
%25 = call double @sqrt(double %24)
store double %25, double* %3
%26 = load double, double* %3
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %28, label %32
28: ; preds = %1
%29 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store double 1.000000e+00, double* %3
%30 = load double*, double** %2
%31 = getelementptr inbounds double, double* %30, i64 0
store double 1.000000e+00, double* %31
br label %32
32: ; preds = %28, %1
%33 = load double, double* %3
%34 = fdiv double 1.000000e+00, %33
store double %34, double* %3
%35 = load double, double* %3
%36 = load double*, double** %2
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = fmul double %38, %35
store double %39, double* %37
%40 = load double, double* %3
%41 = load double*, double** %2
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = fmul double %43, %40
store double %44, double* %42
%45 = load double, double* %3
%46 = load double*, double** %2
%47 = getelementptr inbounds double, double* %46, i64 2
%48 = load double, double* %47
%49 = fmul double %48, %45
store double %49, double* %47
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"normalize: zero length vector\00"
define void @normalize(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 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = load double, double* %0
br label %16
14: ; preds = %1
%15 = tail call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %12, %14
%17 = phi double [ 1.000000e+00, %14 ], [ %13, %12 ]
%18 = phi double [ 1.000000e+00, %14 ], [ %10, %12 ]
%19 = fdiv double 1.000000e+00, %18
%20 = load double, double* %3
%21 = insertelement <2 x double> poison, double %17, i64 0
%22 = insertelement <2 x double> %21, double %20, i64 1
%23 = insertelement <2 x double> poison, double %19, i64 0
%24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
%25 = fmul <2 x double> %22, %24
%26 = bitcast double* %0 to <2 x double>*
store <2 x double> %25, <2 x double>* %26
%27 = load double, double* %7
%28 = fmul double %19, %27
store double %28, double* %7
ret void
}