; 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_mean = external hidden unnamed_addr constant [34 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: nounwind uwtable
define dso_local float @dsbuffer_mean(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %9

8:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 260, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_mean) #3
  unreachable

9:                                                ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store float 0.000000e+00, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %26, %9
  %11 = load i64, ptr %4, align 8, !tbaa !11
  %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 !13
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %29

17:                                               ; preds = %10
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._dsbuffer_t, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = load i64, ptr %4, align 8, !tbaa !11
  %22 = getelementptr inbounds float, ptr %20, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = load float, ptr %3, align 4, !tbaa !9
  %25 = fadd float %24, %23
  store float %25, ptr %3, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %17
  %27 = load i64, ptr %4, align 8, !tbaa !11
  %28 = add i64 %27, 1
  store i64 %28, ptr %4, align 8, !tbaa !11
  br label %10, !llvm.loop !17

29:                                               ; preds = %16
  %30 = load float, ptr %3, align 4, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._dsbuffer_t, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = uitofp i64 %33 to float
  %35 = fdiv float %30, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret float %35
}

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 = { 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 }
attributes #4 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"_dsbuffer_t", !6, i64 0, !12, i64 8, !12, i64 16, !6, i64 24, !15, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !6, i64 64}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!14, !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_mean = external hidden unnamed_addr constant [34 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
define dso_local float @dsbuffer_mean(ptr noundef readonly %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %6, label %.preheader

.preheader:                                       ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not14 = icmp eq i64 %3, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

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

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, -8
  br label %13

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %13, %.lr.ph
  %.lcssa.ph = phi float [ poison, %.lr.ph ], [ %44, %13 ]
  %.012.unr = phi i64 [ 0, %.lr.ph ], [ %45, %13 ]
  %.0811.unr = phi float [ 0.000000e+00, %.lr.ph ], [ %44, %13 ]
  %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
  %.012.epil = phi i64 [ %10, %.epil.preheader ], [ %.012.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0811.epil = phi float [ %9, %.epil.preheader ], [ %.0811.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %7 = getelementptr inbounds float, ptr %4, i64 %.012.epil
  %8 = load float, ptr %7, align 4, !tbaa !13
  %9 = fadd float %.0811.epil, %8
  %10 = add nuw i64 %.012.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, %.preheader
  %.08.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %.epil.preheader ]
  %11 = uitofp i64 %3 to float
  %12 = fdiv float %.08.lcssa, %11
  ret float %12

13:                                               ; preds = %13, %.lr.ph.new
  %.012 = phi i64 [ 0, %.lr.ph.new ], [ %45, %13 ]
  %.0811 = phi float [ 0.000000e+00, %.lr.ph.new ], [ %44, %13 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.7, %13 ]
  %14 = getelementptr inbounds float, ptr %4, i64 %.012
  %15 = load float, ptr %14, align 4, !tbaa !13
  %16 = fadd float %.0811, %15
  %17 = or disjoint i64 %.012, 1
  %18 = getelementptr inbounds float, ptr %4, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = fadd float %16, %19
  %21 = or disjoint i64 %.012, 2
  %22 = getelementptr inbounds float, ptr %4, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = fadd float %20, %23
  %25 = or disjoint i64 %.012, 3
  %26 = getelementptr inbounds float, ptr %4, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !13
  %28 = fadd float %24, %27
  %29 = or disjoint i64 %.012, 4
  %30 = getelementptr inbounds float, ptr %4, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !13
  %32 = fadd float %28, %31
  %33 = or disjoint i64 %.012, 5
  %34 = getelementptr inbounds float, ptr %4, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !13
  %36 = fadd float %32, %35
  %37 = or disjoint i64 %.012, 6
  %38 = getelementptr inbounds float, ptr %4, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !13
  %40 = fadd float %36, %39
  %41 = or disjoint i64 %.012, 7
  %42 = getelementptr inbounds float, ptr %4, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !13
  %44 = fadd float %40, %43
  %45 = add nuw i64 %.012, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %13, !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 = { 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 = { 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,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass