; LLVM IR from INMOST-DEV/INMOST-FEM :: anifem++/fem/tetdofmap.ll (ZN3Ani4DofT12VectorDofMap12GetSubDofMapEPKii)

; 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.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"struct.Ani::DofT::VectorDofMap" = type <{ %"struct.Ani::DofT::BaseDofMap", %"class.std::shared_ptr", i32, [4 x i8] }>
%"struct.Ani::DofT::BaseDofMap" = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Ani4DofT12VectorDofMap12GetSubDofMapEPKii(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(28) %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %9 = load ptr, ptr %6, align 8
  %10 = load i32, ptr %8, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %38

12:                                               ; preds = %4
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %38

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = getelementptr inbounds %"struct.Ani::DofT::VectorDofMap", ptr %9, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %22, label %38

22:                                               ; preds = %16
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = getelementptr inbounds %"struct.Ani::DofT::VectorDofMap", ptr %9, i32 0, i32 1
  call void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %26) #2
  br label %37

27:                                               ; preds = %22
  %28 = getelementptr inbounds %"struct.Ani::DofT::VectorDofMap", ptr %9, i32 0, i32 1
  %29 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %28) #2
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds i32, ptr %30, i64 1
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 1
  %34 = load ptr, ptr %29, align 8, !tbaa !17
  %35 = getelementptr inbounds ptr, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8
  call void %36(ptr dead_on_unwind writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %31, i32 noundef %33)
  br label %37

37:                                               ; preds = %27, %25
  br label %39

38:                                               ; preds = %16, %12, %4
  call void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr null) #2
  br label %39

39:                                               ; preds = %38, %37
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16), ptr) unnamed_addr #0 align 2

attributes #0 = { 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 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, !10, i64 24}
!12 = !{!"_ZTSN3Ani4DofT12VectorDofMapE", !13, i64 0, !14, i64 8, !10, i64 24}
!13 = !{!"_ZTSN3Ani4DofT10BaseDofMapE"}
!14 = !{!"_ZTSSt10shared_ptrIN3Ani4DofT10BaseDofMapEE", !15, i64 0}
!15 = !{!"_ZTSSt12__shared_ptrIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !16, i64 8}
!16 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}


; 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.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3Ani4DofT12VectorDofMap12GetSubDofMapEPKii(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(28) %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %6, label %23

6:                                                ; preds = %4
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, -1
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load i32, ptr %9, align 8
  %11 = icmp slt i32 %7, %10
  %or.cond = select i1 %8, i1 %11, i1 false
  br i1 %or.cond, label %12, label %23

12:                                               ; preds = %6
  %13 = icmp eq i32 %3, 1
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  br i1 %13, label %15, label %16

15:                                               ; preds = %12
  tail call void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %14) #2
  br label %24

16:                                               ; preds = %12
  %17 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %14) #2
  %18 = getelementptr inbounds i8, ptr %2, i64 4
  %19 = add nsw i32 %3, -1
  %20 = load ptr, ptr %17, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %20, i64 128
  %22 = load ptr, ptr %21, align 8
  tail call void %22(ptr dead_on_unwind writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull %18, i32 noundef %19)
  br label %24

23:                                               ; preds = %6, %4
  tail call void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr null) #2
  br label %24

24:                                               ; preds = %15, %16, %23
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN3Ani4DofT10BaseDofMapEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16), ptr) unnamed_addr #0 align 2

attributes #0 = { 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass