; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Greedy/Kruskal’s Minimum Spanning Tree.ll (Z5UnionP6subsetii)

; 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.subset = type { i32, i32 }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4findP6subseti(ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5UnionP6subsetii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = call noundef i32 @_Z4findP6subseti(ptr noundef %9, i32 noundef %10)
  store i32 %11, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = call noundef i32 @_Z4findP6subseti(ptr noundef %12, i32 noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.subset, ptr %15, i64 %17
  %19 = getelementptr inbounds %struct.subset, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.subset, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.subset, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = icmp slt i32 %20, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %3
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.subset, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.subset, ptr %33, i32 0, i32 0
  store i32 %29, ptr %34, align 4, !tbaa !13
  br label %71

35:                                               ; preds = %3
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.subset, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct.subset, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.subset, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.subset, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = icmp sgt i32 %41, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %35
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.subset, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.subset, ptr %54, i32 0, i32 0
  store i32 %50, ptr %55, align 4, !tbaa !13
  br label %70

56:                                               ; preds = %35
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.subset, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.subset, ptr %61, i32 0, i32 0
  store i32 %57, ptr %62, align 4, !tbaa !13
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.subset, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.subset, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %67, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %56, %49
  br label %71

71:                                               ; preds = %70, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS6subset", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 0}


; 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.subset = type { i32, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5UnionP6subsetii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_Z4findP6subseti(ptr noundef %0, i32 noundef %1)
  %5 = tail call noundef i32 @_Z4findP6subseti(ptr noundef %0, i32 noundef %2)
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds %struct.subset, ptr %0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %5 to i64
  %11 = getelementptr inbounds %struct.subset, ptr %0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp slt i32 %9, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 %5, ptr %7, align 4, !tbaa !10
  br label %20

16:                                               ; preds = %3
  %17 = icmp sgt i32 %9, %13
  store i32 %4, ptr %11, align 4, !tbaa !10
  br i1 %17, label %20, label %18

18:                                               ; preds = %16
  %19 = add nsw i32 %9, 1
  store i32 %19, ptr %8, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %16, %18, %15
  ret void
}

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

!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 = !{!"_ZTS6subset", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass