#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(float const *, float const *, float *);
int /*<<< orphan*/ mexWarnMsgTxt(char *);
scalar_t__ sqrt(float);
void crossVectorsNorm(const float *u, const float *v, float *res) {
  float norm_res;
  crossVectors(u, v, res);
  norm_res =
      (float)sqrt((float)(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>:
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   1030 <crossVectors@plt>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1050 <sqrt@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11d0 <crossVectorsNorm+0xa0>
jp     11d0 <crossVectorsNorm+0xa0>
lea    0xe3a(%rip),%rdi
call   1040 <mexWarnMsgTxt@plt>
jmp    1213 <crossVectorsNorm+0xe3>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crossVectorsNorm>:
push   %rbx
mov    %rdx,%rbx
call   1030 <crossVectors@plt>
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rbx),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1050 <sqrt@plt>
test   %rax,%rax
je     1197 <crossVectorsNorm+0x67>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
divss  %xmm0,%xmm2
movss  %xmm2,0x4(%rbx)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%rbx)
pop    %rbx
ret
lea    0xe62(%rip),%rdi
pop    %rbx
jmp    1040 <mexWarnMsgTxt@plt>

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