; LLVM IR from tangjz/acm-icpc :: uoj/16.ll (Z3dfsii)

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

@w = external dso_local global [200001 x i32], align 16
@pre = external dso_local global [200001 x i32], align 16
@ans1 = external dso_local global i32, align 4
@ans2 = external dso_local global i32, align 4
@e = external dso_local global [400002 x %struct.Edge], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

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

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %19)
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = call noundef i32 @_Z3sqri(i32 noundef %23)
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %24)
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  call void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8, i32 noundef %28)
  br label %29

29:                                               ; preds = %15, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200001 x i32], ptr @pre, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %9, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %71, %29
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %77

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [400002 x %struct.Edge], ptr @e, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Edge, ptr %41, i32 0, i32 1
  store ptr %42, ptr %11, align 8, !tbaa !9
  %43 = load ptr, ptr %11, align 8, !tbaa !9
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  store i32 4, ptr %10, align 4
  br label %68

48:                                               ; preds = %38
  %49 = load ptr, ptr %11, align 8, !tbaa !9
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %50, i32 noundef %51)
  %52 = load ptr, ptr %11, align 8, !tbaa !9
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %56)
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = call noundef i32 @_Z3sqri(i32 noundef %61)
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %62)
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  call void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8, i32 noundef %67)
  store i32 0, ptr %10, align 4
  br label %68

68:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %69 = load i32, ptr %10, align 4
  switch i32 %69, label %92 [
    i32 0, label %70
    i32 4, label %71
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %68
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [400002 x %struct.Edge], ptr @e, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Edge, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !11
  store i32 %76, ptr %9, align 4, !tbaa !5
  br label %34, !llvm.loop !13

77:                                               ; preds = %37
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = mul nsw i32 %78, %79
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %80)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = call noundef i32 @_Z3sqri(i32 noundef %81)
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sub nsw i32 %82, %83
  store i32 %84, ptr %12, align 4, !tbaa !5
  %85 = load i32, ptr %12, align 4, !tbaa !5
  %86 = icmp slt i32 %85, 0
  br i1 %86, label %87, label %90

87:                                               ; preds = %77
  %88 = load i32, ptr %12, align 4, !tbaa !5
  %89 = add nsw i32 %88, 10007
  store i32 %89, ptr %12, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %87, %77
  %91 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %91)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void

92:                                               ; preds = %68
  unreachable
}

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

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

attributes #0 = { mustprogress nounwind 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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"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 }

@w = external dso_local local_unnamed_addr global [200001 x i32], align 16
@pre = external dso_local local_unnamed_addr global [200001 x i32], align 16
@ans1 = external dso_local global i32, align 4
@ans2 = external dso_local global i32, align 4
@e = external dso_local local_unnamed_addr global [400002 x %struct.Edge], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %1, -1
  br i1 %.not, label %14, label %7

7:                                                ; preds = %2
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %10)
  %11 = load i32, ptr %9, align 4, !tbaa !5
  %12 = call noundef i32 @_Z3sqri(i32 noundef %11)
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %12)
  %13 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %13)
  br label %14

14:                                               ; preds = %7, %2
  %15 = sext i32 %0 to i64
  %16 = getelementptr inbounds [200001 x i32], ptr @pre, i64 0, i64 %15
  %.01722 = load i32, ptr %16, align 4, !tbaa !5
  %.not2123 = icmp eq i32 %.01722, 0
  br i1 %.not2123, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %45, %14
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = mul nsw i32 %18, %17
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans1, i32 noundef %19)
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = call noundef i32 @_Z3sqri(i32 noundef %20)
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sub nsw i32 %21, %22
  %24 = icmp slt i32 %23, 0
  %25 = add nsw i32 %23, 10007
  %spec.select = select i1 %24, i32 %25, i32 %23
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) @ans2, i32 noundef %spec.select)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  ret void

.lr.ph:                                           ; preds = %14, %45
  %.01724 = phi i32 [ %.017, %45 ], [ %.01722, %14 ]
  %26 = sext i32 %.01724 to i64
  %27 = getelementptr inbounds [400002 x %struct.Edge], ptr @e, i64 0, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, %1
  br i1 %30, label %45, label %31

31:                                               ; preds = %.lr.ph
  call void @_Z3dfsii(i32 noundef %29, i32 noundef %0)
  %32 = load i32, ptr %28, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %35)
  %36 = load i32, ptr %28, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call noundef i32 @_Z3sqri(i32 noundef %39)
  call void @_Z3incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %40)
  %41 = load i32, ptr %28, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200001 x i32], ptr @w, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  call void @_Z3updRiS_i(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %44)
  br label %45

45:                                               ; preds = %.lr.ph, %31
  %.017 = load i32, ptr %27, align 8, !tbaa !5
  %.not21 = icmp eq i32 %.017, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass