; LLVM IR from tangjz/acm-icpc :: lydsy/3308.ll (ZN8PrimDual7minCostEi)

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

@_ZN8PrimDual1NE = external dso_local global i32, align 4
@_ZN8PrimDual1SE = external dso_local global i32, align 4
@_ZN8PrimDual3sumE = external dso_local global i32, align 4
@_ZN8PrimDual4flowE = external dso_local global i32, align 4
@_ZN8PrimDual4costE = external dso_local global i32, align 4
@_ZN8PrimDual3visE = external dso_local global [200001 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8PrimDual4SPFAEv() #0

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8PrimDual8DijkstraEv() #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN8PrimDual3dfsEii(i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8PrimDual7minCostEi(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = call noundef zeroext i1 @_ZN8PrimDual4SPFAEv()
  br label %6

6:                                                ; preds = %41, %1
  br label %7

7:                                                ; preds = %34, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %35

10:                                               ; preds = %7
  %11 = load i32, ptr @_ZN8PrimDual1NE, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = mul i64 %12, 1
  call void @llvm.memset.p0.i64(ptr align 16 @_ZN8PrimDual3visE, i8 0, i64 %13, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %14 = load i32, ptr @_ZN8PrimDual1SE, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = call noundef i32 @_ZN8PrimDual3dfsEii(i32 noundef %14, i32 noundef %15)
  store i32 %16, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %10
  store i32 5, ptr %4, align 4
  br label %32

20:                                               ; preds = %10
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sub nsw i32 %22, %21
  store i32 %23, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @_ZN8PrimDual4flowE, align 4, !tbaa !5
  %26 = add nsw i32 %25, %24
  store i32 %26, ptr @_ZN8PrimDual4flowE, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr @_ZN8PrimDual3sumE, align 4, !tbaa !5
  %29 = mul nsw i32 %27, %28
  %30 = load i32, ptr @_ZN8PrimDual4costE, align 4, !tbaa !5
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr @_ZN8PrimDual4costE, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %32

32:                                               ; preds = %20, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %33 = load i32, ptr %4, align 4
  switch i32 %33, label %44 [
    i32 0, label %34
    i32 5, label %35
  ]

34:                                               ; preds = %32
  br label %7, !llvm.loop !9

35:                                               ; preds = %32, %7
  br label %36

36:                                               ; preds = %35
  %37 = call noundef zeroext i1 @_ZN8PrimDual8DijkstraEv()
  br i1 %37, label %38, label %41

38:                                               ; preds = %36
  %39 = load i32, ptr @_ZN8PrimDual3sumE, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 0
  br label %41

41:                                               ; preds = %38, %36
  %42 = phi i1 [ false, %36 ], [ %40, %38 ]
  br i1 %42, label %6, label %43, !llvm.loop !11

43:                                               ; preds = %41
  ret void

44:                                               ; preds = %32
  unreachable
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@_ZN8PrimDual1NE = external dso_local local_unnamed_addr global i32, align 4
@_ZN8PrimDual1SE = external dso_local local_unnamed_addr global i32, align 4
@_ZN8PrimDual3sumE = external dso_local local_unnamed_addr global i32, align 4
@_ZN8PrimDual4flowE = external dso_local local_unnamed_addr global i32, align 4
@_ZN8PrimDual4costE = external dso_local local_unnamed_addr global i32, align 4
@_ZN8PrimDual3visE = external dso_local local_unnamed_addr global [200001 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN8PrimDual4SPFAEv() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8PrimDual8DijkstraEv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN8PrimDual3dfsEii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8PrimDual7minCostEi(i32 noundef %0) local_unnamed_addr #2 {
  %2 = tail call noundef zeroext i1 @_ZN8PrimDual4SPFAEv()
  br label %3

3:                                                ; preds = %.thread, %1
  %.08 = phi i32 [ %0, %1 ], [ %.1.lcssa, %.thread ]
  %4 = icmp sgt i32 %.08, 0
  br i1 %4, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %3, %9
  %.113 = phi i32 [ %10, %9 ], [ %.08, %3 ]
  %5 = load i32, ptr @_ZN8PrimDual1NE, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @_ZN8PrimDual3visE, i8 0, i64 %6, i1 false)
  %7 = load i32, ptr @_ZN8PrimDual1SE, align 4, !tbaa !5
  %8 = tail call noundef i32 @_ZN8PrimDual3dfsEii(i32 noundef %7, i32 noundef %.113)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.thread, label %9

9:                                                ; preds = %.lr.ph
  %10 = sub nsw i32 %.113, %8
  %11 = load i32, ptr @_ZN8PrimDual4flowE, align 4, !tbaa !5
  %12 = add nsw i32 %11, %8
  store i32 %12, ptr @_ZN8PrimDual4flowE, align 4, !tbaa !5
  %13 = load i32, ptr @_ZN8PrimDual3sumE, align 4, !tbaa !5
  %14 = mul nsw i32 %13, %8
  %15 = load i32, ptr @_ZN8PrimDual4costE, align 4, !tbaa !5
  %16 = add nsw i32 %15, %14
  store i32 %16, ptr @_ZN8PrimDual4costE, align 4, !tbaa !5
  %17 = icmp sgt i32 %10, 0
  br i1 %17, label %.lr.ph, label %.thread

.thread:                                          ; preds = %9, %.lr.ph, %3
  %.1.lcssa = phi i32 [ %.08, %3 ], [ %.113, %.lr.ph ], [ %10, %9 ]
  %18 = tail call noundef zeroext i1 @_ZN8PrimDual8DijkstraEv()
  %19 = load i32, ptr @_ZN8PrimDual3sumE, align 4
  %20 = icmp slt i32 %19, 0
  %21 = select i1 %18, i1 %20, i1 false
  br i1 %21, label %3, label %22, !llvm.loop !9

22:                                               ; preds = %.thread
  ret void
}

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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