; 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 zeroext i1 @_ZN11LinkedGraph12containsEdgeEii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.LinkedGraph, ptr %11, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %14)
  %16 = icmp slt i32 %12, %15
  br i1 %16, label %17, label %71

17:                                               ; preds = %3
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.LinkedGraph, ptr %11, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %20)
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %71

23:                                               ; preds = %17
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %26, label %71

26:                                               ; preds = %23
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %71

29:                                               ; preds = %26
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = icmp ne i32 %30, %31
  br i1 %32, label %33, label %71

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %34 = getelementptr inbounds %class.LinkedGraph, ptr %11, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = call noundef ptr @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE3getEi(ptr noundef nonnull align 8 dereferenceable(12) %35, i32 noundef %36)
  store ptr %37, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %62, %33
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %40)
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  store i32 2, ptr %10, align 4
  br label %65

44:                                               ; preds = %38
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %45, i32 noundef %46)
  %48 = getelementptr inbounds %class.LinkedGraphEdge, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %60, label %52

52:                                               ; preds = %44
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %53, i32 noundef %54)
  %56 = getelementptr inbounds %class.LinkedGraphEdge, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %52, %44
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %65

61:                                               ; preds = %52
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %9, align 4, !tbaa !9
  br label %38, !llvm.loop !16

65:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %66 = load i32, ptr %10, align 4
  switch i32 %66, label %68 [
    i32 2, label %67
  ]

67:                                               ; preds = %65
  store i32 0, ptr %10, align 4
  br label %68

68:                                               ; preds = %67, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %69 = load i32, ptr %10, align 4
  switch i32 %69, label %74 [
    i32 0, label %70
    i32 1, label %72
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %29, %26, %23, %17, %3
  store i1 false, ptr %4, align 1
  br label %72

72:                                               ; preds = %71, %68
  %73 = load i1, ptr %4, align 1
  ret i1 %73

74:                                               ; preds = %68
  unreachable
}

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 0}
!14 = !{!"_ZTS15LinkedGraphEdge", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!14, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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 zeroext i1 @_ZN11LinkedGraph12containsEdgeEii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %4)
  %6 = icmp sgt i32 %5, %1
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %3
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = tail call noundef i32 @_ZN9ArrayListIP10LinkedListIP15LinkedGraphEdgeEE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(12) %8)
  %10 = icmp sle i32 %9, %2
  %11 = or i32 %2, %1
  %12 = icmp slt i32 %11, 0
  %or.cond3.not30 = or i1 %12, %10
  %.not = icmp eq i32 %1, %2
  %or.cond = or i1 %.not, %or.cond3.not30
  br i1 %or.cond, label %.thread, label %13

13:                                               ; preds = %7
  %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 %1)
  %16 = tail call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %15)
  %.not2631 = icmp sgt i32 %16, 0
  br i1 %.not2631, label %.lr.ph, label %.thread

17:                                               ; preds = %23
  %18 = add nuw nsw i32 %.02232, 1
  %19 = tail call noundef i32 @_ZN10LinkedListIP15LinkedGraphEdgeE7getSizeEv(ptr noundef nonnull align 8 dereferenceable(20) %15)
  %.not26 = icmp slt i32 %18, %19
  br i1 %.not26, label %.lr.ph, label %.thread, !llvm.loop !10

.lr.ph:                                           ; preds = %13, %17
  %.02232 = phi i32 [ %18, %17 ], [ 0, %13 ]
  %20 = tail call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %15, i32 noundef %.02232)
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = icmp eq i32 %21, %2
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %.lr.ph
  %24 = tail call noundef ptr @_ZN10LinkedListIP15LinkedGraphEdgeE3getEi(ptr noundef nonnull align 8 dereferenceable(20) %15, i32 noundef %.02232)
  %25 = getelementptr inbounds i8, ptr %24, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp eq i32 %26, %2
  br i1 %27, label %.thread, label %17

.thread:                                          ; preds = %17, %.lr.ph, %23, %13, %3, %7
  %.1 = phi i1 [ false, %7 ], [ false, %3 ], [ false, %13 ], [ false, %17 ], [ true, %.lr.ph ], [ true, %23 ]
  ret i1 %.1
}

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 0}
!13 = !{!"_ZTS15LinkedGraphEdge", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"int", !8, i64 0}
!15 = !{!13, !14, i64 4}


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