; LLVM IR from tangjz/acm-icpc :: uvalive/6140.ll (Z3pfsi)

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

@nxt = external dso_local global [100010 x i32], align 16
@now = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@cir = external dso_local global [100010 x i32], align 16
@cir_cnt = external dso_local global [100010 x i32], align 16
@cir_no = external dso_local global [100010 x i32], align 16
@dfsno = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @now, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @dfsno, i64 0, i64 %7
  store i32 %5, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x i32], ptr @dfsno, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %1
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  call void @_Z3pfsi(i32 noundef %21)
  br label %83

22:                                               ; preds = %1
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100010 x i32], ptr @dfsno, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr @now, align 4, !tbaa !5
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %82

32:                                               ; preds = %22
  %33 = load i32, ptr @tot, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @tot, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100010 x i32], ptr @cir, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr @tot, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100010 x i32], ptr @cir_cnt, i64 0, i64 %39
  store i32 1, ptr %40, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100010 x i32], ptr @cir_no, i64 0, i64 %42
  store i32 1, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %48 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %48, ptr %4, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %75, %32
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = icmp ne i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %81

54:                                               ; preds = %49
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100010 x i32], ptr @cir, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100010 x i32], ptr @cir, i64 0, i64 %60
  store i32 %58, ptr %61, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100010 x i32], ptr @cir_no, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100010 x i32], ptr @cir_no, i64 0, i64 %68
  store i32 %66, ptr %69, align 4, !tbaa !5
  %70 = load i32, ptr @tot, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100010 x i32], ptr @cir_cnt, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %72, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %54
  %76 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %76, ptr %4, align 4, !tbaa !5
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, ptr %3, align 4, !tbaa !5
  br label %49, !llvm.loop !9

81:                                               ; preds = %53
  br label %82

82:                                               ; preds = %81, %22
  br label %83

83:                                               ; preds = %82, %17
  ret void
}

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


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

@nxt = external dso_local local_unnamed_addr global [100010 x i32], align 16
@now = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@cir = external dso_local local_unnamed_addr global [100010 x i32], align 16
@cir_cnt = external dso_local local_unnamed_addr global [100010 x i32], align 16
@cir_no = external dso_local local_unnamed_addr global [100010 x i32], align 16
@dfsno = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3pfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @now, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse, %1
  %.tr = phi i32 [ %0, %1 ], [ %6, %tailrecurse ]
  %3 = sext i32 %.tr to i64
  %4 = getelementptr inbounds [100010 x i32], ptr @dfsno, i64 0, i64 %3
  store i32 %2, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %3
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @dfsno, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %tailrecurse, label %10

10:                                               ; preds = %tailrecurse
  %11 = icmp eq i32 %9, %2
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %10
  %13 = load i32, ptr @tot, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @tot, align 4, !tbaa !5
  %15 = getelementptr inbounds [100010 x i32], ptr @cir, i64 0, i64 %3
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @cir_cnt, i64 0, i64 %16
  store i32 1, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [100010 x i32], ptr @cir_no, i64 0, i64 %3
  store i32 1, ptr %18, align 4, !tbaa !5
  %.not1824 = icmp eq i32 %6, %.tr
  br i1 %.not1824, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.lr.ph
  %19 = phi i32 [ %23, %.lr.ph ], [ 1, %12 ]
  %20 = phi i32 [ %25, %.lr.ph ], [ 1, %12 ]
  %.01626 = phi i32 [ %.016, %.lr.ph ], [ %6, %12 ]
  %21 = sext i32 %.01626 to i64
  %22 = getelementptr inbounds [100010 x i32], ptr @cir, i64 0, i64 %21
  store i32 %14, ptr %22, align 4, !tbaa !5
  %23 = add nuw nsw i32 %19, 1
  %24 = getelementptr inbounds [100010 x i32], ptr @cir_no, i64 0, i64 %21
  store i32 %23, ptr %24, align 4, !tbaa !5
  %25 = add nuw nsw i32 %20, 1
  %26 = getelementptr inbounds [100010 x i32], ptr @nxt, i64 0, i64 %21
  %.016 = load i32, ptr %26, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.016, %.tr
  br i1 %.not18, label %..loopexit_crit_edge, label %.lr.ph, !llvm.loop !9

..loopexit_crit_edge:                             ; preds = %.lr.ph
  store i32 %25, ptr %17, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %12, %..loopexit_crit_edge, %10
  ret void
}

attributes #0 = { mustprogress nofree norecurse 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" }

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


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