; LLVM IR from TheAlgorithms/C-Plus-Plus :: graph/kruskal.ll (Z4rooti)

; 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.std::array" = type { [1000005 x i64] }

@parent = external dso_local global %"struct.std::array", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4rooti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %11, %1
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %5) #1
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = icmp ne i64 %7, %9
  br i1 %10, label %11, label %26

11:                                               ; preds = %3
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %13) #1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %15) #1
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %19) #1
  store i64 %17, ptr %20, align 8, !tbaa !9
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %22) #1
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !11

26:                                               ; preds = %3
  %27 = load i32, ptr %2, align 4, !tbaa !5
  ret i32 %27
}

attributes #0 = { 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 #1 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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.std::array" = type { [1000005 x i64] }

@parent = external dso_local global %"struct.std::array", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4rooti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %2) #1
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not7 = icmp eq i64 %4, %2
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %5 = phi i64 [ %13, %.lr.ph ], [ %2, %1 ]
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %5) #1
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %7) #1
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %5) #1
  store i64 %9, ptr %10, align 8, !tbaa !5
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %5) #1
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %sext = shl i64 %12, 32
  %13 = ashr exact i64 %sext, 32
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt5arrayIlLm1000005EEixEm(ptr noundef nonnull align 8 dereferenceable(8000040) @parent, i64 noundef %13) #1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %.not = icmp eq i64 %15, %13
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %16 = trunc i64 %12 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.0.lcssa = phi i32 [ %0, %1 ], [ %16, %._crit_edge.loopexit ]
  ret i32 %.0.lcssa
}

attributes #0 = { 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 #1 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass