#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*/ assert(double *);
double vectord_length(double *, size_t);
int /*<<< orphan*/ vectord_multiply_inplace(double *, size_t, int);
int /*<<< orphan*/ vectord_remove_mean_inplace(double *, size_t);
void vectord_normalize_to_unit_length_inplace(double *self, size_t size,
                                              bool remove_mean) {
  assert(self);
  if (remove_mean)
    vectord_remove_mean_inplace(self, size);
  double length = vectord_length(self, size);
  vectord_multiply_inplace(self, size, 1 / length);
}


x86 assembly (clang, -O0):
<vectord_normalize_to_unit_length_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
je     1173 <vectord_normalize_to_unit_length_inplace+0x33>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <vectord_remove_mean_inplace@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <vectord_length@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  0xe6b(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edx
call   1030 <vectord_multiply_inplace@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectord_normalize_to_unit_length_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <assert@plt>
test   %ebp,%ebp
je     1160 <vectord_normalize_to_unit_length_inplace+0x20>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <vectord_remove_mean_inplace@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <vectord_length@plt>
movsd  0xe8d(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <vectord_multiply_inplace@plt>

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

LLVM IR (-O2):
define void @vectord_normalize_to_unit_length_inplace(double* %0, i64 %1, i32 %2) {
%4 = tail call i32 @assert(double* %0)
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @vectord_remove_mean_inplace(double* %0, i64 %1)
br label %8
8: ; preds = %6, %3
%9 = tail call double @vectord_length(double* %0, i64 %1)
%10 = fdiv double 1.000000e+00, %9
%11 = fptosi double %10 to i32
%12 = tail call i32 @vectord_multiply_inplace(double* %0, i64 %1, i32 %11)
ret void
}