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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3Ani14VectorFemSpace8subSpaceEPKii(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr.21") align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef %2, i32 noundef %3) unnamed_addr #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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
  %11 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %12 = getelementptr inbounds %"struct.Ani::BaseFemSpace", ptr %11, i32 0, i32 1
  %13 = call noundef ptr @_ZNK3Ani4DofT6DofMap6targetINS0_12VectorDofMapEEEPKT_v(ptr noundef nonnull align 8 dereferenceable(16) %12)
  %14 = getelementptr inbounds %"struct.Ani::DofT::VectorDofMap", ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !11
  store i32 %15, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp sge i32 %16, 1
  br i1 %17, label %18, label %45

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %19, i64 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %45

24:                                               ; preds = %18
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds i32, ptr %25, i64 0
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %45

29:                                               ; preds = %24
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = getelementptr inbounds %"struct.Ani::VectorFemSpace", ptr %11, i32 0, i32 1
  call void @_ZNSt10shared_ptrIN3Ani12BaseFemSpaceEEC2ERKS2_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %33) #3
  br label %44

34:                                               ; preds = %29
  %35 = getelementptr inbounds %"struct.Ani::VectorFemSpace", ptr %11, i32 0, i32 1
  %36 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3Ani12BaseFemSpaceELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %35) #3
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i32, ptr %37, i64 1
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = load ptr, ptr %36, align 8, !tbaa !17
  %42 = getelementptr inbounds ptr, ptr %41, i64 24
  %43 = load ptr, ptr %42, align 8
  call void %43(ptr dead_on_unwind writable sret(%"class.std::shared_ptr.21") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %36, ptr noundef %38, i32 noundef %40)
  br label %44

44:                                               ; preds = %34, %32
  store i32 1, ptr %10, align 4
  br label %46

45:                                               ; preds = %24, %18, %4
  call void @_ZNSt10shared_ptrIN3Ani12BaseFemSpaceEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr null) #3
  store i32 1, ptr %10, align 4
  br label %46

46:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

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

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

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 = { 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 = !{!"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.21" = type { %"class.std::__shared_ptr.22" }
%"class.std::__shared_ptr.22" = 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_accessIN3Ani12BaseFemSpaceELN9__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 @_ZNK3Ani14VectorFemSpace8subSpaceEPKii(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr.21") align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = tail call noundef ptr @_ZNK3Ani4DofT6DofMap6targetINS0_12VectorDofMapEEEPKT_v(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %8, label %25

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

14:                                               ; preds = %8
  %15 = icmp eq i32 %3, 1
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  br i1 %15, label %17, label %18

17:                                               ; preds = %14
  tail call void @_ZNSt10shared_ptrIN3Ani12BaseFemSpaceEEC2ERKS2_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %16) #2
  br label %26

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

25:                                               ; preds = %8, %4
  tail call void @_ZNSt10shared_ptrIN3Ani12BaseFemSpaceEEC2EDn(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr null) #2
  br label %26

26:                                               ; preds = %17, %18, %25
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN3Ani12BaseFemSpaceEEC2ERKS2_(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_ptrIN3Ani12BaseFemSpaceEEC2EDn(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, !14, i64 24}
!6 = !{!"_ZTSN3Ani4DofT12VectorDofMapE", !7, i64 0, !8, i64 8, !14, i64 24}
!7 = !{!"_ZTSN3Ani4DofT10BaseDofMapE"}
!8 = !{!"_ZTSSt10shared_ptrIN3Ani4DofT10BaseDofMapEE", !9, i64 0}
!9 = !{!"_ZTSSt12__shared_ptrIN3Ani4DofT10BaseDofMapELN9__gnu_cxx12_Lock_policyE2EE", !10, i64 0, !13, i64 8}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !10, i64 0}
!14 = !{!"int", !11, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !12, i64 0}


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