; LLVM IR from eyangch/competitive-programming :: Codeforces/1509/c.ll (Z3dpfxx)

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dpfxx(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
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %8 = load i64, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %5, align 8, !tbaa !5
  %10 = icmp sgt i64 %8, %9
  br i1 %10, label %11, label %12

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

12:                                               ; preds = %2
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds [2000 x [2000 x i64]], ptr @dp, i64 0, i64 %13
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds [2000 x i64], ptr %14, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = sitofp i64 %17 to double
  %19 = fcmp une double %18, 1.000000e+17
  br i1 %19, label %20, label %26

20:                                               ; preds = %12
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds [2000 x [2000 x i64]], ptr @dp, i64 0, i64 %21
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds [2000 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 %49

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

49:                                               ; preds = %26, %20, %11
  %50 = load i64, ptr %3, align 8
  ret i64 %50
}

; 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)) #1

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

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"

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

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

6:                                                ; preds = %2
  %7 = getelementptr inbounds [2000 x [2000 x i64]], ptr @dp, i64 0, i64 %0, i64 %1
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = sitofp i64 %8 to double
  %10 = fcmp une double %9, 1.000000e+17
  br i1 %10, label %common.ret17, label %11

common.ret17:                                     ; preds = %6, %2, %11
  %common.ret17.op = phi i64 [ %23, %11 ], [ 0, %2 ], [ %8, %6 ]
  ret i64 %common.ret17.op

11:                                               ; preds = %6
  %12 = getelementptr inbounds [2000 x i64], ptr @s, i64 0, i64 %1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds [2000 x i64], ptr @s, i64 0, i64 %0
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = sub nsw i64 %13, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %17 = add nsw i64 %0, 1
  %18 = tail call noundef i64 @_Z3dpfxx(i64 noundef %17, i64 noundef %1)
  store i64 %18, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %19 = add nsw i64 %1, -1
  %20 = tail call noundef i64 @_Z3dpfxx(i64 noundef %0, i64 noundef %19)
  store i64 %20, ptr %4, align 8, !tbaa !5
  %21 = 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) %4)
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = add nsw i64 %22, %16
  store i64 %23, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %common.ret17
}

; 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

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

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

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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass