; LLVM IR from eyangch/competitive-programming :: Codeforces/1675/g.ll (Z7upd_minxx)

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

@M = external dso_local global i64, align 8
@dp = external dso_local global [251 x [251 x [251 x i64]]], align 16
@mn = external dso_local global [251 x [251 x [251 x i64]]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7upd_minxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @dp, i64 0, i64 %6
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds [251 x [251 x i64]], ptr %7, i64 0, i64 %8
  %10 = load i64, ptr @M, align 8, !tbaa !5
  %11 = getelementptr inbounds [251 x i64], ptr %9, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %13
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds [251 x [251 x i64]], ptr %14, i64 0, i64 %15
  %17 = load i64, ptr @M, align 8, !tbaa !5
  %18 = getelementptr inbounds [251 x i64], ptr %16, i64 0, i64 %17
  store i64 %12, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %19 = load i64, ptr @M, align 8, !tbaa !5
  %20 = sub nsw i64 %19, 1
  store i64 %20, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %47, %2
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = icmp sge i64 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %50

25:                                               ; preds = %21
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %26
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds [251 x [251 x i64]], ptr %27, i64 0, i64 %28
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  %32 = getelementptr inbounds [251 x i64], ptr %29, i64 0, i64 %31
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @dp, i64 0, i64 %33
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds [251 x [251 x i64]], ptr %34, i64 0, i64 %35
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds [251 x i64], ptr %36, i64 0, i64 %37
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef nonnull align 8 dereferenceable(8) %38)
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %41
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds [251 x [251 x i64]], ptr %42, i64 0, i64 %43
  %45 = load i64, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds [251 x i64], ptr %44, i64 0, i64 %45
  store i64 %40, ptr %46, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %25
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = add nsw i64 %48, -1
  store i64 %49, ptr %5, align 8, !tbaa !5
  br label %21, !llvm.loop !9

50:                                               ; preds = %24
  ret void
}

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@M = external dso_local local_unnamed_addr global i64, align 8
@dp = external dso_local global [251 x [251 x [251 x i64]]], align 16
@mn = external dso_local global [251 x [251 x [251 x i64]]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7upd_minxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @M, align 8, !tbaa !5
  %4 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @dp, i64 0, i64 %0, i64 %1, i64 %3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %0, i64 %1, i64 %3
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = icmp sgt i64 %3, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.0.in15 = phi i64 [ %.0, %.lr.ph ], [ %3, %2 ]
  %.0 = add nsw i64 %.0.in15, -1
  %8 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %0, i64 %1, i64 %.0.in15
  %9 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @dp, i64 0, i64 %0, i64 %1, i64 %.0
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds [251 x [251 x [251 x i64]]], ptr @mn, i64 0, i64 %0, i64 %1, i64 %.0
  store i64 %11, ptr %12, align 8, !tbaa !5
  %13 = icmp ugt i64 %.0.in15, 1
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass