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

; 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"

%struct._dsbuffer_t = type { ptr, i64, i64, ptr, i8, ptr, ptr, i64, ptr }

@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [109 x i8], align 1
@__PRETTY_FUNCTION__.dsbuffer_variance = external hidden unnamed_addr constant [38 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local float @dsbuffer_mean(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local float @dsbuffer_variance(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i64, align 8
  %6 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %11

10:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 318, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_variance) #4
  unreachable

11:                                               ; preds = %9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._dsbuffer_t, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  br label %18

17:                                               ; preds = %11
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.2, i32 noundef 319, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_variance) #4
  unreachable

18:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = call float @dsbuffer_mean(ptr noundef %19)
  store float %20, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store float 0.000000e+00, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %41, %18
  %22 = load i64, ptr %5, align 8, !tbaa !15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._dsbuffer_t, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = icmp ult i64 %22, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %44

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._dsbuffer_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i64, ptr %5, align 8, !tbaa !15
  %33 = getelementptr inbounds float, ptr %31, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = load float, ptr %3, align 4, !tbaa !13
  %36 = fsub float %34, %35
  store float %36, ptr %6, align 4, !tbaa !13
  %37 = load float, ptr %6, align 4, !tbaa !13
  %38 = load float, ptr %6, align 4, !tbaa !13
  %39 = load float, ptr %4, align 4, !tbaa !13
  %40 = call float @llvm.fmuladd.f32(float %37, float %38, float %39)
  store float %40, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %41

41:                                               ; preds = %28
  %42 = load i64, ptr %5, align 8, !tbaa !15
  %43 = add i64 %42, 1
  store i64 %43, ptr %5, align 8, !tbaa !15
  br label %21, !llvm.loop !17

44:                                               ; preds = %27
  %45 = load float, ptr %4, align 4, !tbaa !13
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._dsbuffer_t, ptr %46, i32 0, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = sub i64 %48, 1
  %50 = uitofp i64 %49 to float
  %51 = fdiv float %45, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret float %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_dsbuffer_t", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [109 x i8], align 1
@__PRETTY_FUNCTION__.dsbuffer_variance = external hidden unnamed_addr constant [38 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [15 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
declare dso_local float @dsbuffer_mean(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local float @dsbuffer_variance(ptr noundef %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %3

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 318, ptr noundef nonnull @__PRETTY_FUNCTION__.dsbuffer_variance) #3
  unreachable

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ugt i64 %5, 1
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.2, i32 noundef 319, ptr noundef nonnull @__PRETTY_FUNCTION__.dsbuffer_variance) #3
  unreachable

8:                                                ; preds = %3
  %9 = tail call float @dsbuffer_mean(ptr noundef nonnull %0)
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %.not19 = icmp eq i64 %10, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %xtraiter = and i64 %10, 3
  %12 = icmp ult i64 %10, 4
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %21, %.lr.ph
  %.lcssa.ph = phi float [ poison, %.lr.ph ], [ %40, %21 ]
  %.017.unr = phi float [ 0.000000e+00, %.lr.ph ], [ %40, %21 ]
  %.01316.unr = phi i64 [ 0, %.lr.ph ], [ %41, %21 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %.017.epil = phi float [ %16, %.epil.preheader ], [ %.017.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01316.epil = phi i64 [ %17, %.epil.preheader ], [ %.01316.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %13 = getelementptr inbounds float, ptr %11, i64 %.01316.epil
  %14 = load float, ptr %13, align 4, !tbaa !13
  %15 = fsub float %14, %9
  %16 = tail call float @llvm.fmuladd.f32(float %15, float %15, float %.017.epil)
  %17 = add nuw i64 %.01316.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 %.epil.preheader, !llvm.loop !15

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %8
  %.0.lcssa = phi float [ 0.000000e+00, %8 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %16, %.epil.preheader ]
  %18 = add i64 %10, -1
  %19 = uitofp i64 %18 to float
  %20 = fdiv float %.0.lcssa, %19
  ret float %20

21:                                               ; preds = %21, %.lr.ph.new
  %.017 = phi float [ 0.000000e+00, %.lr.ph.new ], [ %40, %21 ]
  %.01316 = phi i64 [ 0, %.lr.ph.new ], [ %41, %21 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %21 ]
  %22 = getelementptr inbounds float, ptr %11, i64 %.01316
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = fsub float %23, %9
  %25 = tail call float @llvm.fmuladd.f32(float %24, float %24, float %.017)
  %26 = or disjoint i64 %.01316, 1
  %27 = getelementptr inbounds float, ptr %11, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !13
  %29 = fsub float %28, %9
  %30 = tail call float @llvm.fmuladd.f32(float %29, float %29, float %25)
  %31 = or disjoint i64 %.01316, 2
  %32 = getelementptr inbounds float, ptr %11, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !13
  %34 = fsub float %33, %9
  %35 = tail call float @llvm.fmuladd.f32(float %34, float %34, float %30)
  %36 = or disjoint i64 %.01316, 3
  %37 = getelementptr inbounds float, ptr %11, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !13
  %39 = fsub float %38, %9
  %40 = tail call float @llvm.fmuladd.f32(float %39, float %39, float %35)
  %41 = add nuw i64 %.01316, 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 %21, !llvm.loop !17
}

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { noreturn 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, !10, i64 8}
!6 = !{!"_dsbuffer_t", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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