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

; 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__.vectorf_normalize_to_unit_length = external hidden unnamed_addr constant [77 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 float @vectorf_length(ptr noundef, i64 noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @vectorf_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 float, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca float, align 4
  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__.vectorf_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__.vectorf_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 %74

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 @vectorf_remove_mean(ptr noundef %27, i64 noundef %28, ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store float 0.000000e+00, ptr %9, align 4, !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 float, ptr %36, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !15
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds float, ptr %40, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !15
  %44 = load float, ptr %9, align 4, !tbaa !15
  %45 = call float @llvm.fmuladd.f32(float %39, float %43, float %44)
  store float %45, ptr %9, align 4, !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 float, ptr %9, align 4, !tbaa !15
  %51 = fpext float %50 to double
  %52 = call double @sqrt(double noundef %51) #6
  %53 = fptrunc double %52 to float
  store float %53, ptr %9, align 4, !tbaa !15
  %54 = load float, ptr %9, align 4, !tbaa !15
  %55 = fcmp ogt float %54, 0.000000e+00
  br i1 %55, label %56, label %73

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

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

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

62:                                               ; preds = %57
  %63 = load float, ptr %9, align 4, !tbaa !15
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = getelementptr inbounds float, ptr %64, i64 %65
  %67 = load float, ptr %66, align 4, !tbaa !15
  %68 = fdiv float %67, %63
  store float %68, ptr %66, align 4, !tbaa !15
  br label %69

69:                                               ; preds = %62
  %70 = load i64, ptr %11, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %11, align 8, !tbaa !9
  br label %57, !llvm.loop !19

72:                                               ; preds = %61
  br label %73

73:                                               ; preds = %72, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %91

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

80:                                               ; preds = %74
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = load float, ptr %12, align 4, !tbaa !15
  %84 = fdiv float 1.000000e+00, %83
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vectorf_multiply(ptr noundef %81, i64 noundef %82, float noundef %84, ptr noundef %85)
  br label %90

86:                                               ; preds = %74
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load i64, ptr %6, align 8, !tbaa !9
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  call void @vectorf_multiply(ptr noundef %87, i64 noundef %88, float noundef 1.000000e+00, ptr noundef %89)
  br label %90

90:                                               ; preds = %86, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %91

91:                                               ; preds = %90, %73
  ret void
}

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

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 = !{!"float", !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__.vectorf_normalize_to_unit_length = external hidden unnamed_addr constant [77 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 float @vectorf_length(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @vectorf_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__.vectorf_normalize_to_unit_length) #3
  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__.vectorf_normalize_to_unit_length) #3
  unreachable

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

9:                                                ; preds = %8
  tail call void @vectorf_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 float [ poison, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %.040.unr = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %.03239.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %35, %.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 float [ %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 float, ptr %3, i64 %.03239.epil
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %.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 float [ 0.000000e+00, %9 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %13, %.lr.ph.epil ]
  %sqrtf = tail call float @sqrtf(float noundef %.0.lcssa) #4
  %15 = fcmp ogt float %sqrtf, 0.000000e+00
  %16 = icmp ne i64 %1, 0
  %or.cond = and i1 %15, %16
  br i1 %or.cond, label %.lr.ph42.preheader, label %.loopexit

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %1, 4
  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, -4
  %broadcast.splatinsert = insertelement <4 x float> poison, float %sqrtf, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = getelementptr inbounds float, ptr %3, i64 %index
  %wide.load = load <4 x float>, ptr %17, align 4, !tbaa !5
  %18 = fdiv <4 x float> %wide.load, %broadcast.splat
  store <4 x float> %18, ptr %17, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, 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 float [ 0.000000e+00, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %.03239 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %35, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %20 = getelementptr inbounds float, ptr %3, i64 %.03239
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = tail call float @llvm.fmuladd.f32(float %21, float %21, float %.040)
  %23 = or disjoint i64 %.03239, 1
  %24 = getelementptr inbounds float, ptr %3, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !5
  %26 = tail call float @llvm.fmuladd.f32(float %25, float %25, float %22)
  %27 = or disjoint i64 %.03239, 2
  %28 = getelementptr inbounds float, ptr %3, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = tail call float @llvm.fmuladd.f32(float %29, float %29, float %26)
  %31 = or disjoint i64 %.03239, 3
  %32 = getelementptr inbounds float, ptr %3, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = tail call float @llvm.fmuladd.f32(float %33, float %33, float %30)
  %35 = 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 [ %39, %.lr.ph42 ], [ %.03141.ph, %.lr.ph42.preheader45 ]
  %36 = getelementptr inbounds float, ptr %3, i64 %.03141
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = fdiv float %37, %sqrtf
  store float %38, ptr %36, align 4, !tbaa !5
  %39 = add nuw i64 %.03141, 1
  %exitcond44.not = icmp eq i64 %39, %1
  br i1 %exitcond44.not, label %.loopexit, label %.lr.ph42, !llvm.loop !16

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

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

declare float @sqrtf(float) local_unnamed_addr

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 = { noreturn nounwind }
attributes #4 = { 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" }

!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 = !{!"float", !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