; 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_sum = external hidden unnamed_addr constant [33 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_sum(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 269, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_sum) #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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret float %30
}

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_sum = external hidden unnamed_addr constant [33 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_sum(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
  %.not11 = icmp eq i64 %3, 0
  br i1 %.not11, 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 %11

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %11, %.lr.ph
  %.lcssa.ph = phi float [ poison, %.lr.ph ], [ %42, %11 ]
  %.010.unr = phi i64 [ 0, %.lr.ph ], [ %43, %11 ]
  %.079.unr = phi float [ 0.000000e+00, %.lr.ph ], [ %42, %11 ]
  %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
  %.010.epil = phi i64 [ %10, %.epil.preheader ], [ %.010.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.079.epil = phi float [ %9, %.epil.preheader ], [ %.079.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 %.010.epil
  %8 = load float, ptr %7, align 4, !tbaa !13
  %9 = fadd float %.079.epil, %8
  %10 = add nuw i64 %.010.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
  %.07.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %.epil.preheader ]
  ret float %.07.lcssa

11:                                               ; preds = %11, %.lr.ph.new
  %.010 = phi i64 [ 0, %.lr.ph.new ], [ %43, %11 ]
  %.079 = phi float [ 0.000000e+00, %.lr.ph.new ], [ %42, %11 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.7, %11 ]
  %12 = getelementptr inbounds float, ptr %4, i64 %.010
  %13 = load float, ptr %12, align 4, !tbaa !13
  %14 = fadd float %.079, %13
  %15 = or disjoint i64 %.010, 1
  %16 = getelementptr inbounds float, ptr %4, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !13
  %18 = fadd float %14, %17
  %19 = or disjoint i64 %.010, 2
  %20 = getelementptr inbounds float, ptr %4, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !13
  %22 = fadd float %18, %21
  %23 = or disjoint i64 %.010, 3
  %24 = getelementptr inbounds float, ptr %4, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !13
  %26 = fadd float %22, %25
  %27 = or disjoint i64 %.010, 4
  %28 = getelementptr inbounds float, ptr %4, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !13
  %30 = fadd float %26, %29
  %31 = or disjoint i64 %.010, 5
  %32 = getelementptr inbounds float, ptr %4, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !13
  %34 = fadd float %30, %33
  %35 = or disjoint i64 %.010, 6
  %36 = getelementptr inbounds float, ptr %4, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !13
  %38 = fadd float %34, %37
  %39 = or disjoint i64 %.010, 7
  %40 = getelementptr inbounds float, ptr %4, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !13
  %42 = fadd float %38, %41
  %43 = add nuw i64 %.010, 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 %11, !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