#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 */
double doubles_magnitude(double *, int);
void doubles_normalize_self(double *v, int len) {
  double mag = doubles_magnitude(v, len);
  for (int i = 0; i < len; i++)
    v[i] /= mag;
}


x86 assembly (clang, -O0):
<doubles_normalize_self>:
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   1030 <doubles_magnitude@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116c <doubles_normalize_self+0x5c>
movsd  -0x18(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <doubles_normalize_self+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_normalize_self>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <doubles_magnitude@plt>
test   %ebp,%ebp
jle    11b7 <doubles_normalize_self+0xa7>
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    1130 <doubles_normalize_self+0x20>
xor    %ecx,%ecx
jmp    11a0 <doubles_normalize_self+0x90>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rsi
mov    %rsi,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     11be <doubles_normalize_self+0xae>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
nopl   0x0(%rax)
movupd (%rbx,%rsi,8),%xmm2
movupd 0x10(%rbx,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1160 <doubles_normalize_self+0x50>
test   $0x1,%dl
je     119b <doubles_normalize_self+0x8b>
movupd (%rbx,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
cmp    %rax,%rcx
je     11b7 <doubles_normalize_self+0xa7>
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11a0 <doubles_normalize_self+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%dl
jne    118d <doubles_normalize_self+0x7d>
jmp    119b <doubles_normalize_self+0x8b>

LLVM IR (-O0):
define void @doubles_normalize_self(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load double*, double** %3
%8 = load i32, i32* %4
%9 = call double @doubles_magnitude(double* %7, i32 %8)
store double %9, double* %5
store i32 0, i32* %6
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load double, double* %5
%16 = load double*, double** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = fdiv double %20, %15
store double %21, double* %19
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @doubles_normalize_self(double* %0, i32 %1) {
%3 = tail call double @doubles_magnitude(double* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %49
5: ; preds = %2
%6 = zext i32 %1 to i64
%7 = icmp eq i32 %1, 1
br i1 %7, label %47, label %8
8: ; preds = %5
%9 = and i64 %6, 4294967294
%10 = insertelement <2 x double> poison, double %3, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = add nsw i64 %9, -2
%13 = lshr exact i64 %12, 1
%14 = add nuw i64 %13, 1
%15 = and i64 %14, 1
%16 = icmp eq i64 %12, 0
br i1 %16, label %36, label %17
17: ; preds = %8
%18 = and i64 %14, -2
br label %19
19: ; preds = %19, %17
%20 = phi i64 [ 0, %17 ], [ %33, %19 ]
%21 = phi i64 [ 0, %17 ], [ %34, %19 ]
%22 = getelementptr inbounds double, double* %0, i64 %20
%23 = bitcast double* %22 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = fdiv <2 x double> %24, %11
%26 = bitcast double* %22 to <2 x double>*
store <2 x double> %25, <2 x double>* %26
%27 = or i64 %20, 2
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = bitcast double* %28 to <2 x double>*
%30 = load <2 x double>, <2 x double>* %29
%31 = fdiv <2 x double> %30, %11
%32 = bitcast double* %28 to <2 x double>*
store <2 x double> %31, <2 x double>* %32
%33 = add nuw i64 %20, 4
%34 = add nuw i64 %21, 2
%35 = icmp eq i64 %34, %18
br i1 %35, label %36, label %19
36: ; preds = %19, %8
%37 = phi i64 [ 0, %8 ], [ %33, %19 ]
%38 = icmp eq i64 %15, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = getelementptr inbounds double, double* %0, i64 %37
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = fdiv <2 x double> %42, %11
%44 = bitcast double* %40 to <2 x double>*
store <2 x double> %43, <2 x double>* %44
br label %45
45: ; preds = %36, %39
%46 = icmp eq i64 %9, %6
br i1 %46, label %49, label %47
47: ; preds = %5, %45
%48 = phi i64 [ 0, %5 ], [ %9, %45 ]
br label %50
49: ; preds = %50, %45, %2
ret void
50: ; preds = %47, %50
%51 = phi i64 [ %55, %50 ], [ %48, %47 ]
%52 = getelementptr inbounds double, double* %0, i64 %51
%53 = load double, double* %52
%54 = fdiv double %53, %3
store double %54, double* %52
%55 = add nuw nsw i64 %51, 1
%56 = icmp eq i64 %55, %6
br i1 %56, label %49, label %50
}