; LLVM IR from abeaumont/competitive-programming :: kattis/openpitmining.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"

@n = external dso_local global i32, align 4
@l = external dso_local global [202 x i32], align 16
@p = external dso_local global [202 x i32], align 16
@c = external dso_local global [202 x [202 x i32]], align 16

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

12:                                               ; preds = %2
  br label %13

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

16:                                               ; preds = %13
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [202 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 [202 x [202 x i32]], ptr @c, i64 0, i64 %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [202 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sub nsw i32 %27, %17
  store i32 %28, ptr %26, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [202 x [202 x i32]], ptr @c, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [202 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 [202 x i32], ptr %32, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, %29
  store i32 %40, ptr %38, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [202 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 %13, !llvm.loop !9

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

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 = %91, %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = icmp sle i32 %48, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %47
  store i32 4, ptr %7, align 4
  br label %94

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

64:                                               ; preds = %53
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [202 x [202 x i32]], ptr @c, i64 0, i64 %66
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [202 x i32], ptr %67, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %73, label %90

73:                                               ; preds = %64
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [202 x i32], ptr @p, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [202 x [202 x i32]], ptr @c, i64 0, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [202 x i32], ptr %81, i64 0, i64 %83
  %85 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %84, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = call noundef zeroext i1 @_Z3dfsii(i32 noundef %78, i32 noundef %86)
  br i1 %87, label %88, label %89

88:                                               ; preds = %73
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %94

89:                                               ; preds = %73
  br label %90

90:                                               ; preds = %89, %64, %53
  br label %91

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

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

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

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

99:                                               ; preds = %94
  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 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 = 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"

@n = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global [202 x i32], align 16
@p = external dso_local local_unnamed_addr global [202 x i32], align 16
@c = external dso_local global [202 x [202 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %.preheader, label %.preheader25

.preheader25:                                     ; preds = %2
  %.not27 = icmp sgt i32 %4, -2
  br i1 %.not27, label %.lr.ph, label %.loopexit

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

.preheader:                                       ; preds = %2
  %.not2431 = icmp eq i32 %0, 0
  br i1 %.not2431, label %.loopexit, label %.lr.ph33

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

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

26:                                               ; preds = %19
  %27 = getelementptr inbounds [202 x [202 x i32]], ptr @c, i64 0, i64 %7, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %30, label %36

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

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

36:                                               ; preds = %._crit_edge, %19, %26
  %37 = phi i32 [ %.pre, %._crit_edge ], [ %20, %19 ], [ %20, %26 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = sext i32 %37 to i64
  %.not.not = icmp sgt i64 %indvars.iv, %38
  br i1 %.not.not, label %.loopexit, label %19, !llvm.loop !11

.loopexit:                                        ; preds = %30, %36, %.lr.ph33, %.preheader25, %.preheader
  %.1 = phi i1 [ true, %.preheader ], [ false, %.preheader25 ], [ true, %.lr.ph33 ], [ true, %30 ], [ false, %36 ]
  ret i1 %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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 = !{!"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}


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