; LLVM IR from NVIDIA/DALI :: dali/pipeline/data/types.ll (ZN4dali6detail17ScatterGatherCopyEPPvPKvPKliiP11CUstream_st)

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

%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease" = type { ptr, %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.14" }
%"struct.std::_Head_base.14" = type { ptr }

@_ZN4dali6detailL16kMaxSizePerBlockE = external hidden constant i64, align 8

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali6detail17ScatterGatherCopyEPPvPKvPKliiP11CUstream_st(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #1 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca %"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease", align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %19 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN4dali6detail25ScatterGatherPoolInstanceEv()
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE3GetIJRKmEEENS5_11ObjectLeaseEP11CUstream_stDpOT_(ptr dead_on_unwind writable sret(%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease") align 8 %13, ptr noundef nonnull align 8 dereferenceable(33) %19, ptr noundef %20, ptr noundef nonnull align 8 dereferenceable(8) @_ZN4dali6detailL16kMaxSizePerBlockE)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %21, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %49, %6
  %23 = load i32, ptr %15, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %56

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i64, ptr %28, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %32, %34
  store i64 %35, ptr %16, align 8, !tbaa !11
  %36 = invoke noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
          to label %37 unwind label %52

37:                                               ; preds = %27
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %38, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load i64, ptr %16, align 8, !tbaa !11
  invoke void @_ZN4dali7kernels17ScatterGatherBase7AddCopyEPvPKvm(ptr noundef nonnull align 8 dereferenceable(32) %36, ptr noundef %42, ptr noundef %43, i64 noundef %44)
          to label %45 unwind label %52

45:                                               ; preds = %37
  %46 = load i64, ptr %16, align 8, !tbaa !11
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 %46
  store ptr %48, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %49

49:                                               ; preds = %45
  %50 = load i32, ptr %15, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %15, align 4, !tbaa !9
  br label %22, !llvm.loop !13

52:                                               ; preds = %37, %27
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %17, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %65

56:                                               ; preds = %26
  %57 = invoke noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
          to label %58 unwind label %61

58:                                               ; preds = %56
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  invoke void @_ZN4dali7kernels16ScatterGatherGPU3RunEP11CUstream_stbNS0_17ScatterGatherBase6MethodE14cudaMemcpyKind(ptr noundef nonnull align 8 dereferenceable(32) %57, ptr noundef %59, i1 noundef zeroext true, i32 noundef 2, i32 noundef 4)
          to label %60 unwind label %61

60:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  ret void

61:                                               ; preds = %58, %56
  %62 = landingpad { ptr, i32 }
          cleanup
  %63 = extractvalue { ptr, i32 } %62, 0
  store ptr %63, ptr %17, align 8
  %64 = extractvalue { ptr, i32 } %62, 1
  store i32 %64, ptr %18, align 4
  br label %65

65:                                               ; preds = %61, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %17, align 8
  %68 = load i32, ptr %18, align 4
  %69 = insertvalue { ptr, i32 } poison, ptr %67, 0
  %70 = insertvalue { ptr, i32 } %69, i32 %68, 1
  resume { ptr, i32 } %70
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(33) ptr @_ZN4dali6detail25ScatterGatherPoolInstanceEv() #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE3GetIJRKmEEENS5_11ObjectLeaseEP11CUstream_stDpOT_(ptr dead_on_unwind noalias writable sret(%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease") align 8, ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali7kernels17ScatterGatherBase7AddCopyEPvPKvm(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef, i64 noundef) #1 align 2

declare void @_ZN4dali7kernels16ScatterGatherGPU3RunEP11CUstream_stbNS0_17ScatterGatherBase6MethodE14cudaMemcpyKind(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i1 noundef zeroext, i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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 = { "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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease" = type { ptr, %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.14" }
%"struct.std::_Head_base.14" = type { ptr }

@_ZN4dali6detailL16kMaxSizePerBlockE = external hidden constant i64, align 8

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4dali6detail17ScatterGatherCopyEPPvPKvPKliiP11CUstream_st(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %7 = alloca %"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %8 = tail call noundef nonnull align 8 dereferenceable(33) ptr @_ZN4dali6detail25ScatterGatherPoolInstanceEv()
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE3GetIJRKmEEENS5_11ObjectLeaseEP11CUstream_stDpOT_(ptr dead_on_unwind nonnull writable sret(%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease") align 8 %7, ptr noundef nonnull align 8 dereferenceable(33) %8, ptr noundef %5, ptr noundef nonnull align 8 dereferenceable(8) @_ZN4dali6detailL16kMaxSizePerBlockE)
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %10 = sext i32 %4 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %12

._crit_edge:                                      ; preds = %19, %6
  %11 = call noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  invoke void @_ZN4dali7kernels16ScatterGatherGPU3RunEP11CUstream_stbNS0_17ScatterGatherBase6MethodE14cudaMemcpyKind(ptr noundef nonnull align 8 dereferenceable(32) %11, ptr noundef %5, i1 noundef zeroext true, i32 noundef 2, i32 noundef 4)
          to label %23 unwind label %24

12:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %.01721 = phi ptr [ %1, %.lr.ph ], [ %20, %19 ]
  %13 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = mul nsw i64 %14, %10
  %16 = call noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %17 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  invoke void @_ZN4dali7kernels17ScatterGatherBase7AddCopyEPvPKvm(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef %18, ptr noundef %.01721, i64 noundef %15)
          to label %19 unwind label %21

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %.01721, i64 %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !11

21:                                               ; preds = %12
  %22 = landingpad { ptr, i32 }
          cleanup
  br label %26

23:                                               ; preds = %._crit_edge
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret void

24:                                               ; preds = %._crit_edge
  %25 = landingpad { ptr, i32 }
          cleanup
  br label %26

26:                                               ; preds = %24, %21
  %.pn = phi { ptr, i32 } [ %22, %21 ], [ %25, %24 ]
  call void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(33) ptr @_ZN4dali6detail25ScatterGatherPoolInstanceEv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE3GetIJRKmEEENS5_11ObjectLeaseEP11CUstream_stDpOT_(ptr dead_on_unwind noalias writable sret(%"class.dali::PerStreamPool<dali::kernels::ScatterGatherGPU, dali::yielding_spinlock<100>>::ObjectLease") align 8, ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali7kernels17ScatterGatherBase7AddCopyEPvPKvm(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

declare void @_ZN4dali7kernels16ScatterGatherGPU3RunEP11CUstream_stbNS0_17ScatterGatherBase6MethodE14cudaMemcpyKind(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i1 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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 = { "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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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