; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2016 Astar Contest - Round 2A/1003-Snacks.ll (Z3dfsv)

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

@pos = external dso_local global [100005 x i32], align 16
@w = external dso_local global [100005 x i32], align 16
@dfn = external dso_local global i32, align 4
@in = external dso_local global [100005 x i32], align 16
@out = external dso_local global [100005 x i32], align 16
@a = external dso_local global [100005 x i32], align 16
@st = external dso_local global [100005 x i32], align 16
@top = external dso_local global i32, align 4
@vis = external dso_local global [100005 x i32], align 16
@par = external dso_local global [100005 x i32], align 16
@s = external dso_local global [100005 x i64], align 16
@g = external dso_local global [200010 x %struct.edge], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  br label %3

3:                                                ; preds = %102, %0
  %4 = load i32, ptr @top, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %103

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %7 = load i32, ptr @top, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100005 x i32], ptr @st, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100005 x i32], ptr @vis, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %95, label %16

16:                                               ; preds = %6
  %17 = load i32, ptr @dfn, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @dfn, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100005 x i32], ptr @in, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = load i32, ptr @dfn, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100005 x i32], ptr @w, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100005 x i32], ptr @pos, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %85, %16
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %30
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.edge, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100005 x i32], ptr @par, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp ne i32 %39, %43
  br i1 %44, label %45, label %84

45:                                               ; preds = %34
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.edge, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100005 x i32], ptr @par, i64 0, i64 %52
  store i32 %46, ptr %53, align 4, !tbaa !5
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100005 x i64], ptr @s, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !11
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.edge, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100005 x i32], ptr @a, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = add nsw i64 %57, %66
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.edge, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 8, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100005 x i64], ptr @s, i64 0, i64 %73
  store i64 %67, ptr %74, align 8, !tbaa !11
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.edge, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 8, !tbaa !9
  %80 = load i32, ptr @top, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr @top, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100005 x i32], ptr @st, i64 0, i64 %82
  store i32 %79, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %45, %34
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.edge, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !13
  store i32 %90, ptr %2, align 4, !tbaa !5
  br label %30, !llvm.loop !14

91:                                               ; preds = %33
  %92 = load i32, ptr %1, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [100005 x i32], ptr @vis, i64 0, i64 %93
  store i32 1, ptr %94, align 4, !tbaa !5
  br label %102

95:                                               ; preds = %6
  %96 = load i32, ptr @top, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr @top, align 4, !tbaa !5
  %98 = load i32, ptr @dfn, align 4, !tbaa !5
  %99 = load i32, ptr %1, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [100005 x i32], ptr @out, i64 0, i64 %100
  store i32 %98, ptr %101, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %95, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %3, !llvm.loop !16

103:                                              ; preds = %3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@pos = external dso_local local_unnamed_addr global [100005 x i32], align 16
@w = external dso_local local_unnamed_addr global [100005 x i32], align 16
@dfn = external dso_local local_unnamed_addr global i32, align 4
@in = external dso_local local_unnamed_addr global [100005 x i32], align 16
@out = external dso_local local_unnamed_addr global [100005 x i32], align 16
@a = external dso_local local_unnamed_addr global [100005 x i32], align 16
@st = external dso_local local_unnamed_addr global [100005 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [100005 x i32], align 16
@par = external dso_local local_unnamed_addr global [100005 x i32], align 16
@s = external dso_local local_unnamed_addr global [100005 x i64], align 16
@g = external dso_local local_unnamed_addr global [200010 x %struct.edge], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsv() local_unnamed_addr #0 {
  %top.promoted24 = load i32, ptr @top, align 4, !tbaa !5
  %.not30 = icmp eq i32 %top.promoted24, 0
  br i1 %.not30, label %._crit_edge34, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %0
  %dfn.promoted = load i32, ptr @dfn, align 4, !tbaa !5
  br label %.lr.ph33

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %40
  %top.promoted2931 = phi i32 [ %top.promoted27, %40 ], [ %top.promoted24, %.lr.ph33.preheader ]
  %1 = phi i32 [ %41, %40 ], [ %dfn.promoted, %.lr.ph33.preheader ]
  %2 = sext i32 %top.promoted2931 to i64
  %3 = getelementptr inbounds [100005 x i32], ptr @st, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [100005 x i32], ptr @vis, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not18 = icmp eq i32 %7, 0
  br i1 %.not18, label %8, label %37

8:                                                ; preds = %.lr.ph33
  %9 = add nsw i32 %1, 1
  store i32 %9, ptr @dfn, align 4, !tbaa !5
  %10 = getelementptr inbounds [100005 x i32], ptr @in, i64 0, i64 %5
  store i32 %9, ptr %10, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [100005 x i32], ptr @w, i64 0, i64 %11
  store i32 %4, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [100005 x i32], ptr @pos, i64 0, i64 %5
  %.021 = load i32, ptr %13, align 4, !tbaa !5
  %.not1922 = icmp eq i32 %.021, 0
  br i1 %.not1922, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %14 = getelementptr inbounds [100005 x i32], ptr @par, i64 0, i64 %5
  %15 = getelementptr inbounds [100005 x i64], ptr @s, i64 0, i64 %5
  br label %16

._crit_edge:                                      ; preds = %34, %8
  %top.promoted28 = phi i32 [ %top.promoted2931, %8 ], [ %top.promoted25, %34 ]
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %40

16:                                               ; preds = %.lr.ph, %34
  %top.promoted26 = phi i32 [ %top.promoted2931, %.lr.ph ], [ %top.promoted25, %34 ]
  %.023 = phi i32 [ %.021, %.lr.ph ], [ %.0, %34 ]
  %17 = phi i32 [ %top.promoted2931, %.lr.ph ], [ %35, %34 ]
  %18 = sext i32 %.023 to i64
  %19 = getelementptr inbounds [200010 x %struct.edge], ptr @g, i64 0, i64 %18
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %14, align 4, !tbaa !5
  %.not20 = icmp eq i32 %20, %21
  br i1 %.not20, label %34, label %22

22:                                               ; preds = %16
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds [100005 x i32], ptr @par, i64 0, i64 %23
  store i32 %4, ptr %24, align 4, !tbaa !5
  %25 = load i64, ptr %15, align 8, !tbaa !11
  %26 = getelementptr inbounds [100005 x i32], ptr @a, i64 0, i64 %23
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = add nsw i64 %25, %28
  %30 = getelementptr inbounds [100005 x i64], ptr @s, i64 0, i64 %23
  store i64 %29, ptr %30, align 8, !tbaa !11
  %31 = add nsw i32 %17, 1
  store i32 %31, ptr @top, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100005 x i32], ptr @st, i64 0, i64 %32
  store i32 %20, ptr %33, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %16, %22
  %top.promoted25 = phi i32 [ %top.promoted26, %16 ], [ %31, %22 ]
  %35 = phi i32 [ %17, %16 ], [ %31, %22 ]
  %36 = getelementptr inbounds i8, ptr %19, i64 4
  %.0 = load i32, ptr %36, align 4, !tbaa !5
  %.not19 = icmp eq i32 %.0, 0
  br i1 %.not19, label %._crit_edge, label %16, !llvm.loop !13

37:                                               ; preds = %.lr.ph33
  %38 = add nsw i32 %top.promoted2931, -1
  store i32 %38, ptr @top, align 4, !tbaa !5
  %39 = getelementptr inbounds [100005 x i32], ptr @out, i64 0, i64 %5
  store i32 %1, ptr %39, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %37, %._crit_edge
  %41 = phi i32 [ %1, %37 ], [ %9, %._crit_edge ]
  %top.promoted27 = phi i32 [ %38, %37 ], [ %top.promoted28, %._crit_edge ]
  %.not = icmp eq i32 %top.promoted27, 0
  br i1 %.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !15

._crit_edge34:                                    ; preds = %40, %0
  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 = !{!10, !6, i64 0}
!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"}
!15 = distinct !{!15, !14}


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