#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ isnan(float);
int /*<<< orphan*/ printf(char *);
float vectorGetLength(float, float);
void vectorNormalize(float *vxptr, float *vyptr) {
  if (!vxptr || !vyptr || isnan(*vxptr) || isnan(*vyptr)) {
    printf("Cannot normalize invalid vector.\n");
    exit(EXIT_FAILURE);
  }
  float c = vectorGetLength(*vxptr, *vyptr);
  if (c < 0.0000001) {
    *vxptr = 0;
    *vyptr = 0;
  } else {
    *vxptr /= c;
    *vyptr /= c;
  }
}


x86 assembly (clang, -O0):
<vectorNormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <vectorNormalize+0x54>
cmpq   $0x0,-0x10(%rbp)
je     1194 <vectorNormalize+0x54>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
jne    1194 <vectorNormalize+0x54>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
je     11ae <vectorNormalize+0x6e>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
call   1030 <vectorGetLength@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe27(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fe <vectorNormalize+0xbe>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
jmp    1228 <vectorNormalize+0xe8>
movss  -0x14(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0x14(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectorNormalize>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11c1 <vectorNormalize+0x81>
mov    %rsi,%r14
test   %rsi,%rsi
je     11c1 <vectorNormalize+0x81>
mov    %rdi,%rbx
movss  (%rdi),%xmm0
call   1050 <isnan@plt>
test   %rax,%rax
jne    11c1 <vectorNormalize+0x81>
movss  (%r14),%xmm0
call   1050 <isnan@plt>
test   %rax,%rax
jne    11c1 <vectorNormalize+0x81>
movss  (%rbx),%xmm0
movss  (%r14),%xmm1
call   1040 <vectorGetLength@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe72(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    119f <vectorNormalize+0x5f>
movl   $0x0,(%rbx)
xorps  %xmm1,%xmm1
jmp    11b4 <vectorNormalize+0x74>
movss  (%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  (%r14),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Cannot normalize invalid vector.\0A\00"
@EXIT_FAILURE = global i32 0
define void @vectorNormalize(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %3
%7 = icmp ne float* %6, null
br i1 %7, label %8, label %21
8: ; preds = %2
%9 = load float*, float** %4
%10 = icmp ne float* %9, null
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load float*, float** %3
%13 = load float, float* %12
%14 = call i64 @isnan(float %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load float*, float** %4
%18 = load float, float* %17
%19 = call i64 @isnan(float %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16, %11, %8, %2
%22 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = load float*, float** %3
%27 = load float, float* %26
%28 = load float*, float** %4
%29 = load float, float* %28
%30 = call float @vectorGetLength(float %27, float %29)
store float %30, float* %5
%31 = load float, float* %5
%32 = fpext float %31 to double
%33 = fcmp olt double %32, 0x3E7AD7F29ABCAF48
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = load float*, float** %3
store float 0.000000e+00, float* %35
%36 = load float*, float** %4
store float 0.000000e+00, float* %36
br label %46
37: ; preds = %25
%38 = load float, float* %5
%39 = load float*, float** %3
%40 = load float, float* %39
%41 = fdiv float %40, %38
store float %41, float* %39
%42 = load float, float* %5
%43 = load float*, float** %4
%44 = load float, float* %43
%45 = fdiv float %44, %42
store float %45, float* %43
br label %46
46: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [33 x i8] c"Cannot normalize invalid vector.\00"
define void @vectorNormalize(float* %0, float* %1) {
%3 = icmp ne float* %0, null
%4 = icmp ne float* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = load float, float* %0
%8 = tail call i64 @isnan(float %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load float, float* %1
%12 = tail call i64 @isnan(float %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10, %6, %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = load float, float* %0
%20 = load float, float* %1
%21 = tail call float @vectorGetLength(float %19, float %20)
%22 = fpext float %21 to double
%23 = fcmp olt double %22, 0x3E7AD7F29ABCAF48
br i1 %23, label %24, label %25
24: ; preds = %18
store float 0.000000e+00, float* %0
br label %30
25: ; preds = %18
%26 = load float, float* %0
%27 = fdiv float %26, %21
store float %27, float* %0
%28 = load float, float* %1
%29 = fdiv float %28, %21
br label %30
30: ; preds = %25, %24
%31 = phi float [ %29, %25 ], [ 0.000000e+00, %24 ]
store float %31, float* %1
ret void
}