; 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_length = external hidden unnamed_addr constant [36 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
define dso_local float @dsbuffer_length(ptr noundef %0) #3 {
  %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 278, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_length) #5
  unreachable

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

10:                                               ; preds = %32, %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) #6
  br label %35

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 ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._dsbuffer_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load i64, ptr %4, align 8, !tbaa !11
  %28 = getelementptr inbounds float, ptr %26, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !9
  %30 = load float, ptr %3, align 4, !tbaa !9
  %31 = call float @llvm.fmuladd.f32(float %23, float %29, float %30)
  store float %31, ptr %3, align 4, !tbaa !9
  br label %32

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

35:                                               ; preds = %16
  %36 = load float, ptr %3, align 4, !tbaa !9
  %37 = fpext float %36 to double
  %38 = call double @sqrt(double noundef %37) #6
  %39 = fptrunc double %38 to float
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret float %39
}

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

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 = { 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 = !{!"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_length = external hidden unnamed_addr constant [36 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
define dso_local float @dsbuffer_length(ptr noundef readonly %0) local_unnamed_addr #2 {
  %.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
  %.not13 = icmp eq i64 %3, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

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

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

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %11, %.lr.ph
  %.lcssa.ph = phi float [ poison, %.lr.ph ], [ %26, %11 ]
  %.012.unr = phi i64 [ 0, %.lr.ph ], [ %27, %11 ]
  %.0911.unr = phi float [ 0.000000e+00, %.lr.ph ], [ %26, %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
  %.012.epil = phi i64 [ %10, %.epil.preheader ], [ %.012.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0911.epil = phi float [ %9, %.epil.preheader ], [ %.0911.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 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %.0911.epil)
  %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
  %.09.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %.epil.preheader ]
  %sqrtf = tail call float @sqrtf(float noundef %.09.lcssa) #4
  ret float %sqrtf

11:                                               ; preds = %11, %.lr.ph.new
  %.012 = phi i64 [ 0, %.lr.ph.new ], [ %27, %11 ]
  %.0911 = phi float [ 0.000000e+00, %.lr.ph.new ], [ %26, %11 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %11 ]
  %12 = getelementptr inbounds float, ptr %4, i64 %.012
  %13 = load float, ptr %12, align 4, !tbaa !13
  %14 = tail call float @llvm.fmuladd.f32(float %13, float %13, float %.0911)
  %15 = or disjoint i64 %.012, 1
  %16 = getelementptr inbounds float, ptr %4, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !13
  %18 = tail call float @llvm.fmuladd.f32(float %17, float %17, float %14)
  %19 = or disjoint i64 %.012, 2
  %20 = getelementptr inbounds float, ptr %4, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !13
  %22 = tail call float @llvm.fmuladd.f32(float %21, float %21, float %18)
  %23 = or disjoint i64 %.012, 3
  %24 = getelementptr inbounds float, ptr %4, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !13
  %26 = tail call float @llvm.fmuladd.f32(float %25, float %25, float %22)
  %27 = add nuw i64 %.012, 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 %11, !llvm.loop !17
}

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