; LLVM IR from apache/mxnet :: src (lib_api)

; 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.mxnet::ext::MXTensor" = type <{ ptr, %"class.std::vector.3", i32, [4 x i8], i64, %"struct.mxnet::ext::MXContext", %struct.DLTensor, i32, [4 x i8] }>
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<long, std::allocator<long>>::_Vector_impl" }
%"struct.std::_Vector_base<long, std::allocator<long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long, std::allocator<long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long, std::allocator<long>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.mxnet::ext::MXContext" = type <{ %"class.std::__cxx11::basic_string", i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%struct.DLTensor = type { ptr, %struct.DLContext, i32, %struct.DLDataType, ptr, ptr, i64 }
%struct.DLContext = type { i32, i32 }
%struct.DLDataType = type { i8, i8, i16 }

; 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
declare dso_local void @_ZN5mxnet3ext8MXTensor11setDLTensorEv(ptr noundef nonnull align 8 dereferenceable(140)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5mxnet3ext8MXTensor9setTensorEPvNS0_7MXDTypeEPKlimNS0_9MXContextENS0_13MXStorageTypeE(ptr noundef nonnull align 8 dereferenceable(140) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i64 noundef %5, ptr noundef %6, i32 noundef %7) #1 align 2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i32 %4, ptr %13, align 4, !tbaa !11
  store i64 %5, ptr %14, align 8, !tbaa !13
  store ptr %6, ptr %15, align 8, !tbaa !5
  store i32 %7, ptr %16, align 4, !tbaa !15
  %18 = load ptr, ptr %9, align 8
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 0
  store ptr %19, ptr %20, align 8, !tbaa !17
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 2
  store i32 %21, ptr %22, align 8, !tbaa !31
  %23 = load i64, ptr %14, align 8, !tbaa !13
  %24 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 4
  store i64 %23, ptr %24, align 8, !tbaa !32
  %25 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 5
  %26 = call noundef nonnull align 8 dereferenceable(36) ptr @_ZN5mxnet3ext9MXContextaSERKS1_(ptr noundef nonnull align 8 dereferenceable(36) %25, ptr noundef nonnull align 8 dereferenceable(36) %6)
  %27 = load i32, ptr %16, align 4, !tbaa !15
  %28 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 7
  store i32 %27, ptr %28, align 8, !tbaa !33
  %29 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 1
  call void @_ZNSt6vectorIlSaIlEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %29) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %41, %8
  %31 = load i32, ptr %17, align 4, !tbaa !11
  %32 = load i32, ptr %13, align 4, !tbaa !11
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %44

35:                                               ; preds = %30
  %36 = getelementptr inbounds %"struct.mxnet::ext::MXTensor", ptr %18, i32 0, i32 1
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = load i32, ptr %17, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i64, ptr %37, i64 %39
  call void @_ZNSt6vectorIlSaIlEE9push_backERKl(ptr noundef nonnull align 8 dereferenceable(24) %36, ptr noundef nonnull align 8 dereferenceable(8) %40)
  br label %41

41:                                               ; preds = %35
  %42 = load i32, ptr %17, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %17, align 4, !tbaa !11
  br label %30, !llvm.loop !34

44:                                               ; preds = %34
  call void @_ZN5mxnet3ext8MXTensor11setDLTensorEv(ptr noundef nonnull align 8 dereferenceable(140) %18)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(36) ptr @_ZN5mxnet3ext9MXContextaSERKS1_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(36)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIlSaIlEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIlSaIlEE9push_backERKl(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) #1 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 = { inlinehint 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 #3 = { 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 #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 = !{!"_ZTSN5mxnet3ext7MXDTypeE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTSN5mxnet3ext13MXStorageTypeE", !7, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTSN5mxnet3ext8MXTensorE", !6, i64 0, !19, i64 8, !10, i64 32, !14, i64 40, !23, i64 48, !26, i64 88, !16, i64 136}
!19 = !{!"_ZTSSt6vectorIlSaIlEE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIlSaIlEE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIlSaIlEE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIlSaIlEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!"_ZTSN5mxnet3ext9MXContextE", !24, i64 0, !12, i64 32}
!24 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !25, i64 0, !14, i64 8, !7, i64 16}
!25 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!26 = !{!"_ZTS8DLTensor", !6, i64 0, !27, i64 8, !12, i64 16, !29, i64 20, !6, i64 24, !6, i64 32, !14, i64 40}
!27 = !{!"_ZTS9DLContext", !28, i64 0, !12, i64 4}
!28 = !{!"_ZTS12DLDeviceType", !7, i64 0}
!29 = !{!"_ZTS10DLDataType", !7, i64 0, !7, i64 1, !30, i64 2}
!30 = !{!"short", !7, i64 0}
!31 = !{!18, !10, i64 32}
!32 = !{!18, !14, i64 40}
!33 = !{!18, !16, i64 136}
!34 = distinct !{!34, !35}
!35 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5mxnet3ext8MXTensor11setDLTensorEv(ptr noundef nonnull align 8 dereferenceable(140)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5mxnet3ext8MXTensor9setTensorEPvNS0_7MXDTypeEPKlimNS0_9MXContextENS0_13MXStorageTypeE(ptr noundef nonnull align 8 dereferenceable(140) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i64 noundef %5, ptr noundef nonnull %6, i32 noundef %7) local_unnamed_addr #0 align 2 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %2, ptr %9, align 8, !tbaa !26
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %5, ptr %10, align 8, !tbaa !27
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  %12 = tail call noundef nonnull align 8 dereferenceable(36) ptr @_ZN5mxnet3ext9MXContextaSERKS1_(ptr noundef nonnull align 8 dereferenceable(36) %11, ptr noundef nonnull align 8 dereferenceable(36) %6)
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 %7, ptr %13, align 8, !tbaa !28
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZNSt6vectorIlSaIlEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %14) #3
  %15 = icmp sgt i32 %4, 0
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %8
  tail call void @_ZN5mxnet3ext8MXTensor11setDLTensorEv(ptr noundef nonnull align 8 dereferenceable(140) %0)
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %16 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  tail call void @_ZNSt6vectorIlSaIlEE9push_backERKl(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(8) %16)
  %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 %.lr.ph, !llvm.loop !29
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(36) ptr @_ZN5mxnet3ext9MXContextaSERKS1_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(36)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIlSaIlEE9push_backERKl(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { inlinehint 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN5mxnet3ext8MXTensorE", !7, i64 0, !10, i64 8, !14, i64 32, !15, i64 40, !16, i64 48, !20, i64 88, !25, i64 136}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIlSaIlEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIlSaIlEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIlSaIlEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIlSaIlEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!"_ZTSN5mxnet3ext7MXDTypeE", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTSN5mxnet3ext9MXContextE", !17, i64 0, !19, i64 32}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !15, i64 8, !8, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!19 = !{!"int", !8, i64 0}
!20 = !{!"_ZTS8DLTensor", !7, i64 0, !21, i64 8, !19, i64 16, !23, i64 20, !7, i64 24, !7, i64 32, !15, i64 40}
!21 = !{!"_ZTS9DLContext", !22, i64 0, !19, i64 4}
!22 = !{!"_ZTS12DLDeviceType", !8, i64 0}
!23 = !{!"_ZTS10DLDataType", !8, i64 0, !8, i64 1, !24, i64 2}
!24 = !{!"short", !8, i64 0}
!25 = !{!"_ZTSN5mxnet3ext13MXStorageTypeE", !8, i64 0}
!26 = !{!6, !14, i64 32}
!27 = !{!6, !15, i64 40}
!28 = !{!6, !25, i64 136}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


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