; LLVM IR from Tunghohin/Competitive_Coding :: Uva/uva1395.ll (Z7kruskaliii)

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

@e = external dso_local global [10010 x %struct.edge], align 16
@p = external dso_local global [110 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z7kruskaliii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i1, align 1
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %24, %3
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %27

19:                                               ; preds = %14
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [110 x i32], ptr @p, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %9, align 4, !tbaa !5
  br label %14, !llvm.loop !9

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %28 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %28, ptr %10, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %60, %27
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %63

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10010 x %struct.edge], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.edge, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !11
  store i32 %39, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10010 x %struct.edge], ptr @e, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.edge, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !13
  store i32 %44, ptr %12, align 4, !tbaa !5
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = call noundef i32 @_Z4findi(i32 noundef %45)
  store i32 %46, ptr %11, align 4, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = call noundef i32 @_Z4findi(i32 noundef %47)
  store i32 %48, ptr %12, align 4, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = icmp ne i32 %49, %50
  br i1 %51, label %52, label %59

52:                                               ; preds = %34
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [110 x i32], ptr @p, i64 0, i64 %55
  store i32 %53, ptr %56, align 4, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %52, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %10, align 4, !tbaa !5
  br label %29, !llvm.loop !14

63:                                               ; preds = %33
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = icmp eq i32 %64, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  store i1 true, ptr %4, align 1
  store i32 1, ptr %13, align 4
  br label %69

68:                                               ; preds = %63
  store i1 false, ptr %4, align 1
  store i32 1, ptr %13, align 4
  br label %69

69:                                               ; preds = %68, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %70 = load i1, ptr %4, align 1
  ret i1 %70
}

; 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

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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !10}


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

@e = external dso_local local_unnamed_addr global [10010 x %struct.edge], align 16
@p = external dso_local local_unnamed_addr global [110 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z7kruskaliii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not28 = icmp slt i32 %2, 0
  br i1 %.not28, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %4 to i64
  %min.iters.check = icmp ult i32 %2, 7
  br i1 %min.iters.check, label %.lr.ph.preheader40, label %vector.ph

.lr.ph.preheader40:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %5 = getelementptr inbounds [110 x i32], ptr @p, i64 0, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <4 x i32> %vec.ind, ptr %5, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %6, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %7 = icmp eq i64 %index.next, %n.vec
  br i1 %7, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader40

.preheader:                                       ; preds = %.lr.ph, %middle.block, %3
  %.not2630 = icmp sgt i32 %0, %1
  br i1 %.not2630, label %._crit_edge, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %.preheader
  %8 = sext i32 %0 to i64
  %9 = add i32 %1, 1
  br label %.lr.ph33

.lr.ph:                                           ; preds = %.lr.ph.preheader40, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader40 ]
  %10 = getelementptr inbounds [110 x i32], ptr @p, i64 0, i64 %indvars.iv
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %11, ptr %10, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %23, %.preheader
  %.021.lcssa = phi i32 [ 1, %.preheader ], [ %.1, %23 ]
  %12 = icmp eq i32 %.021.lcssa, %2
  ret i1 %12

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %23
  %indvars.iv35 = phi i64 [ %8, %.lr.ph33.preheader ], [ %indvars.iv.next36, %23 ]
  %.02131 = phi i32 [ 1, %.lr.ph33.preheader ], [ %.1, %23 ]
  %13 = getelementptr inbounds [10010 x %struct.edge], ptr @e, i64 0, i64 %indvars.iv35
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %13, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = tail call noundef i32 @_Z4findi(i32 noundef %14)
  %18 = tail call noundef i32 @_Z4findi(i32 noundef %16)
  %.not27 = icmp eq i32 %17, %18
  br i1 %.not27, label %23, label %19

19:                                               ; preds = %.lr.ph33
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [110 x i32], ptr @p, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  %22 = add nsw i32 %.02131, 1
  br label %23

23:                                               ; preds = %19, %.lr.ph33
  %.1 = phi i32 [ %22, %19 ], [ %.02131, %.lr.ph33 ]
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next36 to i32
  %exitcond38.not = icmp eq i32 %9, %lftr.wideiv
  br i1 %exitcond38.not, label %._crit_edge, label %.lr.ph33, !llvm.loop !17
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!16 = !{!15, !6, i64 4}
!17 = distinct !{!17, !10}


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