#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 */
int /*<<< orphan*/ crossVectors_double(double const *, double const *,
                                       double *);
int /*<<< orphan*/ mexWarnMsgTxt(char *);
scalar_t__ sqrt(double);
void crossVectorsNorm_double(const double *u, const double *v, double *res) {
  double norm_res;
  crossVectors_double(u, v, res);
  norm_res =
      (double)sqrt((res[0] * res[0] + res[1] * res[1] + res[2] * res[2]));
  if (norm_res == 0) {
    mexWarnMsgTxt("Normal equal to zero! But should be ok.");
  } else {
    res[0] = res[0] / norm_res;
    res[1] = res[1] / norm_res;
    res[2] = res[2] / norm_res;
  }
}


x86 assembly (clang, -O0):
<crossVectorsNorm_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <crossVectors_double@plt>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d1 <crossVectorsNorm_double+0xa1>
jp     11d1 <crossVectorsNorm_double+0xa1>
lea    0xe39(%rip),%rdi
call   1030 <mexWarnMsgTxt@plt>
jmp    1214 <crossVectorsNorm_double+0xe4>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crossVectorsNorm_double>:
push   %rbx
mov    %rdx,%rbx
call   1050 <crossVectors_double@plt>
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
test   %rax,%rax
je     1191 <crossVectorsNorm_double+0x61>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
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
lea    0xe68(%rip),%rdi
pop    %rbx
jmp    1030 <mexWarnMsgTxt@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"Normal equal to zero! But should be ok.\00"
define void @crossVectorsNorm_double(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%8 = load double*, double** %4
%9 = load double*, double** %5
%10 = load double*, double** %6
%11 = call i32 @crossVectors_double(double* %8, double* %9, double* %10)
%12 = load double*, double** %6
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = load double*, double** %6
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
%21 = load double*, double** %6
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = fmul double %20, %23
%25 = call double @llvm.fmuladd.f64(double %14, double %17, double %24)
%26 = load double*, double** %6
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double*, double** %6
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double %25)
%33 = call i64 @sqrt(double %32)
%34 = sitofp i64 %33 to double
store double %34, double* %7
%35 = load double, double* %7
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %3
%38 = call i32 @mexWarnMsgTxt(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %61
39: ; preds = %3
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load double, double* %41
%43 = load double, double* %7
%44 = fdiv double %42, %43
%45 = load double*, double** %6
%46 = getelementptr inbounds double, double* %45, i64 0
store double %44, double* %46
%47 = load double*, double** %6
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = load double, double* %7
%51 = fdiv double %49, %50
%52 = load double*, double** %6
%53 = getelementptr inbounds double, double* %52, i64 1
store double %51, double* %53
%54 = load double*, double** %6
%55 = getelementptr inbounds double, double* %54, i64 2
%56 = load double, double* %55
%57 = load double, double* %7
%58 = fdiv double %56, %57
%59 = load double*, double** %6
%60 = getelementptr inbounds double, double* %59, i64 2
store double %58, double* %60
br label %61
61: ; preds = %39, %37
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"Normal equal to zero! But should be ok.\00"
define void @crossVectorsNorm_double(double* %0, double* %1, double* %2) {
%4 = tail call i32 @crossVectors_double(double* %0, double* %1, double* %2)
%5 = load double, double* %2
%6 = getelementptr inbounds double, double* %2, i64 1
%7 = load double, double* %6
%8 = fmul double %7, %7
%9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
%10 = getelementptr inbounds double, double* %2, i64 2
%11 = load double, double* %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
%13 = tail call i64 @sqrt(double %12)
%14 = sitofp i64 %13 to double
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @mexWarnMsgTxt(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %27
18: ; preds = %3
%19 = bitcast double* %2 to <2 x double>*
%20 = load <2 x double>, <2 x double>* %19
%21 = insertelement <2 x double> poison, double %14, i64 0
%22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
%23 = fdiv <2 x double> %20, %22
%24 = bitcast double* %2 to <2 x double>*
store <2 x double> %23, <2 x double>* %24
%25 = load double, double* %10
%26 = fdiv double %25, %14
store double %26, double* %10
br label %27
27: ; preds = %18, %16
ret void
}