; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-04-24/F - Toll Roads - lzy.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, ptr }

@lnk = external dso_local global [500009 x ptr], align 16
@cnt = external dso_local global i32, align 4
@l = external dso_local global [500009 x i32], align 16
@r = external dso_local global [500009 x i32], align 16
@f = external dso_local global [500009 x i32], align 16
@s = external dso_local global [500009 x i32], align 16

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

15:                                               ; preds = %50, %2
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %54

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.Edge, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %19
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.Edge, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500009 x i32], ptr @f, i64 0, i64 %30
  store i32 %26, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [500009 x i32], ptr @s, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Edge, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = add nsw i32 %35, %38
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Edge, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [500009 x i32], ptr @s, i64 0, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Edge, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !11
  call void @_Z3dfsii(i32 noundef %45, i32 noundef %48)
  br label %49

49:                                               ; preds = %25, %19
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.Edge, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  store ptr %53, ptr %5, align 8, !tbaa !9
  br label %15, !llvm.loop !15

54:                                               ; preds = %18
  %55 = load i32, ptr @cnt, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [500009 x i32], ptr @r, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !10, i64 8}
!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"

@lnk = external dso_local local_unnamed_addr global [500009 x ptr], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global [500009 x i32], align 16
@r = external dso_local local_unnamed_addr global [500009 x i32], align 16
@f = external dso_local local_unnamed_addr global [500009 x i32], align 16
@s = external dso_local local_unnamed_addr global [500009 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @cnt, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @cnt, align 4, !tbaa !5
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds [500009 x i32], ptr @l, i64 0, i64 %5
  store i32 %4, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [500009 x ptr], ptr @lnk, i64 0, i64 %5
  %.015 = load ptr, ptr %7, align 8, !tbaa !9
  %.not16 = icmp eq ptr %.015, null
  br i1 %.not16, label %._crit_edge, label %.lr.ph

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

._crit_edge.loopexit:                             ; preds = %24
  %.pre = load i32, ptr @cnt, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %9 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %4, %2 ]
  %10 = getelementptr inbounds [500009 x i32], ptr @r, i64 0, i64 %5
  store i32 %9, ptr %10, align 4, !tbaa !5
  ret void

11:                                               ; preds = %.lr.ph, %24
  %.017 = phi ptr [ %.015, %.lr.ph ], [ %.0, %24 ]
  %12 = load i32, ptr %.017, align 8, !tbaa !11
  %.not14 = icmp eq i32 %12, %0
  br i1 %.not14, label %24, label %13

13:                                               ; preds = %11
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [500009 x i32], ptr @f, i64 0, i64 %14
  store i32 %1, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.017, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = add nsw i32 %18, %16
  %20 = load i32, ptr %.017, align 8, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [500009 x i32], ptr @s, i64 0, i64 %21
  store i32 %19, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %.017, align 8, !tbaa !11
  tail call void @_Z3dfsii(i32 noundef %1, i32 noundef %23)
  br label %24

24:                                               ; preds = %11, %13
  %25 = getelementptr inbounds i8, ptr %.017, i64 8
  %.0 = load ptr, ptr %25, align 8, !tbaa !9
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge.loopexit, label %11, !llvm.loop !14
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: read, 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass