; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan/225.ll (Z5dfs_1xx)

; 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 { i64, i64, i64 }

@max_flow = external dso_local global [100010 x i64], align 16
@e = external dso_local global [200020 x %struct.edge], align 16
@head = external dso_local global [100010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z8inv_edgex(i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5dfs_1xx(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds [100010 x i64], ptr @head, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %10, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %33, %2
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %38

15:                                               ; preds = %11
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = call noundef i64 @_Z8inv_edgex(i64 noundef %17)
  %19 = icmp eq i64 %16, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %33

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.edge, ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !9
  store i64 %25, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z5dfs_1xx(i64 noundef %26, i64 noundef %27)
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %33

33:                                               ; preds = %21, %20
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.edge, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !11
  store i64 %37, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !12

38:                                               ; preds = %14
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %48

41:                                               ; preds = %38
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.edge, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !14
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %46
  store i64 %45, ptr %47, align 8, !tbaa !5
  br label %67

48:                                               ; preds = %38
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.edge, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %54, label %58

54:                                               ; preds = %48
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %56
  store i64 %55, ptr %57, align 8, !tbaa !5
  br label %66

58:                                               ; preds = %48
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.edge, ptr %60, i32 0, i32 2
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %61, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = load i64, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %64
  store i64 %63, ptr %65, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %58, %54
  br label %67

67:                                               ; preds = %66, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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


; 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 { i64, i64, i64 }

@max_flow = external dso_local local_unnamed_addr global [100010 x i64], align 16
@e = external dso_local global [200020 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [100010 x i64], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5dfs_1xx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = getelementptr inbounds [100010 x i64], ptr @head, i64 0, i64 %0
  %.016 = load i64, ptr %4, align 8, !tbaa !5
  %.not17 = icmp eq i64 %.016, 0
  br i1 %.not17, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %15
  store i64 %16, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %16, 0
  br i1 %5, label %._crit_edge.thread, label %20

.lr.ph:                                           ; preds = %2, %15
  %.018 = phi i64 [ %.0, %15 ], [ %.016, %2 ]
  %6 = phi i64 [ %16, %15 ], [ 0, %2 ]
  %7 = tail call noundef i64 @_Z8inv_edgex(i64 noundef %1)
  %8 = icmp eq i64 %.018, %7
  br i1 %8, label %15, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %.018
  %11 = load i64, ptr %10, align 8, !tbaa !9
  tail call void @_Z5dfs_1xx(i64 noundef %11, i64 noundef %.018)
  %12 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %6, %13
  br label %15

15:                                               ; preds = %.lr.ph, %9
  %16 = phi i64 [ %6, %.lr.ph ], [ %14, %9 ]
  %17 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %.018, i32 1
  %.0 = load i64, ptr %17, align 8, !tbaa !5
  %.not = icmp eq i64 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge.thread:                               ; preds = %2, %._crit_edge
  %18 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %1, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !13
  br label %27

20:                                               ; preds = %._crit_edge
  %21 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %1, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %27, label %24

24:                                               ; preds = %20
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %26 = load i64, ptr %25, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %20, %24, %._crit_edge.thread
  %.lcssa.sink = phi i64 [ %26, %24 ], [ %19, %._crit_edge.thread ], [ %16, %20 ]
  %28 = getelementptr inbounds [100010 x i64], ptr @max_flow, i64 0, i64 %0
  store i64 %.lcssa.sink, ptr %28, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void
}

; 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 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 = !{!"long long", !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 8, !6, i64 16}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 16}


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