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


x86 assembly (clang, -O0):
<matfNormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bb <matfNormalize+0xab>
jp     11bb <matfNormalize+0xab>
movss  0xe4a(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matfNormalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
cvtss2sd %xmm0,%xmm2
cvtss2sd %xmm1,%xmm1
movss  0x8(%rdi),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm1
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
call   1030 <sqrt@plt>
test   %rax,%rax
je     115c <matfNormalize+0x4c>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
jmp    1164 <matfNormalize+0x54>
movss  0xe9c(%rip),%xmm0
movss  (%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%r14)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @matfNormalize(float* nocapture %0, float* nocapture writeonly %1) {
%3 = load float, float* %0
%4 = fpext float %3 to double
%5 = getelementptr inbounds float, float* %0, i64 1
%6 = load float, float* %5
%7 = fpext float %6 to double
%8 = getelementptr inbounds float, float* %0, i64 2
%9 = load float, float* %8
%10 = fpext float %9 to double
%11 = fmul double %7, %7
%12 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %11)
%13 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %12)
%14 = tail call i64 @sqrt(double %13)
%15 = sitofp i64 %14 to float
%16 = icmp eq i64 %14, 0
%17 = select i1 %16, float 1.000000e+00, float %15
%18 = load float, float* %0
%19 = fdiv float %18, %17
store float %19, float* %1
%20 = load float, float* %5
%21 = fdiv float %20, %17
%22 = getelementptr inbounds float, float* %1, i64 1
store float %21, float* %22
%23 = load float, float* %8
%24 = fdiv float %23, %17
%25 = getelementptr inbounds float, float* %1, i64 2
store float %24, float* %25
ret i32 0
}