; LLVM IR from AnneLivia/Competitive-Programming :: Online Judges/Neps Academy/Reduzindo Detalhes de um Mapa/main.ll (Z7kruskalv)

; 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.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.__gnu_cxx::__normal_iterator" = type { ptr }
%"struct.std::pair" = type { i32, %"struct.std::pair.5" }
%"struct.std::pair.5" = type { i32, i32 }

@g = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5finddi(i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6unionnii(i32 noundef, 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: mustprogress uwtable
define dso_local noundef i32 @_Z7kruskalv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %3 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  %8 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #4
  %9 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %2, i32 0, i32 0
  store ptr %8, ptr %9, align 8
  %10 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #4
  %11 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %3, i32 0, i32 0
  store ptr %10, ptr %11, align 8
  %12 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %2, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8
  %14 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %3, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr %13, ptr %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %52, %0
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = call noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #4
  %19 = trunc i64 %18 to i32
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %55

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %24) #4
  %26 = getelementptr inbounds %"struct.std::pair", ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %"struct.std::pair.5", ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %30) #4
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !12
  store i32 %33, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %35) #4
  %37 = getelementptr inbounds %"struct.std::pair", ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %"struct.std::pair.5", ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  store i32 %39, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = call noundef i32 @_Z5finddi(i32 noundef %40)
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = call noundef i32 @_Z5finddi(i32 noundef %42)
  %44 = icmp ne i32 %41, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %22
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %1, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z6unionnii(i32 noundef %49, i32 noundef %50)
  br label %51

51:                                               ; preds = %45, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !14

55:                                               ; preds = %21
  %56 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret i32 %56
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr, ptr) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 4}
!10 = !{!"_ZTSSt4pairIiS_IiiEE", !6, i64 0, !11, i64 4}
!11 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5finddi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6unionnii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7kruskalv() local_unnamed_addr #0 {
  %1 = tail call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #3
  %2 = tail call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #3
  tail call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr %1, ptr %2)
  %3 = tail call noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #3
  %4 = trunc i64 %3 to i32
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

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

.lr.ph:                                           ; preds = %0, %18
  %indvars.iv = phi i64 [ %indvars.iv.next, %18 ], [ 0, %0 ]
  %.015 = phi i32 [ %.1, %18 ], [ 0, %0 ]
  %6 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %indvars.iv) #3
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %indvars.iv) #3
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @g, i64 noundef %indvars.iv) #3
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = tail call noundef i32 @_Z5finddi(i32 noundef %8)
  %15 = tail call noundef i32 @_Z5finddi(i32 noundef %13)
  %.not = icmp eq i32 %14, %15
  br i1 %.not, label %18, label %16

16:                                               ; preds = %.lr.ph
  %17 = add nsw i32 %10, %.015
  tail call void @_Z6unionnii(i32 noundef %8, i32 noundef %13)
  br label %18

18:                                               ; preds = %16, %.lr.ph
  %.1 = phi i32 [ %17, %16 ], [ %.015, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = tail call noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @g) #3
  %sext = shl i64 %19, 32
  %20 = ashr exact i64 %sext, 32
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr, ptr) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

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


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