; LLVM IR from eyangch/competitive-programming :: CSES/Dynamic_Programming/removal_game.ll (Z3dfsxx)

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

@x = external dso_local global [5000 x i64], align 16
@dp = external dso_local global [5000 x [5000 x i64]], align 16

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

12:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %52

13:                                               ; preds = %2
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds [5000 x [5000 x i64]], ptr @dp, i64 0, i64 %14
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds [5000 x i64], ptr %15, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = icmp sgt i64 %18, -9223372036854775808
  br i1 %19, label %20, label %26

20:                                               ; preds = %13
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds [5000 x [5000 x i64]], ptr @dp, i64 0, i64 %21
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds [5000 x i64], ptr %22, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  store i64 %25, ptr %3, align 8
  br label %52

26:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 -1000000000000000000, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds [5000 x i64], ptr @x, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = call noundef i64 @_Z3dfsxx(i64 noundef %31, i64 noundef %32)
  %34 = sub nsw i64 %29, %33
  store i64 %34, ptr %7, align 8, !tbaa !5
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %36 = load i64, ptr %35, align 8, !tbaa !5
  store i64 %36, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds [5000 x i64], ptr @x, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = sub nsw i64 %41, 1
  %43 = call noundef i64 @_Z3dfsxx(i64 noundef %40, i64 noundef %42)
  %44 = sub nsw i64 %39, %43
  store i64 %44, ptr %8, align 8, !tbaa !5
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %46 = load i64, ptr %45, align 8, !tbaa !5
  store i64 %46, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds [5000 x [5000 x i64]], ptr @dp, i64 0, i64 %48
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds [5000 x i64], ptr %49, i64 0, i64 %50
  store i64 %47, ptr %51, align 8, !tbaa !5
  store i64 %47, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %52

52:                                               ; preds = %26, %20, %12
  %53 = load i64, ptr %3, align 8
  ret i64 %53
}

; 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 @_ZSt3maxIxERKT_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"}


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

@x = external dso_local local_unnamed_addr global [5000 x i64], align 16
@dp = external dso_local local_unnamed_addr global [5000 x [5000 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3dfsxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = icmp sgt i64 %0, %1
  br i1 %6, label %25, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds [5000 x [5000 x i64]], ptr @dp, i64 0, i64 %0, i64 %1
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %9, -9223372036854775808
  br i1 %.not, label %10, label %25

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 -1000000000000000000, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %11 = getelementptr inbounds [5000 x i64], ptr @x, i64 0, i64 %0
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = add nsw i64 %0, 1
  %14 = tail call noundef i64 @_Z3dfsxx(i64 noundef %13, i64 noundef %1)
  %15 = sub nsw i64 %12, %14
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %17 = load i64, ptr %16, align 8, !tbaa !5
  store i64 %17, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %18 = getelementptr inbounds [5000 x i64], ptr @x, i64 0, i64 %1
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = add nsw i64 %1, -1
  %21 = call noundef i64 @_Z3dfsxx(i64 noundef %0, i64 noundef %20)
  %22 = sub nsw i64 %19, %21
  store i64 %22, ptr %5, align 8, !tbaa !5
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %24 = load i64, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  store i64 %24, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %25

25:                                               ; preds = %7, %2, %10
  %.0 = phi i64 [ %24, %10 ], [ 0, %2 ], [ %9, %7 ]
  ret i64 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { 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"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass