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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #0

declare void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEEC1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

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

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

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

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %25

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

20:                                               ; preds = %14
  call void @_ZN10LinkedListIP15LinkedGraphEdgeED1Ev(ptr noundef nonnull align 8 dereferenceable(20) %18) #6
  call void @_ZdlPvm(ptr noundef %18, i64 noundef 24) #7
  br label %21

21:                                               ; preds = %20, %14
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !13

25:                                               ; preds = %13
  %26 = getelementptr inbounds %class.LinkedGraph, ptr %6, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = icmp eq ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEED1Ev(ptr noundef nonnull align 8 dereferenceable(12) %27) #6
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 16) #7
  br label %30

30:                                               ; preds = %29, %25
  %31 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #8
  invoke void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEEC1Ev(ptr noundef nonnull align 8 dereferenceable(12) %31)
          to label %32 unwind label %34

32:                                               ; preds = %30
  %33 = getelementptr inbounds %class.LinkedGraph, ptr %6, i32 0, i32 0
  store ptr %31, ptr %33, align 8, !tbaa !11
  ret void

34:                                               ; preds = %30
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %4, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %31, i64 noundef 16) #7
  br label %38

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8
  %40 = load i32, ptr %5, align 4
  %41 = insertvalue { ptr, i32 } poison, ptr %39, 0
  %42 = insertvalue { ptr, i32 } %41, i32 %40, 1
  resume { ptr, i32 } %42
}

; Function Attrs: nounwind
declare void @_ZN10LinkedListIP15LinkedGraphEdgeED1Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #5

; Function Attrs: nounwind
declare void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEED1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #5

attributes #0 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind "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 #6 = { nounwind }
attributes #7 = { builtin nounwind }
attributes #8 = { builtin allocsize(0) }

!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

declare void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEEC1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11LinkedGraph5clearEv(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %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 %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %11, %1
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %17, label %16

.lr.ph:                                           ; preds = %1, %11
  %.07 = phi i32 [ %12, %11 ], [ 0, %1 ]
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %7, i32 noundef %.07)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %.lr.ph
  tail call void @_ZN10LinkedListIP15LinkedGraphEdgeED1Ev(ptr noundef nonnull align 8 dereferenceable(20) %8) #5
  tail call void @_ZdlPvm(ptr noundef nonnull %8, i64 noundef 24) #6
  br label %11

11:                                               ; preds = %.lr.ph, %10
  %12 = add nuw nsw i32 %.07, 1
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = tail call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %13)
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !10

16:                                               ; preds = %._crit_edge
  tail call void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEED1Ev(ptr noundef nonnull align 8 dereferenceable(12) %5) #5
  tail call void @_ZdlPvm(ptr noundef nonnull %5, i64 noundef 16) #6
  br label %17

17:                                               ; preds = %16, %._crit_edge
  %18 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #7
  invoke void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEEC1Ev(ptr noundef nonnull align 8 dereferenceable(12) %18)
          to label %19 unwind label %20

19:                                               ; preds = %17
  store ptr %18, ptr %0, align 8, !tbaa !5
  ret void

20:                                               ; preds = %17
  %21 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %18, i64 noundef 16) #6
  resume { ptr, i32 } %21
}

; Function Attrs: nounwind
declare void @_ZN10LinkedListIP15LinkedGraphEdgeED1Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #4

; Function Attrs: nounwind
declare void @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEED1Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #4

attributes #0 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { 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 #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { builtin nounwind }
attributes #7 = { builtin allocsize(0) }

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass