; LLVM IR from Muhammad-Magdi/problem-solving :: Graphs (Minimum Spanning Tree [Kruskal])

; 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 }
%class.anon = type { i8 }

@E = external dso_local global [300005 x %struct.edge], align 16
@sorted = external dso_local global [300005 x i32], align 16
@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@total = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.edge, align 4
  %4 = alloca %class.anon, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %8

8:                                                ; preds = %86, %0
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %91

12:                                               ; preds = %8
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p, ptr noundef @n, ptr noundef @m)
  call void @_Z4initv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %36, %12
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %39

19:                                               ; preds = %14
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @u, ptr noundef @v, ptr noundef @c)
  call void @llvm.lifetime.start.p0(i64 12, ptr %3) #5
  %21 = getelementptr inbounds %struct.edge, ptr %3, i32 0, i32 0
  %22 = load i32, ptr @u, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @u, align 4, !tbaa !5
  store i32 %23, ptr %21, align 4, !tbaa !9
  %24 = getelementptr inbounds %struct.edge, ptr %3, i32 0, i32 1
  %25 = load i32, ptr @v, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr @v, align 4, !tbaa !5
  store i32 %26, ptr %24, align 4, !tbaa !11
  %27 = getelementptr inbounds %struct.edge, ptr %3, i32 0, i32 2
  %28 = load i32, ptr @c, align 4, !tbaa !5
  store i32 %28, ptr %27, align 4, !tbaa !12
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %31, ptr align 4 %3, i64 12, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 12, ptr %3) #5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [300005 x i32], ptr @sorted, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %19
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !14

39:                                               ; preds = %18
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @sorted, i64 %41
  call void @"_ZSt4sortIPiZ4mainE3$_0EvT_S2_T0_"(ptr noundef @sorted, ptr noundef %42)
  store i32 0, ptr @total, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %83, %39
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %86

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [300005 x i32], ptr @sorted, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.edge, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.edge, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !11
  %63 = call noundef zeroext i1 @_Z7sameSetii(i32 noundef %57, i32 noundef %62)
  br i1 %63, label %82, label %64

64:                                               ; preds = %48
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.edge, ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.edge, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !11
  call void @_Z4joinii(i32 noundef %69, i32 noundef %74)
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.edge, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 4, !tbaa !12
  %80 = load i32, ptr @total, align 4, !tbaa !5
  %81 = add nsw i32 %80, %79
  store i32 %81, ptr @total, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %64, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %5, align 4, !tbaa !5
  br label %43, !llvm.loop !16

86:                                               ; preds = %47
  %87 = load i32, ptr @p, align 4, !tbaa !5
  %88 = load i32, ptr @total, align 4, !tbaa !5
  %89 = mul nsw i32 %87, %88
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %89)
  br label %8, !llvm.loop !17

91:                                               ; preds = %8
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z4initv() #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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt4sortIPiZ4mainE3$_0EvT_S2_T0_"(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7sameSetii(i32 noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z4joinii(i32 noundef, i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #1

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


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

@E = external dso_local local_unnamed_addr global [300005 x %struct.edge], align 16
@sorted = external dso_local global [300005 x i32], align 16
@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@total = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not20 = icmp eq i32 %2, 0
  br i1 %.not20, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %0, %._crit_edge19
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p, ptr noundef nonnull @n, ptr noundef nonnull @m)
  tail call void @_Z4initv()
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.lr.ph22.._crit_edge_crit_edge

.lr.ph22.._crit_edge_crit_edge:                   ; preds = %.lr.ph22
  %.pre29 = sext i32 %5 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph22.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre29, %.lr.ph22.._crit_edge_crit_edge ], [ %20, %.lr.ph ]
  %7 = getelementptr inbounds i32, ptr @sorted, i64 %.pre-phi
  tail call void @"_ZSt4sortIPiZ4mainE3$_0EvT_S2_T0_"(ptr noundef nonnull @sorted, ptr noundef nonnull %7)
  store i32 0, ptr @total, align 4, !tbaa !5
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph18, label %._crit_edge19

.lr.ph:                                           ; preds = %.lr.ph22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph22 ]
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @u, ptr noundef nonnull @v, ptr noundef nonnull @c)
  %11 = load i32, ptr @u, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @u, align 4, !tbaa !5
  %13 = load i32, ptr @v, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr @v, align 4, !tbaa !5
  %15 = load i32, ptr @c, align 4, !tbaa !5
  %16 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %indvars.iv
  store i32 %12, ptr %16, align 4, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %16, i64 4
  store i32 %14, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %16, i64 8
  store i32 %15, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %17 = getelementptr inbounds [300005 x i32], ptr @sorted, i64 0, i64 %indvars.iv
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %18, ptr %17, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge19.loopexit:                           ; preds = %43
  %.pre = load i32, ptr @total, align 4, !tbaa !5
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %._crit_edge19.loopexit, %._crit_edge
  %22 = phi i32 [ %.pre, %._crit_edge19.loopexit ], [ 0, %._crit_edge ]
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = mul nsw i32 %22, %23
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %24)
  %26 = load i32, ptr @t, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !11

.lr.ph18:                                         ; preds = %._crit_edge, %43
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %43 ], [ 0, %._crit_edge ]
  %28 = getelementptr inbounds [300005 x i32], ptr @sorted, i64 0, i64 %indvars.iv26
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [300005 x %struct.edge], ptr @E, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %31, i64 4
  %34 = load i32, ptr %33, align 4, !tbaa !14
  %35 = tail call noundef zeroext i1 @_Z7sameSetii(i32 noundef %32, i32 noundef %34)
  br i1 %35, label %43, label %36

36:                                               ; preds = %.lr.ph18
  %37 = load i32, ptr %31, align 4, !tbaa !12
  %38 = load i32, ptr %33, align 4, !tbaa !14
  tail call void @_Z4joinii(i32 noundef %37, i32 noundef %38)
  %39 = getelementptr inbounds i8, ptr %31, i64 8
  %40 = load i32, ptr %39, align 4, !tbaa !15
  %41 = load i32, ptr @total, align 4, !tbaa !5
  %42 = add nsw i32 %41, %40
  store i32 %42, ptr @total, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %36, %.lr.ph18
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next27, %45
  br i1 %46, label %.lr.ph18, label %._crit_edge19.loopexit, !llvm.loop !16

._crit_edge23:                                    ; preds = %._crit_edge19, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt4sortIPiZ4mainE3$_0EvT_S2_T0_"(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7sameSetii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z4joinii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress norecurse 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 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 #2 = { inlinehint 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!13, !6, i64 4}
!15 = !{!13, !6, i64 8}
!16 = distinct !{!16, !10}


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