; LLVM IR from pranjalwalia/Competitive-programming :: implementations/graphs/mst/Kruskals.ll (Z5mergexx)

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

@p = external dso_local global [100005 x i64], align 16
@rnk = external dso_local global [100005 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4findx(i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergexx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = call noundef i64 @_Z4findx(i64 noundef %5)
  store i64 %6, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = call noundef i64 @_Z4findx(i64 noundef %7)
  store i64 %8, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = icmp ne i64 %9, %10
  br i1 %11, label %12, label %32

12:                                               ; preds = %2
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = icmp slt i64 %15, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %12
  call void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #2
  br label %21

21:                                               ; preds = %20, %12
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i64 %27, %24
  store i64 %28, ptr %26, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %30
  store i64 %29, ptr %31, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %21, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

attributes #0 = { 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 #1 = { inlinehint mustprogress 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 #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 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@p = external dso_local local_unnamed_addr global [100005 x i64], align 16
@rnk = external dso_local local_unnamed_addr global [100005 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4findx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5mergexx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = tail call noundef i64 @_Z4findx(i64 noundef %0)
  store i64 %5, ptr %3, align 8, !tbaa !5
  %6 = tail call noundef i64 @_Z4findx(i64 noundef %1)
  store i64 %6, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, %6
  br i1 %.not, label %22, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %5
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %6
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp slt i64 %9, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %7
  call void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #2
  %.pre = load i64, ptr %4, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %.pre
  %.pre2 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.pre3 = load i64, ptr %3, align 8, !tbaa !5
  %.phi.trans.insert4 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %.pre3
  %.pre5 = load i64, ptr %.phi.trans.insert4, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %7
  %15 = phi i64 [ %.pre5, %13 ], [ %9, %7 ]
  %16 = phi i64 [ %.pre3, %13 ], [ %5, %7 ]
  %17 = phi i64 [ %.pre2, %13 ], [ %11, %7 ]
  %18 = phi i64 [ %.pre, %13 ], [ %6, %7 ]
  %19 = getelementptr inbounds [100005 x i64], ptr @rnk, i64 0, i64 %16
  %20 = add nsw i64 %15, %17
  store i64 %20, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds [100005 x i64], ptr @p, i64 0, i64 %18
  store i64 %16, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %14, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint mustprogress 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 #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 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,TailCallElimPass