; LLVM IR from NVIDIA/DALI :: dali/pipeline/data/types.ll (ZN4dali6detail17ScatterGatherCopyEPPvPPKvPKliiP11CUstream_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 @_ZN4dali6detail17ScatterGatherCopyEPPvPPKvPKliiP11CUstream_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 i32, align 4
  %15 = alloca ptr, align 8
  %16 = 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
  %17 = call noundef nonnull align 8 dereferenceable(33) ptr @_ZN4dali6detail25ScatterGatherPoolInstanceEv()
  %18 = 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) %17, ptr noundef %18, ptr noundef nonnull align 8 dereferenceable(8) @_ZN4dali6detailL16kMaxSizePerBlockE)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %46, %6
  %20 = load i32, ptr %14, align 4, !tbaa !9
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %53

24:                                               ; preds = %19
  %25 = invoke noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
          to label %26 unwind label %49

26:                                               ; preds = %24
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i32, ptr %14, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i64, ptr %37, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %41, %43
  invoke void @_ZN4dali7kernels17ScatterGatherBase7AddCopyEPvPKvm(ptr noundef nonnull align 8 dereferenceable(32) %25, ptr noundef %31, ptr noundef %36, i64 noundef %44)
          to label %45 unwind label %49

45:                                               ; preds = %26
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %14, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %14, align 4, !tbaa !9
  br label %19, !llvm.loop !13

49:                                               ; preds = %26, %24
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %15, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %62

53:                                               ; preds = %23
  %54 = invoke noundef ptr @_ZNK4dali13PerStreamPoolINS_7kernels16ScatterGatherGPUENS_17yielding_spinlockILi100EEELb1EE11ObjectLeaseptEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
          to label %55 unwind label %58

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

57:                                               ; preds = %55
  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

58:                                               ; preds = %55, %53
  %59 = landingpad { ptr, i32 }
          cleanup
  %60 = extractvalue { ptr, i32 } %59, 0
  store ptr %60, ptr %15, align 8
  %61 = extractvalue { ptr, i32 } %59, 1
  store i32 %61, ptr %16, align 4
  br label %62

62:                                               ; preds = %58, %49
  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 %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %15, align 8
  %65 = load i32, ptr %16, align 4
  %66 = insertvalue { ptr, i32 } poison, ptr %64, 0
  %67 = insertvalue { ptr, i32 } %66, i32 %65, 1
  resume { ptr, i32 } %67
}

; 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 @_ZN4dali6detail17ScatterGatherCopyEPPvPPKvPKliiP11CUstream_st(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %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 = %21, %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 %24 unwind label %25

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

21:                                               ; preds = %12
  %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

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

24:                                               ; 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

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

27:                                               ; preds = %25, %22
  %.pn = phi { ptr, i32 } [ %23, %22 ], [ %26, %25 ]
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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