; LLVM IR from VAR-solutions/Algorithms :: Graphs/Minimum Spanning Tree/C++/data-structures (LinkedGraph)

; 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.LinkedGraph = type { ptr }
%class.LinkedGraphEdge = type { i32, i32, i32 }

; 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

declare noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12)) #1

declare noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #1

declare noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #1

declare noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11LinkedGraph15totalEdgeMetricEv(ptr noundef nonnull align 8 dereferenceable(8) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %40, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = getelementptr inbounds %class.LinkedGraph, ptr %7, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %11)
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %43

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %36, %15
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.LinkedGraph, ptr %7, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %19, i32 noundef %20)
  %22 = call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %21)
  %23 = icmp slt i32 %17, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %39

25:                                               ; preds = %16
  %26 = getelementptr inbounds %class.LinkedGraph, ptr %7, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %27, i32 noundef %28)
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %29, i32 noundef %30)
  %32 = getelementptr inbounds %class.LinkedGraphEdge, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %3, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %25
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !15

39:                                               ; preds = %24
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !17

43:                                               ; preds = %14
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = ashr i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !9
  %46 = load i32, ptr %3, align 4, !tbaa !9
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %46
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS11LinkedGraph", !6, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS15LinkedGraphEdge", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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"

declare noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #0

declare noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) local_unnamed_addr #0

declare noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #0

declare noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1073741824, 1073741824) i32 @_ZN11LinkedGraph15totalEdgeMetricEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %2)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader, label %._crit_edge16

.preheader:                                       ; preds = %1, %._crit_edge
  %.01015 = phi i32 [ %10, %._crit_edge ], [ 0, %1 ]
  %.01114 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %1 ]
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = tail call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %5, i32 noundef %.01015)
  %7 = tail call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %6)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge16.loopexit:                           ; preds = %._crit_edge
  %9 = ashr i32 %.1.lcssa, 1
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %._crit_edge16.loopexit, %1
  %.011.lcssa = phi i32 [ 0, %1 ], [ %9, %._crit_edge16.loopexit ]
  ret i32 %.011.lcssa

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.1.lcssa = phi i32 [ %.01114, %.preheader ], [ %19, %.lr.ph ]
  %10 = add nuw nsw i32 %.01015, 1
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = tail call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %11)
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %.preheader, label %._crit_edge16.loopexit, !llvm.loop !10

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.013 = phi i32 [ %20, %.lr.ph ], [ 0, %.preheader ]
  %.112 = phi i32 [ %19, %.lr.ph ], [ %.01114, %.preheader ]
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = tail call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %14, i32 noundef %.01015)
  %16 = tail call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %15, i32 noundef %.013)
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = add nsw i32 %18, %.112
  %20 = add nuw nsw i32 %.013, 1
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = tail call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %21, i32 noundef %.01015)
  %23 = tail call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %22)
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

attributes #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" }

!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 = !{!"_ZTS11LinkedGraph", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 8}
!13 = !{!"_ZTS15LinkedGraphEdge", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"int", !8, i64 0}
!15 = distinct !{!15, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass