; LLVM IR from tangjz/acm-icpc :: hdu/6035.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 }

@c = external dso_local global [200001 x i32], align 16
@lnk = external dso_local global [200001 x i32], align 16
@pos = external dso_local global [200001 x i32], align 16
@ctr = external dso_local global [200001 x i32], align 16
@rem = external dso_local global [200001 x i32], align 16
@ans = external dso_local global i64, align 8
@e = external dso_local global [400003 x %struct.Edge], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3dfsii(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 i32, align 4
  %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) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200001 x i32], ptr @c, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200001 x i32], ptr @c, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %21
  store i32 %16, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200001 x i32], ptr @lnk, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %7, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %63, %2
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %69

31:                                               ; preds = %27
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [400003 x %struct.Edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Edge, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp ne i32 %36, %37
  br i1 %38, label %39, label %62

39:                                               ; preds = %31
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %41
  store i32 0, ptr %42, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [400003 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = call noundef i32 @_Z3dfsii(i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sub nsw i32 %50, %54
  %56 = call noundef i64 @_Z4sum2i(i32 noundef %55)
  %57 = load i64, ptr @ans, align 8, !tbaa !11
  %58 = sub nsw i64 %57, %56
  store i64 %58, ptr @ans, align 8, !tbaa !11
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %62

62:                                               ; preds = %39, %31
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [400003 x %struct.Edge], ptr @e, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.Edge, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !13
  store i32 %68, ptr %7, align 4, !tbaa !5
  br label %27, !llvm.loop !14

69:                                               ; preds = %30
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %69
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %75
  br label %84

77:                                               ; preds = %69
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [200001 x i32], ptr @c, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200001 x i32], ptr @rem, i64 0, i64 %82
  br label %84

84:                                               ; preds = %77, %73
  %85 = phi ptr [ %76, %73 ], [ %83, %77 ]
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = add nsw i32 %86, %70
  store i32 %87, ptr %85, align 4, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [200001 x i32], ptr @c, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %93
  store i32 %88, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %95
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4sum2i(i32 noundef) #2

; 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 = { inlinehint 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 #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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 }

@c = external dso_local local_unnamed_addr global [200001 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [200001 x i32], align 16
@pos = external dso_local local_unnamed_addr global [200001 x i32], align 16
@ctr = external dso_local local_unnamed_addr global [200001 x i32], align 16
@rem = external dso_local local_unnamed_addr global [200001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@e = external dso_local local_unnamed_addr global [400003 x %struct.Edge], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [200001 x i32], ptr @c, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %0, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds [200001 x i32], ptr @lnk, i64 0, i64 %3
  %.02226 = load i32, ptr %9, align 4, !tbaa !5
  %.not27 = icmp eq i32 %.02226, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %3
  br label %11

._crit_edge:                                      ; preds = %24, %2
  %.0.lcssa = phi i32 [ 1, %2 ], [ %.1, %24 ]
  %.not24 = icmp eq i32 %8, 0
  br i1 %.not24, label %28, label %25

11:                                               ; preds = %.lr.ph, %24
  %.02229 = phi i32 [ %.02226, %.lr.ph ], [ %.022, %24 ]
  %.028 = phi i32 [ 1, %.lr.ph ], [ %.1, %24 ]
  %12 = sext i32 %.02229 to i64
  %13 = getelementptr inbounds [400003 x %struct.Edge], ptr @e, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not25 = icmp eq i32 %15, %1
  br i1 %.not25, label %24, label %16

16:                                               ; preds = %11
  store i32 0, ptr %10, align 4, !tbaa !5
  %17 = tail call noundef i32 @_Z3dfsii(i32 noundef %15, i32 noundef %0)
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = sub nsw i32 %17, %18
  %20 = tail call noundef i64 @_Z4sum2i(i32 noundef %19)
  %21 = load i64, ptr @ans, align 8, !tbaa !11
  %22 = sub nsw i64 %21, %20
  store i64 %22, ptr @ans, align 8, !tbaa !11
  %23 = add nsw i32 %17, %.028
  br label %24

24:                                               ; preds = %11, %16
  %.1 = phi i32 [ %23, %16 ], [ %.028, %11 ]
  %.022 = load i32, ptr %13, align 8, !tbaa !5
  %.not = icmp eq i32 %.022, 0
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !13

25:                                               ; preds = %._crit_edge
  %26 = sext i32 %8 to i64
  %27 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %26
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  %.pre30 = sext i32 %.pre to i64
  br label %32

28:                                               ; preds = %._crit_edge
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200001 x i32], ptr @rem, i64 0, i64 %30
  br label %32

32:                                               ; preds = %28, %25
  %.pre-phi = phi i64 [ %30, %28 ], [ %.pre30, %25 ]
  %33 = phi ptr [ %31, %28 ], [ %27, %25 ]
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %.0.lcssa
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %.pre-phi
  store i32 %8, ptr %36, align 4, !tbaa !5
  ret i32 %.0.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4sum2i(i32 noundef) local_unnamed_addr #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 = { inlinehint 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" }

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


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