; LLVM IR from abeaumont/competitive-programming :: kattis/mincut.ll (Z3dfsix)

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

@n = external dso_local global i32, align 4
@s = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@l = external dso_local global [500 x i32], align 16
@p = external dso_local global [500 x i32], align 16
@g = external dso_local global [500 x [500 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsix(i32 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %46

11:                                               ; preds = %2
  br label %12

12:                                               ; preds = %16, %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr @s, align 4, !tbaa !5
  %15 = icmp ne i32 %13, %14
  br i1 %15, label %16, label %45

16:                                               ; preds = %12
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [500 x i64], ptr %23, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = sub nsw i64 %27, %17
  store i64 %28, ptr %26, align 8, !tbaa !9
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [500 x i64], ptr %32, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = add nsw i64 %39, %29
  store i64 %40, ptr %38, align 8, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %12, !llvm.loop !11

45:                                               ; preds = %12
  store i1 true, ptr %3, align 1
  br label %96

46:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %90, %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 4, ptr %7, align 4
  br label %93

52:                                               ; preds = %47
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [500 x i32], ptr @l, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [500 x i32], ptr @l, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = icmp eq i32 %56, %61
  br i1 %62, label %63, label %89

63:                                               ; preds = %52
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %65
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [500 x i64], ptr %66, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !9
  %71 = icmp ne i64 %70, 0
  br i1 %71, label %72, label %89

72:                                               ; preds = %63
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %75
  store i32 %73, ptr %76, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %79
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [500 x i64], ptr %80, i64 0, i64 %82
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %83)
  %85 = load i64, ptr %84, align 8, !tbaa !9
  %86 = call noundef zeroext i1 @_Z3dfsix(i32 noundef %77, i64 noundef %85)
  br i1 %86, label %87, label %88

87:                                               ; preds = %72
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %93

88:                                               ; preds = %72
  br label %89

89:                                               ; preds = %88, %63, %52
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %6, align 4, !tbaa !5
  br label %47, !llvm.loop !13

93:                                               ; preds = %87, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %94 = load i32, ptr %7, align 4
  switch i32 %94, label %98 [
    i32 4, label %95
    i32 1, label %96
  ]

95:                                               ; preds = %93
  store i1 false, ptr %3, align 1
  br label %96

96:                                               ; preds = %95, %93, %45
  %97 = load i1, ptr %3, align 1
  ret i1 %97

98:                                               ; preds = %93
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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)) #2

; 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 = { 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"}
!13 = distinct !{!13, !12}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global i32, align 4
@t = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global [500 x i32], align 16
@p = external dso_local local_unnamed_addr global [500 x i32], align 16
@g = external dso_local global [500 x [500 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3dfsix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  store i64 %1, ptr %3, align 8, !tbaa !5
  %4 = load i32, ptr @t, align 4, !tbaa !9
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %.preheader, label %.preheader26

.preheader26:                                     ; preds = %2
  %6 = load i32, ptr @n, align 4, !tbaa !9
  %.not2528 = icmp sgt i32 %6, 0
  br i1 %.not2528, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader26
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [500 x i32], ptr @l, i64 0, i64 %7
  br label %20

.preheader:                                       ; preds = %2
  %9 = load i32, ptr @s, align 4, !tbaa !9
  %.not2432 = icmp eq i32 %9, %0
  br i1 %.not2432, label %.loopexit, label %.lr.ph34

.lr.ph34:                                         ; preds = %.preheader, %.lr.ph34
  %.02033 = phi i32 [ %12, %.lr.ph34 ], [ %0, %.preheader ]
  %10 = sext i32 %.02033 to i64
  %11 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %13, i64 %10
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = sub nsw i64 %15, %1
  store i64 %16, ptr %14, align 8, !tbaa !5
  %17 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %10, i64 %13
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = add nsw i64 %18, %1
  store i64 %19, ptr %17, align 8, !tbaa !5
  %.not24 = icmp eq i32 %12, %9
  br i1 %.not24, label %.loopexit, label %.lr.ph34, !llvm.loop !11

20:                                               ; preds = %.lr.ph, %36
  %21 = phi i32 [ %6, %.lr.ph ], [ %37, %36 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %36 ]
  %22 = getelementptr inbounds [500 x i32], ptr @l, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  %26 = icmp eq i32 %23, %25
  br i1 %26, label %27, label %36

27:                                               ; preds = %20
  %28 = getelementptr inbounds [500 x [500 x i64]], ptr @g, i64 0, i64 %7, i64 %indvars.iv
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %36, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds [500 x i32], ptr @p, i64 0, i64 %indvars.iv
  store i32 %0, ptr %31, align 4, !tbaa !9
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %28)
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  %35 = call noundef zeroext i1 @_Z3dfsix(i32 noundef %34, i64 noundef %33)
  br i1 %35, label %.loopexit, label %._crit_edge

._crit_edge:                                      ; preds = %30
  %.pre = load i32, ptr @n, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %._crit_edge, %20, %27
  %37 = phi i32 [ %.pre, %._crit_edge ], [ %21, %20 ], [ %21, %27 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = sext i32 %37 to i64
  %.not25 = icmp slt i64 %indvars.iv.next, %38
  br i1 %.not25, label %20, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %30, %36, %.lr.ph34, %.preheader26, %.preheader
  %.1 = phi i1 [ true, %.preheader ], [ false, %.preheader26 ], [ true, %.lr.ph34 ], [ true, %30 ], [ false, %36 ]
  ret i1 %.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 #1

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 = { 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" }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass