; LLVM IR from AllAlgorithms/c :: algorithms/graphs (kruskals)

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

%struct.edge = type { i32, i32, i32 }
%struct.ufds = type { ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @edge_comp(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @ufds_init(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @in_same_set(i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @union_set(i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @ufds_destroy(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @kruskals(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = call ptr @ufds_init(i32 noundef %11)
  store ptr %12, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  call void @qsort(ptr noundef %13, i64 noundef %15, i64 noundef 12, ptr noundef @edge_comp)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %61, %2
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %9, align 4
  br label %64

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.edge, ptr %22, i64 %24
  store ptr %25, ptr %10, align 8, !tbaa !9
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.edge, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load ptr, ptr %10, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.edge, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = call i32 @in_same_set(i32 noundef %28, i32 noundef %31, ptr noundef %32)
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %49, label %35

35:                                               ; preds = %21
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.edge, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr %7, align 4, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.edge, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = load ptr, ptr %10, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.edge, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = call i32 @union_set(i32 noundef %43, i32 noundef %46, ptr noundef %47)
  br label %49

49:                                               ; preds = %35, %21
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.ufds, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !15
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %57

54:                                               ; preds = %49
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  call void @ufds_destroy(ptr noundef %55)
  %56 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %56, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %58

57:                                               ; preds = %49
  store i32 0, ptr %9, align 4
  br label %58

58:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %59 = load i32, ptr %9, align 4
  switch i32 %59, label %64 [
    i32 0, label %60
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %8, align 4, !tbaa !5
  br label %16, !llvm.loop !17

64:                                               ; preds = %58, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %65 = load i32, ptr %9, align 4
  switch i32 %65, label %69 [
    i32 2, label %66
  ]

66:                                               ; preds = %64
  %67 = load ptr, ptr %6, align 8, !tbaa !9
  call void @ufds_destroy(ptr noundef %67)
  %68 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %68, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %66, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 24}
!16 = !{!"ufds", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.edge = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @edge_comp(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @ufds_init(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @in_same_set(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @union_set(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @ufds_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @kruskals(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @ufds_init(i32 noundef %0)
  %4 = sext i32 %0 to i64
  tail call void @qsort(ptr noundef %1, i64 noundef %4, i64 noundef 12, ptr noundef nonnull @edge_comp) #2
  %.not3137 = icmp sgt i32 %0, 0
  br i1 %.not3137, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %3, i64 24
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %7

6:                                                ; preds = %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %7, !llvm.loop !5

7:                                                ; preds = %.lr.ph, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %6 ]
  %.02738 = phi i32 [ 0, %.lr.ph ], [ %.128, %6 ]
  %8 = getelementptr inbounds %struct.edge, ptr %1, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !7
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = tail call i32 @in_same_set(i32 noundef %9, i32 noundef %11, ptr noundef %3)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %20

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = add nsw i32 %15, %.02738
  %17 = load i32, ptr %8, align 4, !tbaa !7
  %18 = load i32, ptr %10, align 4, !tbaa !12
  %19 = tail call i32 @union_set(i32 noundef %17, i32 noundef %18, ptr noundef %3)
  br label %20

20:                                               ; preds = %13, %7
  %.128 = phi i32 [ %.02738, %7 ], [ %16, %13 ]
  %21 = load i32, ptr %5, align 8, !tbaa !14
  %.not30 = icmp eq i32 %21, 1
  br i1 %.not30, label %.thread33, label %6

.thread33:                                        ; preds = %20
  tail call void @ufds_destroy(ptr noundef nonnull %3)
  br label %22

._crit_edge:                                      ; preds = %6, %2
  %.027.lcssa = phi i32 [ 0, %2 ], [ %.128, %6 ]
  tail call void @ufds_destroy(ptr noundef %3)
  br label %22

22:                                               ; preds = %.thread33, %._crit_edge
  %.3 = phi i32 [ %.027.lcssa, %._crit_edge ], [ %.128, %.thread33 ]
  ret i32 %.3
}

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { 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 = { nofree "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"edge", !9, i64 0, !9, i64 4, !9, i64 8}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!8, !9, i64 4}
!13 = !{!8, !9, i64 8}
!14 = !{!15, !9, i64 24}
!15 = !{!"ufds", !16, i64 0, !16, i64 8, !16, i64 16, !9, i64 24}
!16 = !{!"any pointer", !10, i64 0}


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