; 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
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.dsbuffer_sqrt = external hidden unnamed_addr constant [42 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
declare float @sqrtf(float noundef) #2

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

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 393, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_sqrt) #4
  unreachable

12:                                               ; preds = %10
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %17

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.2, i32 noundef 394, ptr noundef @__PRETTY_FUNCTION__.dsbuffer_sqrt) #4
  unreachable

17:                                               ; preds = %15
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._dsbuffer_t, ptr %18, i32 0, i32 4
  %20 = load i8, ptr %19, align 8, !tbaa !9, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %49

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %23

23:                                               ; preds = %45, %22
  %24 = load i64, ptr %5, align 8, !tbaa !15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._dsbuffer_t, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = icmp ult i64 %24, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %48

30:                                               ; preds = %23
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._dsbuffer_t, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._dsbuffer_t, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !18
  %37 = load i64, ptr %5, align 8, !tbaa !15
  %38 = add i64 %36, %37
  %39 = getelementptr inbounds float, ptr %33, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !19
  %41 = call float @sqrtf(float noundef %40) #5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !15
  %44 = getelementptr inbounds float, ptr %42, i64 %43
  store float %41, ptr %44, align 4, !tbaa !19
  br label %45

45:                                               ; preds = %30
  %46 = load i64, ptr %5, align 8, !tbaa !15
  %47 = add i64 %46, 1
  store i64 %47, ptr %5, align 8, !tbaa !15
  br label %23, !llvm.loop !21

48:                                               ; preds = %29
  br label %83

49:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._dsbuffer_t, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !18
  store i64 %52, ptr %6, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !15
  br label %53

53:                                               ; preds = %79, %49
  %54 = load i64, ptr %7, align 8, !tbaa !15
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._dsbuffer_t, ptr %55, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !16
  %58 = icmp ult i64 %54, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %82

60:                                               ; preds = %53
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._dsbuffer_t, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load i64, ptr %6, align 8, !tbaa !15
  %65 = getelementptr inbounds float, ptr %63, i64 %64
  %66 = load float, ptr %65, align 4, !tbaa !19
  %67 = call float @sqrtf(float noundef %66) #5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i64, ptr %7, align 8, !tbaa !15
  %70 = getelementptr inbounds float, ptr %68, i64 %69
  store float %67, ptr %70, align 4, !tbaa !19
  %71 = load i64, ptr %6, align 8, !tbaa !15
  %72 = add i64 %71, 1
  store i64 %72, ptr %6, align 8, !tbaa !15
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._dsbuffer_t, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !16
  %76 = icmp eq i64 %72, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %60
  store i64 0, ptr %6, align 8, !tbaa !15
  br label %78

78:                                               ; preds = %77, %60
  br label %79

79:                                               ; preds = %78
  %80 = load i64, ptr %7, align 8, !tbaa !15
  %81 = add i64 %80, 1
  store i64 %81, ptr %7, align 8, !tbaa !15
  br label %53, !llvm.loop !23

82:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %83

83:                                               ; preds = %82, %48
  ret void
}

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 "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 = { 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, !12, i64 32}
!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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 8}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !11, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.dsbuffer_sqrt = external hidden unnamed_addr constant [42 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 nofree nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dsbuffer_sqrt(ptr noundef readonly %0, ptr noundef writeonly %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

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

4:                                                ; preds = %2
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.2, i32 noundef 394, ptr noundef nonnull @__PRETTY_FUNCTION__.dsbuffer_sqrt) #3
  unreachable

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load i8, ptr %7, align 8, !tbaa !5, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %.not31 = icmp eq i64 %11, 0
  br i1 %9, label %.preheader, label %24

.preheader:                                       ; preds = %6
  br i1 %.not31, label %.loopexit, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  br label %13

13:                                               ; preds = %.lr.ph29, %13
  %.02128 = phi i64 [ 0, %.lr.ph29 ], [ %21, %13 ]
  %14 = load ptr, ptr %0, align 8, !tbaa !15
  %15 = load i64, ptr %12, align 8, !tbaa !16
  %16 = getelementptr float, ptr %14, i64 %15
  %17 = getelementptr float, ptr %16, i64 %.02128
  %18 = load float, ptr %17, align 4, !tbaa !17
  %19 = tail call float @sqrtf(float noundef %18) #4
  %20 = getelementptr inbounds float, ptr %1, i64 %.02128
  store float %19, ptr %20, align 4, !tbaa !17
  %21 = add nuw i64 %.02128, 1
  %22 = load i64, ptr %10, align 8, !tbaa !14
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %13, label %.loopexit, !llvm.loop !19

24:                                               ; preds = %6
  br i1 %.not31, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %24
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load i64, ptr %25, align 8, !tbaa !16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.027 = phi i64 [ %35, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.02026 = phi i64 [ %spec.store.select, %.lr.ph ], [ %26, %.lr.ph.preheader ]
  %27 = load ptr, ptr %0, align 8, !tbaa !15
  %28 = getelementptr inbounds float, ptr %27, i64 %.02026
  %29 = load float, ptr %28, align 4, !tbaa !17
  %30 = tail call float @sqrtf(float noundef %29) #4
  %31 = getelementptr inbounds float, ptr %1, i64 %.027
  store float %30, ptr %31, align 4, !tbaa !17
  %32 = add i64 %.02026, 1
  %33 = load i64, ptr %10, align 8, !tbaa !14
  %34 = icmp eq i64 %32, %33
  %spec.store.select = select i1 %34, i64 0, i64 %32
  %35 = add nuw i64 %.027, 1
  %36 = icmp ult i64 %35, %33
  br i1 %36, label %.lr.ph, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph, %13, %24, %.preheader
  ret void
}

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 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" }
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, !11, i64 32}
!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 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass