; LLVM IR from herrkaefer/AccelerateWatch :: AccelerateWatch/Classes/acceleratelib (vectord)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.vectord_normalize_to_unit_length = external hidden unnamed_addr constant [79 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local double @vectord_length(ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @vectord_multiply(ptr noundef, i64 noundef, double noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @vectord_remove_mean(ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @vectord_normalize_to_unit_length(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  %13 = zext i1 %2 to i8
  store i8 %13, ptr %7, align 1, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  br label %18

17:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 112, ptr noundef @__PRETTY_FUNCTION__.vectord_normalize_to_unit_length) #5
  unreachable

18:                                               ; preds = %16
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  br label %23

22:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 113, ptr noundef @__PRETTY_FUNCTION__.vectord_normalize_to_unit_length) #5
  unreachable

23:                                               ; preds = %21
  %24 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %72

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vectord_remove_mean(ptr noundef %27, i64 noundef %28, ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store double 0.000000e+00, ptr %9, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %46, %26
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %49

35:                                               ; preds = %30
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %36, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !15
  %44 = load double, ptr %9, align 8, !tbaa !15
  %45 = call double @llvm.fmuladd.f64(double %39, double %43, double %44)
  store double %45, ptr %9, align 8, !tbaa !15
  br label %46

46:                                               ; preds = %35
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %10, align 8, !tbaa !9
  br label %30, !llvm.loop !17

49:                                               ; preds = %34
  %50 = load double, ptr %9, align 8, !tbaa !15
  %51 = call double @sqrt(double noundef %50) #6
  store double %51, ptr %9, align 8, !tbaa !15
  %52 = load double, ptr %9, align 8, !tbaa !15
  %53 = fcmp ogt double %52, 0.000000e+00
  br i1 %53, label %54, label %71

54:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %67, %54
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %70

60:                                               ; preds = %55
  %61 = load double, ptr %9, align 8, !tbaa !15
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = getelementptr inbounds double, ptr %62, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !15
  %66 = fdiv double %65, %61
  store double %66, ptr %64, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %60
  %68 = load i64, ptr %11, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %11, align 8, !tbaa !9
  br label %55, !llvm.loop !19

70:                                               ; preds = %59
  br label %71

71:                                               ; preds = %70, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %89

72:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %6, align 8, !tbaa !9
  %75 = call double @vectord_length(ptr noundef %73, i64 noundef %74)
  store double %75, ptr %12, align 8, !tbaa !15
  %76 = load double, ptr %12, align 8, !tbaa !15
  %77 = fcmp ogt double %76, 0.000000e+00
  br i1 %77, label %78, label %84

78:                                               ; preds = %72
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i64, ptr %6, align 8, !tbaa !9
  %81 = load double, ptr %12, align 8, !tbaa !15
  %82 = fdiv double 1.000000e+00, %81
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vectord_multiply(ptr noundef %79, i64 noundef %80, double noundef %82, ptr noundef %83)
  br label %88

84:                                               ; preds = %72
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %6, align 8, !tbaa !9
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vectord_multiply(ptr noundef %85, i64 noundef %86, double noundef 1.000000e+00, ptr noundef %87)
  br label %88

88:                                               ; preds = %84, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %89

89:                                               ; preds = %88, %71
  ret void
}

attributes #0 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { noreturn nounwind }
attributes #6 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.vectord_normalize_to_unit_length = external hidden unnamed_addr constant [79 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @vectord_length(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @vectord_multiply(ptr noundef, i64 noundef, double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @vectord_remove_mean(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @vectord_normalize_to_unit_length(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 112, ptr noundef nonnull @__PRETTY_FUNCTION__.vectord_normalize_to_unit_length) #4
  unreachable

6:                                                ; preds = %4
  %.not38 = icmp eq ptr %3, null
  br i1 %.not38, label %7, label %8

7:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 113, ptr noundef nonnull @__PRETTY_FUNCTION__.vectord_normalize_to_unit_length) #4
  unreachable

8:                                                ; preds = %6
  br i1 %2, label %9, label %.loopexit.sink.split

9:                                                ; preds = %8
  tail call void @vectord_remove_mean(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %3)
  %.not43 = icmp eq i64 %1, 0
  br i1 %.not43, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %xtraiter = and i64 %1, 3
  %10 = icmp ult i64 %1, 4
  br i1 %10, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %35, %.lr.ph ]
  %.040.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %35, %.lr.ph ]
  %.03239.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %36, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.040.epil = phi double [ %13, %.lr.ph.epil ], [ %.040.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.03239.epil = phi i64 [ %14, %.lr.ph.epil ], [ %.03239.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %11 = getelementptr inbounds double, ptr %3, i64 %.03239.epil
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %.040.epil)
  %14 = add nuw i64 %.03239.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %9
  %.0.lcssa = phi double [ 0.000000e+00, %9 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %13, %.lr.ph.epil ]
  %15 = tail call double @sqrt(double noundef %.0.lcssa) #5
  %16 = fcmp ogt double %15, 0.000000e+00
  %17 = icmp ne i64 %1, 0
  %or.cond = and i1 %16, %17
  br i1 %or.cond, label %.lr.ph42.preheader, label %.loopexit

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %1, 2
  br i1 %min.iters.check, label %.lr.ph42.preheader45, label %vector.ph

.lr.ph42.preheader45:                             ; preds = %middle.block, %.lr.ph42.preheader
  %.03141.ph = phi i64 [ 0, %.lr.ph42.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph42

vector.ph:                                        ; preds = %.lr.ph42.preheader
  %n.vec = and i64 %1, -2
  %broadcast.splatinsert = insertelement <2 x double> poison, double %15, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = getelementptr inbounds double, ptr %3, i64 %index
  %wide.load = load <2 x double>, ptr %18, align 8, !tbaa !5
  %19 = fdiv <2 x double> %wide.load, %broadcast.splat
  store <2 x double> %19, ptr %18, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %1
  br i1 %cmp.n, label %.loopexit, label %.lr.ph42.preheader45

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.040 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %35, %.lr.ph ]
  %.03239 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %36, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %21 = getelementptr inbounds double, ptr %3, i64 %.03239
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %.040)
  %24 = or disjoint i64 %.03239, 1
  %25 = getelementptr inbounds double, ptr %3, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %23)
  %28 = or disjoint i64 %.03239, 2
  %29 = getelementptr inbounds double, ptr %3, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %27)
  %32 = or disjoint i64 %.03239, 3
  %33 = getelementptr inbounds double, ptr %3, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %31)
  %36 = add nuw i64 %.03239, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !15

.lr.ph42:                                         ; preds = %.lr.ph42.preheader45, %.lr.ph42
  %.03141 = phi i64 [ %40, %.lr.ph42 ], [ %.03141.ph, %.lr.ph42.preheader45 ]
  %37 = getelementptr inbounds double, ptr %3, i64 %.03141
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fdiv double %38, %15
  store double %39, ptr %37, align 8, !tbaa !5
  %40 = add nuw i64 %.03141, 1
  %exitcond44.not = icmp eq i64 %40, %1
  br i1 %exitcond44.not, label %.loopexit, label %.lr.ph42, !llvm.loop !16

.loopexit.sink.split:                             ; preds = %8
  %41 = tail call double @vectord_length(ptr noundef nonnull %0, i64 noundef %1)
  %42 = fcmp ogt double %41, 0.000000e+00
  %43 = fdiv double 1.000000e+00, %41
  %.sink = select i1 %42, double %43, double 1.000000e+00
  tail call void @vectord_multiply(ptr noundef nonnull %0, i64 noundef %1, double noundef %.sink, ptr noundef nonnull %3)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph42, %middle.block, %.loopexit.sink.split, %._crit_edge
  ret void
}

attributes #0 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { noreturn nounwind }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12, !14, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass