#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 */
typedef int /*<<< orphan*/ uint;

/* Variables and functions */
int /*<<< orphan*/ imul_vn_fl(double *, double, int /*<<< orphan*/ const);
double len_squared_vn(double *, int /*<<< orphan*/ const);
double sqrt(double);
double normalize_vn(double v0[], const uint dims) {
  double d = len_squared_vn(v0, dims);
  if (d != 0.0 && ((d = sqrt(d)) != 0.0)) {
    imul_vn_fl(v0, 1.0 / d, dims);
  }
  return d;
}


x86 assembly (clang, -O0):
<normalize_vn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <len_squared_vn@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116d <normalize_vn+0x3d>
jp     116d <normalize_vn+0x3d>
jmp    11ad <normalize_vn+0x7d>
movsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1194 <normalize_vn+0x64>
jp     1194 <normalize_vn+0x64>
jmp    11ad <normalize_vn+0x7d>
mov    -0x8(%rbp),%rdi
movsd  0xe60(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%esi
call   1030 <imul_vn_fl@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_vn>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <len_squared_vn@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114d <normalize_vn+0x1d>
jnp    118e <normalize_vn+0x5e>
jb     1155 <normalize_vn+0x25>
sqrtsd %xmm1,%xmm1
jmp    1162 <normalize_vn+0x32>
movapd %xmm1,%xmm0
call   1050 <sqrt@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    116e <normalize_vn+0x3e>
jnp    118e <normalize_vn+0x5e>
movsd  0xe8a(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %rbx,%rdi
mov    %ebp,%esi
movsd  %xmm1,(%rsp)
call   1030 <imul_vn_fl@plt>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @normalize_vn(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%6 = load double*, double** %3
%7 = load i32, i32* %4
%8 = call double @len_squared_vn(double* %6, i32 %7)
store double %8, double* %5
%9 = load double, double* %5
%10 = fcmp une double %9, 0.000000e+00
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load double, double* %5
%13 = call double @sqrt(double %12)
store double %13, double* %5
%14 = fcmp une double %13, 0.000000e+00
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load double*, double** %3
%17 = load double, double* %5
%18 = fdiv double 1.000000e+00, %17
%19 = load i32, i32* %4
%20 = call i32 @imul_vn_fl(double* %16, double %18, i32 %19)
br label %21
21: ; preds = %15, %11, %2
%22 = load double, double* %5
ret double %22
}

LLVM IR (-O2):
define double @normalize_vn(double* %0, i32 %1) {
%3 = tail call double @len_squared_vn(double* %0, i32 %1)
%4 = fcmp une double %3, 0.000000e+00
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call double @sqrt(double %3)
%7 = fcmp une double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = fdiv double 1.000000e+00, %6
%10 = tail call i32 @imul_vn_fl(double* %0, double %9, i32 %1)
br label %11
11: ; preds = %8, %5, %2
%12 = phi double [ %6, %8 ], [ %6, %5 ], [ %3, %2 ]
ret double %12
}