#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 */
long double cvector_norm_l(double const *, int);
void cvector_normalize_l(double *vdest, const double *vorg, int n) {
  long double norm_l = cvector_norm_l(vorg, n);
  for (int i = 0; i < n; i++) {
    vdest[i] = vorg[i] / norm_l;
  }
}


x86 assembly (clang, -O0):
<cvector_normalize_l>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <cvector_norm_l@plt>
fstpt  -0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1178 <cvector_normalize_l+0x68>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
fldl   (%rax,%rcx,8)
fldt   -0x30(%rbp)
fdivrp %st,%st(1)
fstpl  -0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1139 <cvector_normalize_l+0x29>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvector_normalize_l>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <cvector_norm_l@plt>
test   %ebp,%ebp
jle    122a <cvector_normalize_l+0x11a>
mov    %ebp,%eax
cmp    $0x4,%ebp
jb     114b <cvector_normalize_l+0x3b>
lea    (%rbx,%rax,8),%rcx
cmp    %r14,%rcx
jbe    1192 <cvector_normalize_l+0x82>
lea    (%r14,%rax,8),%rcx
cmp    %rbx,%rcx
jbe    1192 <cvector_normalize_l+0x82>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
test   $0x1,%al
je     1164 <cvector_normalize_l+0x54>
fld    %st(0)
fdivrl (%rbx,%rcx,8)
fstpl  (%r14,%rcx,8)
or     $0x1,%rcx
add    %rax,%rdx
je     122a <cvector_normalize_l+0x11a>
nopl   (%rax)
fld    %st(0)
fdivrl (%rbx,%rcx,8)
fstpl  (%r14,%rcx,8)
fld    %st(0)
fdivrl 0x8(%rbx,%rcx,8)
fstpl  0x8(%r14,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%rax
jne    1170 <cvector_normalize_l+0x60>
jmp    122a <cvector_normalize_l+0x11a>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    0x0(,%rax,8),%rdx
and    $0xffffffffffffffe0,%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movups (%rbx,%rsi,1),%xmm0
movups 0x10(%rbx,%rsi,1),%xmm1
movhps %xmm0,0x30(%rsp)
movlps %xmm0,0x38(%rsp)
movhps %xmm1,0x20(%rsp)
movlps %xmm1,0x28(%rsp)
fld    %st(0)
fdivrl 0x30(%rsp)
fld    %st(1)
fdivrl 0x38(%rsp)
fld    %st(2)
fdivrl 0x20(%rsp)
fld    %st(3)
fdivrl 0x28(%rsp)
fxch   %st(2)
fstpl  0x18(%rsp)
fxch   %st(2)
fstpl  0x10(%rsp)
movsd  0x18(%rsp),%xmm0
movhps 0x10(%rsp),%xmm0
fstpl  0x8(%rsp)
fstpl  (%rsp)
movsd  0x8(%rsp),%xmm1
movhps (%rsp),%xmm1
movups %xmm0,(%r14,%rsi,1)
movups %xmm1,0x10(%r14,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%rdx
jne    11b0 <cvector_normalize_l+0xa0>
cmp    %rax,%rcx
jne    114d <cvector_normalize_l+0x3d>
fstp   %st(0)
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @cvector_normalize_l(double* nocapture writeonly %0, double* %1, i32 %2) {
%4 = tail call x86_fp80 @cvector_norm_l(double* %1, i32 %2)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %60
6: ; preds = %3
%7 = zext i32 %2 to i64
%8 = icmp ult i32 %2, 4
br i1 %8, label %43, label %9
9: ; preds = %6
%10 = getelementptr double, double* %0, i64 %7
%11 = getelementptr double, double* %1, i64 %7
%12 = icmp ugt double* %11, %0
%13 = icmp ugt double* %10, %1
%14 = and i1 %12, %13
br i1 %14, label %43, label %15
15: ; preds = %9
%16 = and i64 %7, 4294967292
%17 = insertelement <2 x x86_fp80> poison, x86_fp80 %4, i64 0
%18 = shufflevector <2 x x86_fp80> %17, <2 x x86_fp80> poison, <2 x i32> zeroinitializer
%19 = insertelement <2 x x86_fp80> poison, x86_fp80 %4, i64 0
%20 = shufflevector <2 x x86_fp80> %19, <2 x x86_fp80> poison, <2 x i32> zeroinitializer
br label %21
21: ; preds = %21, %15
%22 = phi i64 [ 0, %15 ], [ %39, %21 ]
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = bitcast double* %23 to <2 x double>*
%25 = load <2 x double>, <2 x double>* %24
%26 = getelementptr inbounds double, double* %23, i64 2
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = fpext <2 x double> %25 to <2 x x86_fp80>
%30 = fpext <2 x double> %28 to <2 x x86_fp80>
%31 = fdiv <2 x x86_fp80> %29, %18
%32 = fdiv <2 x x86_fp80> %30, %20
%33 = fptrunc <2 x x86_fp80> %31 to <2 x double>
%34 = fptrunc <2 x x86_fp80> %32 to <2 x double>
%35 = getelementptr inbounds double, double* %0, i64 %22
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> %33, <2 x double>* %36
%37 = getelementptr inbounds double, double* %35, i64 2
%38 = bitcast double* %37 to <2 x double>*
store <2 x double> %34, <2 x double>* %38
%39 = add nuw i64 %22, 4
%40 = icmp eq i64 %39, %16
br i1 %40, label %41, label %21
41: ; preds = %21
%42 = icmp eq i64 %16, %7
br i1 %42, label %60, label %43
43: ; preds = %9, %6, %41
%44 = phi i64 [ 0, %9 ], [ 0, %6 ], [ %16, %41 ]
%45 = xor i64 %44, -1
%46 = and i64 %7, 1
%47 = icmp eq i64 %46, 0
br i1 %47, label %56, label %48
48: ; preds = %43
%49 = getelementptr inbounds double, double* %1, i64 %44
%50 = load double, double* %49
%51 = fpext double %50 to x86_fp80
%52 = fdiv x86_fp80 %51, %4
%53 = fptrunc x86_fp80 %52 to double
%54 = getelementptr inbounds double, double* %0, i64 %44
store double %53, double* %54
%55 = or i64 %44, 1
br label %56
56: ; preds = %48, %43
%57 = phi i64 [ %44, %43 ], [ %55, %48 ]
%58 = sub nsw i64 0, %7
%59 = icmp eq i64 %45, %58
br i1 %59, label %60, label %61
60: ; preds = %56, %61, %41, %3
ret void
61: ; preds = %56, %61
%62 = phi i64 [ %76, %61 ], [ %57, %56 ]
%63 = getelementptr inbounds double, double* %1, i64 %62
%64 = load double, double* %63
%65 = fpext double %64 to x86_fp80
%66 = fdiv x86_fp80 %65, %4
%67 = fptrunc x86_fp80 %66 to double
%68 = getelementptr inbounds double, double* %0, i64 %62
store double %67, double* %68
%69 = add nuw nsw i64 %62, 1
%70 = getelementptr inbounds double, double* %1, i64 %69
%71 = load double, double* %70
%72 = fpext double %71 to x86_fp80
%73 = fdiv x86_fp80 %72, %4
%74 = fptrunc x86_fp80 %73 to double
%75 = getelementptr inbounds double, double* %0, i64 %69
store double %74, double* %75
%76 = add nuw nsw i64 %62, 2
%77 = icmp eq i64 %76, %7
br i1 %77, label %60, label %61
}