; LLVM IR from PaddlePaddle/Paddle :: paddle/common/ddim.ll (ZN6common12stride_numelERKNS_4DDimE)

; 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.common::DDim" = type <{ %"class.common::Dim", i32, [4 x i8] }>
%"class.common::Dim" = type { %"class.common::Array" }
%"class.common::Array" = type { [9 x 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 i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76), i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6common12stride_numelERKNS_4DDimE(ptr dead_on_unwind noalias writable sret(%"class.common::DDim") align 8 %0, ptr noundef nonnull align 8 dereferenceable(76) %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @_ZN6common4DDimC1Ev(ptr noundef nonnull align 8 dereferenceable(76) %0)
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %6)
  %8 = getelementptr inbounds %"class.common::DDim", ptr %0, i32 0, i32 1
  store i32 %7, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %9)
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %14)
  %16 = sub nsw i32 %15, 1
  %17 = call noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %13, i32 noundef %16)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %18)
  %20 = sub nsw i32 %19, 1
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %20)
  store i64 %17, ptr %21, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %23)
  %25 = sub nsw i32 %24, 2
  store i32 %25, ptr %5, align 4, !tbaa !16
  br label %26

26:                                               ; preds = %41, %22
  %27 = load i32, ptr %5, align 4, !tbaa !16
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %44

30:                                               ; preds = %26
  %31 = load i32, ptr %5, align 4, !tbaa !16
  %32 = add nsw i32 %31, 1
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %32)
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !16
  %37 = call noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %35, i32 noundef %36)
  %38 = mul nsw i64 %34, %37
  %39 = load i32, ptr %5, align 4, !tbaa !16
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %39)
  store i64 %38, ptr %40, align 8, !tbaa !14
  br label %41

41:                                               ; preds = %30
  %42 = load i32, ptr %5, align 4, !tbaa !16
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %5, align 4, !tbaa !16
  br label %26, !llvm.loop !17

44:                                               ; preds = %29
  ret void
}

declare void @_ZN6common4DDimC1Ev(ptr)

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 = { 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 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, !13, i64 72}
!10 = !{!"_ZTSN6common4DDimE", !11, i64 0, !13, i64 72}
!11 = !{!"_ZTSN6common3DimILi9EEE", !12, i64 0}
!12 = !{!"_ZTSN6common5ArrayIlLm9EEE", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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.common::DDim" = type <{ %"class.common::Dim", i32, [4 x i8] }>
%"class.common::Dim" = type { %"class.common::Array" }
%"class.common::Array" = type { [9 x i64] }

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6common12stride_numelERKNS_4DDimE(ptr dead_on_unwind noalias writable sret(%"class.common::DDim") align 8 %0, ptr noundef nonnull align 8 dereferenceable(76) %1) local_unnamed_addr #2 {
  tail call void @_ZN6common4DDimC1Ev(ptr noundef nonnull align 8 dereferenceable(76) %0)
  %3 = tail call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %3, ptr %4, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %14

7:                                                ; preds = %2
  %8 = tail call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  %9 = add nsw i32 %8, -1
  %10 = tail call noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %1, i32 noundef %9)
  %11 = tail call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  %12 = add nsw i32 %11, -1
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %12)
  store i64 %10, ptr %13, align 8, !tbaa !12
  br label %14

14:                                               ; preds = %7, %2
  %15 = tail call noundef i32 @_ZNK6common4DDim4sizeEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  %16 = icmp sgt i32 %15, 1
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %14
  %17 = add nsw i32 %15, -2
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %14
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.011 = phi i32 [ %24, %.lr.ph ], [ %17, %.lr.ph.preheader ]
  %18 = add nuw nsw i32 %.011, 1
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %18)
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = tail call noundef i64 @_ZNK6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %1, i32 noundef %.011)
  %22 = mul nsw i64 %21, %20
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN6common4DDimixEi(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %.011)
  store i64 %22, ptr %23, align 8, !tbaa !12
  %24 = add nsw i32 %.011, -1
  %.not = icmp eq i32 %.011, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14
}

declare void @_ZN6common4DDimC1Ev(ptr) local_unnamed_addr

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 = { 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 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, !11, i64 72}
!6 = !{!"_ZTSN6common4DDimE", !7, i64 0, !11, i64 72}
!7 = !{!"_ZTSN6common3DimILi9EEE", !8, i64 0}
!8 = !{!"_ZTSN6common5ArrayIlLm9EEE", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass