; LLVM IR from AnneLivia/Competitive-Programming :: Data Structures/UnionFind/Union Find/main.ll (Z9has_cyclePA3_i)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15unionFind_unionPiii(ptr noundef, 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 @_Z9has_cyclePA3_i(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %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
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = call noalias ptr @malloc(i64 noundef 12) #5
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %11, i8 -1, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %58, %1
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 3
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %6, align 4
  br label %61

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %17 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %52, %16
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 3
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 5, ptr %6, align 4
  br label %55

22:                                               ; preds = %18
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3 x i32], ptr %23, i64 %25
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %51

32:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = call noundef i32 @_Z14unionFind_findPii(ptr noundef %33, i32 noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = call noundef i32 @_Z14unionFind_findPii(ptr noundef %36, i32 noundef %37)
  store i32 %38, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %32
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %48

43:                                               ; preds = %32
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  call void @_Z15unionFind_unionPiii(ptr noundef %44, i32 noundef %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %43
  store i32 0, ptr %6, align 4
  br label %48

48:                                               ; preds = %47, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %49 = load i32, ptr %6, align 4
  switch i32 %49, label %55 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50, %22
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %18, !llvm.loop !11

55:                                               ; preds = %48, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %56 = load i32, ptr %6, align 4
  switch i32 %56, label %61 [
    i32 5, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !13

61:                                               ; preds = %55, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %62 = load i32, ptr %6, align 4
  switch i32 %62, label %64 [
    i32 2, label %63
  ]

63:                                               ; preds = %61
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

64:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nounwind allocsize(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 nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9has_cyclePA3_i(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
.preheader:
  %1 = tail call noalias dereferenceable_or_null(12) ptr @malloc(i64 noundef 12) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %1, i8 -1, i64 12, i1 false)
  %2 = load i32, ptr %0, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 1
  br i1 %3, label %4, label %8

4:                                                ; preds = %.preheader
  %5 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 0)
  %6 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 0)
  %.not = icmp eq i32 %5, %6
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %4
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %5, i32 noundef %6)
  br label %8

8:                                                ; preds = %7, %.preheader
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 0)
  %14 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 1)
  %.not.146 = icmp eq i32 %13, %14
  br i1 %.not.146, label %.critedge, label %15

15:                                               ; preds = %12
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %13, i32 noundef %14)
  br label %16

16:                                               ; preds = %15, %8
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %.critedge30

20:                                               ; preds = %16
  %21 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 0)
  %22 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 2)
  %.not.247 = icmp eq i32 %21, %22
  br i1 %.not.247, label %.critedge, label %23

23:                                               ; preds = %20
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %21, i32 noundef %22)
  br label %.critedge30

.critedge30:                                      ; preds = %23, %16
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %.critedge30
  %28 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 1)
  %29 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 1)
  %.not.1 = icmp eq i32 %28, %29
  br i1 %.not.1, label %.critedge, label %30

30:                                               ; preds = %27
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %28, i32 noundef %29)
  br label %31

31:                                               ; preds = %30, %.critedge30
  %32 = getelementptr inbounds i8, ptr %0, i64 20
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %.critedge30.1

35:                                               ; preds = %31
  %36 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 1)
  %37 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 2)
  %.not.1.1 = icmp eq i32 %36, %37
  br i1 %.not.1.1, label %.critedge, label %38

38:                                               ; preds = %35
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %36, i32 noundef %37)
  br label %.critedge30.1

.critedge30.1:                                    ; preds = %38, %31
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %.critedge

42:                                               ; preds = %.critedge30.1
  %43 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 2)
  %44 = tail call noundef i32 @_Z14unionFind_findPii(ptr noundef nonnull %1, i32 noundef 2)
  %.not.2 = icmp eq i32 %43, %44
  br i1 %.not.2, label %.critedge, label %45

45:                                               ; preds = %42
  tail call void @_Z15unionFind_unionPiii(ptr noundef nonnull %1, i32 noundef %43, i32 noundef %44)
  br label %.critedge

.critedge:                                        ; preds = %20, %12, %4, %35, %27, %42, %.critedge30.1, %45
  %spec.select = phi i32 [ 0, %45 ], [ 0, %.critedge30.1 ], [ 1, %42 ], [ 1, %27 ], [ 1, %35 ], [ 1, %4 ], [ 1, %12 ], [ 1, %20 ]
  ret i32 %spec.select
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass