; LLVM IR from VeloxChem/VeloxChem :: src/orbdata/AODensityMatrix.ll (ZNK16CAODensityMatrix11betaDensityEi)

; 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.CAODensityMatrix = type <{ %"class.std::vector", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<CDenseMatrix, std::allocator<CDenseMatrix>>::_Vector_impl" }
%"struct.std::_Vector_base<CDenseMatrix, std::allocator<CDenseMatrix>>::_Vector_impl" = type { %"struct.std::_Vector_base<CDenseMatrix, std::allocator<CDenseMatrix>>::_Vector_impl_data" }
%"struct.std::_Vector_base<CDenseMatrix, std::allocator<CDenseMatrix>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK16CAODensityMatrix13isClosedShellEv(ptr noundef nonnull align 8 dereferenceable(28)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNKSt6vectorI12CDenseMatrixSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK16CAODensityMatrix26getNumberOfDensityMatricesEv(ptr noundef nonnull align 8 dereferenceable(28)) #0 align 2

declare noundef ptr @_ZNK12CDenseMatrix6valuesEv(ptr noundef nonnull align 8 dereferenceable(32)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK16CAODensityMatrix11betaDensityEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = call noundef i32 @_ZNK16CAODensityMatrix26getNumberOfDensityMatricesEv(ptr noundef nonnull align 8 dereferenceable(28) %6)
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %10, label %26

10:                                               ; preds = %2
  %11 = call noundef zeroext i1 @_ZNK16CAODensityMatrix13isClosedShellEv(ptr noundef nonnull align 8 dereferenceable(28) %6)
  br i1 %11, label %12, label %18

12:                                               ; preds = %10
  %13 = getelementptr inbounds %class.CAODensityMatrix, ptr %6, i32 0, i32 0
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNKSt6vectorI12CDenseMatrixSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %13, i64 noundef %15) #3
  %17 = call noundef ptr @_ZNK12CDenseMatrix6valuesEv(ptr noundef nonnull align 8 dereferenceable(32) %16)
  store ptr %17, ptr %3, align 8
  br label %27

18:                                               ; preds = %10
  %19 = getelementptr inbounds %class.CAODensityMatrix, ptr %6, i32 0, i32 0
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = mul nsw i32 2, %20
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNKSt6vectorI12CDenseMatrixSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef %23) #3
  %25 = call noundef ptr @_ZNK12CDenseMatrix6valuesEv(ptr noundef nonnull align 8 dereferenceable(32) %24)
  store ptr %25, ptr %3, align 8
  br label %27

26:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %27

27:                                               ; preds = %26, %18, %12
  %28 = load ptr, ptr %3, align 8
  ret ptr %28
}

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 = { "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}


; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK16CAODensityMatrix13isClosedShellEv(ptr noundef nonnull align 8 dereferenceable(28)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNKSt6vectorI12CDenseMatrixSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

declare noundef ptr @_ZNK12CDenseMatrix6valuesEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK16CAODensityMatrix11betaDensityEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = tail call noundef i32 @_ZNK16CAODensityMatrix26getNumberOfDensityMatricesEv(ptr noundef nonnull align 8 dereferenceable(28) %0)
  %4 = icmp sgt i32 %3, %1
  br i1 %4, label %.sink.split, label %11

.sink.split:                                      ; preds = %2
  %5 = tail call noundef zeroext i1 @_ZNK16CAODensityMatrix13isClosedShellEv(ptr noundef nonnull align 8 dereferenceable(28) %0)
  %6 = shl nsw i32 %1, 1
  %7 = or disjoint i32 %6, 1
  %.sink = select i1 %5, i32 %1, i32 %7
  %8 = sext i32 %.sink to i64
  %9 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNKSt6vectorI12CDenseMatrixSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %8) #3
  %10 = tail call noundef ptr @_ZNK12CDenseMatrix6valuesEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  br label %11

11:                                               ; preds = %.sink.split, %2
  %.0 = phi ptr [ null, %2 ], [ %10, %.sink.split ]
  ret ptr %.0
}

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 = { "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)"}


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