; LLVM IR from interpretml/interpret :: shared/libebm/Tensor.ll (ZN14NAMESPACE_MAIN6Tensor5ResetEv)

; 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.NAMESPACE_MAIN::Tensor" = type { i64, i64, i64, i64, ptr, i8, [1 x %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo"] }
%"struct.NAMESPACE_MAIN::Tensor::DimensionInfo" = type { 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14NAMESPACE_MAIN6Tensor5ResetEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72) %6)
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %19, %1
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %6, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp ult i64 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %22

14:                                               ; preds = %8
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %15, i64 %16
  %18 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %17, i32 0, i32 0
  store i64 1, ptr %18, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %14
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = add i64 %20, 1
  store i64 %21, ptr %4, align 8, !tbaa !9
  br label %8, !llvm.loop !16

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

23:                                               ; preds = %34, %22
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %6, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %23
  %30 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %6, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  store double 0.000000e+00, ptr %33, align 8, !tbaa !20
  br label %34

34:                                               ; preds = %29
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !9
  br label %23, !llvm.loop !22

37:                                               ; preds = %28
  %38 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %6, i32 0, i32 5
  store i8 0, ptr %38, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

%"struct.NAMESPACE_MAIN::Tensor::DimensionInfo" = type { i64, ptr, i64 }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN14NAMESPACE_MAIN6Tensor5ResetEv(ptr noundef nonnull align 8 dereferenceable(72) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %4, 3
  %5 = icmp ult i64 %4, 4
  br i1 %5, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %4, -4
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %.078.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %20, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil
  %.078.epil = phi i64 [ %7, %.lr.ph.epil ], [ %.078.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %6 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %2, i64 %.078.epil
  store i64 1, ptr %6, align 8, !tbaa !12
  %7 = add nuw i64 %.078.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 %.preheader, label %.lr.ph.epil, !llvm.loop !14

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !16
  %.not11 = icmp eq i64 %9, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph10

.lr.ph10:                                         ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = shl nuw i64 %9, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 %12, i1 false), !tbaa !18
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.078 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %20, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %13 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %2, i64 %.078
  store i64 1, ptr %13, align 8, !tbaa !12
  %14 = or disjoint i64 %.078, 1
  %15 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %2, i64 %14
  store i64 1, ptr %15, align 8, !tbaa !12
  %16 = or disjoint i64 %.078, 2
  %17 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %2, i64 %16
  store i64 1, ptr %17, align 8, !tbaa !12
  %18 = or disjoint i64 %.078, 3
  %19 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %2, i64 %18
  store i64 1, ptr %19, align 8, !tbaa !12
  %20 = add nuw i64 %.078, 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 %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %.lr.ph10, %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 0, ptr %21, align 8, !tbaa !22
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { inlinehint 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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