#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*/ fvec_mul_by(float *, long, int);
double fvec_norm(float *, long, double);
double fvec_normalize(float *v, long n, double norm) {
  double nr;
  if (norm == 0) {
    return 0;
  }
  nr = fvec_norm(v, n, norm);
  fvec_mul_by(v, n, 1 / nr);
  return nr;
}


x86 assembly (clang, -O0):
<fvec_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115a <fvec_normalize+0x3a>
jp     115a <fvec_normalize+0x3a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1199 <fvec_normalize+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
call   1030 <fvec_norm@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  0xe7f(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edx
call   1040 <fvec_mul_by@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvec_normalize>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1131 <fvec_normalize+0x11>
jp     1131 <fvec_normalize+0x11>
movapd %xmm1,%xmm0
ret
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <fvec_norm@plt>
movsd  %xmm0,(%rsp)
movsd  0xeb3(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fvec_mul_by@plt>
movsd  (%rsp),%xmm1
add    $0x8,%rsp
pop    %rbx
pop    %r14
movaps %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @fvec_normalize(float* %0, i64 %1, double %2) {
%4 = alloca double
%5 = alloca float*
%6 = alloca i64
%7 = alloca double
%8 = alloca double
store float* %0, float** %5
store i64 %1, i64* %6
store double %2, double* %7
%9 = load double, double* %7
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %3
store double 0.000000e+00, double* %4
br label %24
12: ; preds = %3
%13 = load float*, float** %5
%14 = load i64, i64* %6
%15 = load double, double* %7
%16 = call double @fvec_norm(float* %13, i64 %14, double %15)
store double %16, double* %8
%17 = load float*, float** %5
%18 = load i64, i64* %6
%19 = load double, double* %8
%20 = fdiv double 1.000000e+00, %19
%21 = fptosi double %20 to i32
%22 = call i32 @fvec_mul_by(float* %17, i64 %18, i32 %21)
%23 = load double, double* %8
store double %23, double* %4
br label %24
24: ; preds = %12, %11
%25 = load double, double* %4
ret double %25
}

LLVM IR (-O2):
define double @fvec_normalize(float* %0, i64 %1, double %2) {
%4 = fcmp oeq double %2, 0.000000e+00
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call double @fvec_norm(float* %0, i64 %1, double %2)
%7 = fdiv double 1.000000e+00, %6
%8 = fptosi double %7 to i32
%9 = tail call i32 @fvec_mul_by(float* %0, i64 %1, i32 %8)
br label %10
10: ; preds = %3, %5
%11 = phi double [ %6, %5 ], [ 0.000000e+00, %3 ]
ret double %11
}