; LLVM IR from VeloxChem/VeloxChem :: src/math/DenseMatrix.ll (ZN12CDenseMatrix10symmetrizeEv)

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

; 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
define dso_local void @_ZN12CDenseMatrix10symmetrizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %11 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 2
  %12 = call noundef ptr @_ZNSt6vectorIdSaIdEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #2
  store ptr %12, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = icmp eq i32 %14, %16
  br i1 %17, label %18, label %75

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !17
  br label %19

19:                                               ; preds = %71, %18
  %20 = load i32, ptr %4, align 4, !tbaa !17
  %21 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %74

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %26 = load i32, ptr %4, align 4, !tbaa !17
  store i32 %26, ptr %6, align 4, !tbaa !17
  br label %27

27:                                               ; preds = %67, %25
  %28 = load i32, ptr %6, align 4, !tbaa !17
  %29 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %70

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %34 = load i32, ptr %4, align 4, !tbaa !17
  %35 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = mul nsw i32 %34, %36
  %38 = load i32, ptr %6, align 4, !tbaa !17
  %39 = add nsw i32 %37, %38
  store i32 %39, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %40 = load i32, ptr %6, align 4, !tbaa !17
  %41 = getelementptr inbounds %class.CDenseMatrix, ptr %10, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !16
  %43 = mul nsw i32 %40, %42
  %44 = load i32, ptr %4, align 4, !tbaa !17
  %45 = add nsw i32 %43, %44
  store i32 %45, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !17
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !18
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !17
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !18
  %56 = fadd double %50, %55
  store double %56, ptr %9, align 8, !tbaa !18
  %57 = load double, ptr %9, align 8, !tbaa !18
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !17
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %58, i64 %60
  store double %57, ptr %61, align 8, !tbaa !18
  %62 = load double, ptr %9, align 8, !tbaa !18
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !17
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  store double %62, ptr %66, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %67

67:                                               ; preds = %33
  %68 = load i32, ptr %6, align 4, !tbaa !17
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %6, align 4, !tbaa !17
  br label %27, !llvm.loop !20

70:                                               ; preds = %32
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %4, align 4, !tbaa !17
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %4, align 4, !tbaa !17
  br label %19, !llvm.loop !22

74:                                               ; preds = %24
  br label %75

75:                                               ; preds = %74, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNSt6vectorIdSaIdEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) #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 = { 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, !11, i64 0}
!10 = !{!"_ZTS12CDenseMatrix", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIdSaIdEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!10, !11, i64 4}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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
define dso_local void @_ZN12CDenseMatrix10symmetrizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = tail call noundef ptr @_ZNSt6vectorIdSaIdEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !15
  %7 = icmp eq i32 %4, %6
  %8 = icmp sgt i32 %4, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %1
  %9 = zext nneg i32 %4 to i64
  %wide.trip.count27 = zext nneg i32 %4 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %11
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %11 ]
  %10 = mul nuw nsw i64 %indvars.iv, %9
  %invariant.gep = getelementptr inbounds double, ptr %3, i64 %10
  %invariant.gep29 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  br label %12

11:                                               ; preds = %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next, %wide.trip.count27
  br i1 %exitcond28.not, label %.loopexit, label %.preheader, !llvm.loop !16

12:                                               ; preds = %.preheader, %12
  %indvars.iv23 = phi i64 [ %indvars.iv, %.preheader ], [ %indvars.iv.next24, %12 ]
  %13 = mul nuw nsw i64 %indvars.iv23, %9
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv23
  %14 = load double, ptr %gep, align 8, !tbaa !18
  %gep30 = getelementptr inbounds double, ptr %invariant.gep29, i64 %13
  %15 = load double, ptr %gep30, align 8, !tbaa !18
  %16 = fadd double %14, %15
  store double %16, ptr %gep, align 8, !tbaa !18
  store double %16, ptr %gep30, align 8, !tbaa !18
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count27
  br i1 %exitcond.not, label %11, label %12, !llvm.loop !20

.loopexit:                                        ; preds = %11, %1
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNSt6vectorIdSaIdEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) local_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 = { 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, !7, i64 0}
!6 = !{!"_ZTS12CDenseMatrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIdSaIdEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = distinct !{!20, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass