#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);
int matNormalize(double *v1, double *v2) {
  double d;
  d = sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
  if (d == 0.0)
    return -1;
  v2[0] = v1[0] / d;
  v2[1] = v1[1] / d;
  v2[2] = v1[2] / d;
  return 0;
}


x86 assembly (clang, -O0):
<matNormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <matNormalize+0x82>
jp     1192 <matNormalize+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <matNormalize+0xcc>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matNormalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
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     114c <matNormalize+0x3c>
sqrtsd %xmm0,%xmm0
jmp    1155 <matNormalize+0x45>
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
mov    $0xffffffff,%eax
ucomisd %xmm1,%xmm0
jne    1162 <matNormalize+0x52>
jnp    118f <matNormalize+0x7f>
movsd  (%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  0x8(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @matNormalize(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = fmul double %5, %5
%7 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %6)
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %7)
%11 = tail call double @sqrt(double %10)
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %22, label %13
13: ; preds = %2
%14 = load double, double* %0
%15 = fdiv double %14, %11
store double %15, double* %1
%16 = load double, double* %4
%17 = fdiv double %16, %11
%18 = getelementptr inbounds double, double* %1, i64 1
store double %17, double* %18
%19 = load double, double* %8
%20 = fdiv double %19, %11
%21 = getelementptr inbounds double, double* %1, i64 2
store double %20, double* %21
br label %22
22: ; preds = %2, %13
%23 = phi i32 [ 0, %13 ], [ -1, %2 ]
ret i32 %23
}