; LLVM IR from tangjz/acm-icpc :: 51nod/1076.ll (Z6tarjanii)

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

@e = external dso_local global [100001 x %struct.Edge], align 16
@tot = external dso_local global i32, align 4
@deg = external dso_local global [50001 x i32], align 16
@lnk = external dso_local global [50001 x i32], align 16
@pre = external dso_local global [50001 x i32], align 16
@used = external dso_local global [100001 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6tarjanii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %9 = load i32, ptr @tot, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @tot, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %6, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %92, %2
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp ne i32 %19, -1
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = xor i32 %24, 1
  %26 = icmp eq i32 %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %92

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Edge, ptr %31, i32 0, i32 1
  store ptr %32, ptr %7, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %76

39:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = call noundef i32 @_Z6tarjanii(i32 noundef %41, i32 noundef %42)
  store i32 %43, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = icmp sgt i32 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %39
  %48 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %47, %39
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %75

56:                                               ; preds = %49
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr %59, align 4, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %65, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = xor i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100001 x i8], ptr @used, i64 0, i64 %70
  store i8 1, ptr %71, align 1, !tbaa !11
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x i8], ptr @used, i64 0, i64 %73
  store i8 1, ptr %74, align 1, !tbaa !11
  br label %75

75:                                               ; preds = %56, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %91

76:                                               ; preds = %28
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !9
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = icmp sgt i32 %77, %82
  br i1 %83, label %84, label %90

84:                                               ; preds = %76
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  store i32 %89, ptr %5, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %84, %76
  br label %91

91:                                               ; preds = %90, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %92

92:                                               ; preds = %91, %27
  %93 = load i32, ptr %6, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Edge, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 8, !tbaa !13
  store i32 %97, ptr %6, align 4, !tbaa !5
  br label %18, !llvm.loop !15

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

; 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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.Edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [100001 x %struct.Edge], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@deg = external dso_local local_unnamed_addr global [50001 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [50001 x i32], align 16
@pre = external dso_local local_unnamed_addr global [50001 x i32], align 16
@used = external dso_local local_unnamed_addr global [100001 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z6tarjanii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @tot, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @tot, align 4, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %5
  store i32 %3, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %5
  %.02227 = load i32, ptr %7, align 4, !tbaa !5
  %.not28 = icmp eq i32 %.02227, -1
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %8 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %5
  br label %9

._crit_edge:                                      ; preds = %._crit_edge31, %2
  %.0.lcssa = phi i32 [ %3, %2 ], [ %.3, %._crit_edge31 ]
  ret i32 %.0.lcssa

9:                                                ; preds = %.lr.ph, %._crit_edge31
  %.02230 = phi i32 [ %.02227, %.lr.ph ], [ %.022, %._crit_edge31 ]
  %.029 = phi i32 [ %3, %.lr.ph ], [ %.3, %._crit_edge31 ]
  %10 = xor i32 %.02230, 1
  %11 = icmp eq i32 %10, %1
  %.pre = sext i32 %.02230 to i64
  br i1 %11, label %._crit_edge31, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %.pre, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50001 x i32], ptr @pre, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %34

19:                                               ; preds = %12
  %20 = tail call noundef i32 @_Z6tarjanii(i32 noundef %14, i32 noundef %.02230)
  %spec.select = tail call i32 @llvm.smin.i32(i32 %.029, i32 %20)
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp slt i32 %21, %20
  br i1 %22, label %23, label %._crit_edge31

23:                                               ; preds = %19
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %13, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = sext i32 %10 to i64
  %32 = getelementptr inbounds [100001 x i8], ptr @used, i64 0, i64 %31
  store i8 1, ptr %32, align 1, !tbaa !9
  %33 = getelementptr inbounds [100001 x i8], ptr @used, i64 0, i64 %.pre
  store i8 1, ptr %33, align 1, !tbaa !9
  br label %._crit_edge31

34:                                               ; preds = %12
  %spec.select26 = tail call i32 @llvm.smin.i32(i32 %.029, i32 %17)
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %9, %34, %23, %19
  %.3 = phi i32 [ %spec.select26, %34 ], [ %spec.select, %23 ], [ %spec.select, %19 ], [ %.029, %9 ]
  %35 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %.pre
  %.022 = load i32, ptr %35, align 8, !tbaa !5
  %.not = icmp eq i32 %.022, -1
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !11
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

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


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