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

; 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::MXSparse" = type { ptr, i64, ptr, i64, ptr, i64 }

; 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 nounwind uwtable
define dso_local void @_ZN5mxnet3ext8MXSparse3setEPvPKliS2_lS2_l(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) #1 align 2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i64 %5, ptr %14, align 8, !tbaa !11
  store ptr %6, ptr %15, align 8, !tbaa !5
  store i64 %7, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %9, align 8
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 0
  store ptr %19, ptr %20, align 8, !tbaa !13
  %21 = load i64, ptr %14, align 8, !tbaa !11
  %22 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 1
  store i64 %21, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr %15, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %44, label %25

25:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  store i32 1, ptr %17, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %40, %25
  %27 = load i32, ptr %17, align 4, !tbaa !9
  %28 = load i32, ptr %12, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load i32, ptr %17, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i64, ptr %32, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = mul nsw i64 %38, %36
  store i64 %39, ptr %37, align 8, !tbaa !15
  br label %40

40:                                               ; preds = %31
  %41 = load i32, ptr %17, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %17, align 4, !tbaa !9
  br label %26, !llvm.loop !16

43:                                               ; preds = %30
  br label %44

44:                                               ; preds = %43, %8
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 2
  store ptr %45, ptr %46, align 8, !tbaa !18
  %47 = load i64, ptr %14, align 8, !tbaa !11
  %48 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 3
  store i64 %47, ptr %48, align 8, !tbaa !19
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %56

51:                                               ; preds = %44
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 4
  store ptr %52, ptr %53, align 8, !tbaa !20
  %54 = load i64, ptr %16, align 8, !tbaa !11
  %55 = getelementptr inbounds %"struct.mxnet::ext::MXSparse", ptr %18, i32 0, i32 5
  store i64 %54, ptr %55, align 8, !tbaa !21
  br label %56

56:                                               ; preds = %51, %44
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN5mxnet3ext8MXSparseE", !6, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !12, i64 40}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !6, i64 16}
!19 = !{!14, !12, i64 24}
!20 = !{!14, !6, i64 32}
!21 = !{!14, !12, i64 40}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN5mxnet3ext8MXSparse3setEPvPKliS2_lS2_l(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(48) %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) local_unnamed_addr #0 align 2 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %5, ptr %9, align 8, !tbaa !11
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.preheader, label %.critedge

.preheader:                                       ; preds = %8
  %10 = icmp sgt i32 %3, 1
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %3 to i64
  %11 = add nsw i64 %wide.trip.count, -1
  %12 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %11, 3
  %13 = icmp ult i64 %12, 3
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %11, -4
  %invariant.gep = getelementptr inbounds i8, ptr %2, i64 8
  %invariant.gep21 = getelementptr inbounds i8, ptr %2, i64 16
  %invariant.gep23 = getelementptr inbounds i8, ptr %2, i64 24
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %14 = phi i64 [ %5, %.lr.ph.preheader.new ], [ %23, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %15 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = mul nsw i64 %14, %16
  store i64 %17, ptr %9, align 8, !tbaa !11
  %gep = getelementptr inbounds i64, ptr %invariant.gep, i64 %indvars.iv
  %18 = load i64, ptr %gep, align 8, !tbaa !12
  %19 = mul nsw i64 %17, %18
  store i64 %19, ptr %9, align 8, !tbaa !11
  %gep22 = getelementptr inbounds i64, ptr %invariant.gep21, i64 %indvars.iv
  %20 = load i64, ptr %gep22, align 8, !tbaa !12
  %21 = mul nsw i64 %19, %20
  store i64 %21, ptr %9, align 8, !tbaa !11
  %gep24 = getelementptr inbounds i64, ptr %invariant.gep23, i64 %indvars.iv
  %22 = load i64, ptr %gep24, align 8, !tbaa !12
  %23 = mul nsw i64 %21, %22
  store i64 %23, ptr %9, align 8, !tbaa !11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 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 %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %8
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %4, ptr %24, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %5, ptr %25, align 8, !tbaa !16
  br label %._crit_edge

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.unr = phi i64 [ %5, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %26 = phi i64 [ %29, %.lr.ph.epil ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %27 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv.epil
  %28 = load i64, ptr %27, align 8, !tbaa !12
  %29 = mul nsw i64 %26, %28
  store i64 %29, ptr %9, align 8, !tbaa !11
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.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 %.lr.ph.epil, !llvm.loop !17

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader, %.critedge
  %.sink20 = phi i64 [ 32, %.critedge ], [ 16, %.preheader ], [ 16, %.lr.ph.epil ], [ 16, %._crit_edge.loopexit.unr-lcssa ]
  %.sink18 = phi ptr [ %6, %.critedge ], [ %4, %.preheader ], [ %4, %.lr.ph.epil ], [ %4, %._crit_edge.loopexit.unr-lcssa ]
  %.sink17 = phi i64 [ 40, %.critedge ], [ 24, %.preheader ], [ 24, %.lr.ph.epil ], [ 24, %._crit_edge.loopexit.unr-lcssa ]
  %.sink = phi i64 [ %7, %.critedge ], [ %5, %.preheader ], [ %5, %.lr.ph.epil ], [ %5, %._crit_edge.loopexit.unr-lcssa ]
  %30 = getelementptr inbounds i8, ptr %0, i64 %.sink20
  store ptr %.sink18, ptr %30, align 8, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %0, i64 %.sink17
  store i64 %.sink, ptr %31, align 8, !tbaa !12
  ret void
}

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

!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 = !{!"_ZTSN5mxnet3ext8MXSparseE", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !10, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = !{!7, !7, i64 0}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass