#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 vlabs(int, double *);
double vlnorm(int l, double v[l]) {
  double norm = vlabs(l, v);
  if (norm != 0.0) {
    for (int i = 0; i < l; i++) {
      v[i] /= norm;
    }
  };
  return norm;
}


x86 assembly (clang, -O0):
<vlnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <vlabs@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114d <vlnorm+0x3d>
jp     114d <vlnorm+0x3d>
jmp    118e <vlnorm+0x7e>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1189 <vlnorm+0x79>
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%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    1154 <vlnorm+0x44>
jmp    118e <vlnorm+0x7e>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlnorm>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <vlabs@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    112d <vlnorm+0x1d>
jnp    11c7 <vlnorm+0xb7>
test   %ebp,%ebp
jle    11c7 <vlnorm+0xb7>
mov    %ebp,%eax
cmp    $0x2,%ebp
jae    1140 <vlnorm+0x30>
xor    %ecx,%ecx
jmp    11b0 <vlnorm+0xa0>
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     11ce <vlnorm+0xbe>
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    1170 <vlnorm+0x60>
test   $0x1,%dl
je     11ab <vlnorm+0x9b>
movupd (%rbx,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
cmp    %rax,%rcx
je     11c7 <vlnorm+0xb7>
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11b0 <vlnorm+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%dl
jne    119d <vlnorm+0x8d>
jmp    11ab <vlnorm+0x9b>

LLVM IR (-O0):
define double @vlnorm(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store double* %1, double** %4
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = load i32, i32* %3
%10 = load double*, double** %4
%11 = call double @vlabs(i32 %9, double* %10)
store double %11, double* %5
%12 = load double, double* %5
%13 = fcmp une double %12, 0.000000e+00
br i1 %13, label %14, label %31
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load double, double* %5
%21 = load double*, double** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = fdiv double %25, %20
store double %26, double* %24
br label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %15
30: ; preds = %15
br label %31
31: ; preds = %30, %2
%32 = load double, double* %5
ret double %32
}

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