; LLVM IR from upupming/algorithm :: acwing/周赛/week-7/3760. 最大剩余油量.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"

@head = external dso_local global [300010 x i32], align 16
@ver = external dso_local global [600020 x i32], align 16
@edge = external dso_local global [600020 x i32], align 16
@Next = external dso_local global [600020 x i32], align 16
@w = external dso_local global [300010 x i32], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  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 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [300010 x i32], ptr @head, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %58, %2
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %63

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [600020 x i32], ptr @ver, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [600020 x i32], ptr @edge, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %10, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %21
  store i32 4, ptr %8, align 4
  br label %55

34:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = call noundef i64 @_Z3dfsii(i32 noundef %35, i32 noundef %36)
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = sub nsw i64 %37, %39
  store i64 %40, ptr %11, align 8, !tbaa !9
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = icmp sgt i64 %41, %42
  br i1 %43, label %44, label %47

44:                                               ; preds = %34
  %45 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %45, ptr %6, align 8, !tbaa !9
  %46 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %46, ptr %5, align 8, !tbaa !9
  br label %54

47:                                               ; preds = %34
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = icmp sgt i64 %48, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %47
  %52 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %52, ptr %6, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %51, %47
  br label %54

54:                                               ; preds = %53, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  store i32 0, ptr %8, align 4
  br label %55

55:                                               ; preds = %54, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %56 = load i32, ptr %8, align 4
  switch i32 %56, label %82 [
    i32 0, label %57
    i32 4, label %58
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57, %55
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [600020 x i32], ptr @Next, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %17, !llvm.loop !11

63:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = add nsw i64 %64, %65
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [300010 x i32], ptr @w, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = add nsw i64 %66, %71
  store i64 %72, ptr %12, align 8, !tbaa !9
  %73 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %74 = load i64, ptr %73, align 8, !tbaa !9
  store i64 %74, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [300010 x i32], ptr @w, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = add nsw i64 %75, %80
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %81

82:                                               ; preds = %55
  unreachable
}

; 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

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

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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@head = external dso_local local_unnamed_addr global [300010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [600020 x i32], align 16
@edge = external dso_local local_unnamed_addr global [600020 x i32], align 16
@Next = external dso_local local_unnamed_addr global [600020 x i32], align 16
@w = external dso_local local_unnamed_addr global [300010 x i32], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [300010 x i32], ptr @head, i64 0, i64 %4
  %.02529 = load i32, ptr %5, align 4, !tbaa !5
  %.not30 = icmp eq i32 %.02529, 0
  br i1 %.not30, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %28, %2
  %.022.lcssa = phi i64 [ 0, %2 ], [ %.224, %28 ]
  %.0.lcssa = phi i64 [ 0, %2 ], [ %.2, %28 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %6 = add nsw i64 %.0.lcssa, %.022.lcssa
  %7 = getelementptr inbounds [300010 x i32], ptr @w, i64 0, i64 %4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = add nsw i64 %6, %9
  store i64 %10, ptr %3, align 8, !tbaa !9
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %.0.lcssa, %14
  ret i64 %15

.lr.ph:                                           ; preds = %2, %28
  %.02533 = phi i32 [ %.025, %28 ], [ %.02529, %2 ]
  %.032 = phi i64 [ %.2, %28 ], [ 0, %2 ]
  %.02231 = phi i64 [ %.224, %28 ], [ 0, %2 ]
  %16 = sext i32 %.02533 to i64
  %17 = getelementptr inbounds [600020 x i32], ptr @ver, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, %1
  br i1 %19, label %28, label %20

20:                                               ; preds = %.lr.ph
  %21 = getelementptr inbounds [600020 x i32], ptr @edge, i64 0, i64 %16
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = tail call noundef i64 @_Z3dfsii(i32 noundef %18, i32 noundef %0)
  %24 = sext i32 %22 to i64
  %25 = sub nsw i64 %23, %24
  %26 = icmp sgt i64 %25, %.032
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  %spec.select = tail call i64 @llvm.smax.i64(i64 %25, i64 %.02231)
  br label %28

28:                                               ; preds = %27, %20, %.lr.ph
  %.224 = phi i64 [ %.02231, %.lr.ph ], [ %.032, %20 ], [ %spec.select, %27 ]
  %.2 = phi i64 [ %.032, %.lr.ph ], [ %25, %20 ], [ %.032, %27 ]
  %29 = getelementptr inbounds [600020 x i32], ptr @Next, i64 0, i64 %16
  %.025 = load i32, ptr %29, align 4, !tbaa !5
  %.not = icmp eq i32 %.025, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

; 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 @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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