; LLVM IR from eyangch/competitive-programming :: Codeforces/245/h.ll (Z4dpf2ii)

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

@dp2 = external dso_local global [5000 x [5000 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4dpf1ii(i32 noundef, i32 noundef) #0

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

9:                                                ; preds = %2
  store i32 0, ptr %3, align 4
  br label %55

10:                                               ; preds = %2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp2, i64 0, i64 %12
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5000 x i32], ptr %13, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = xor i32 %17, -1
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %28

20:                                               ; preds = %10
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp2, i64 0, i64 %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [5000 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4
  br label %55

28:                                               ; preds = %10
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = call noundef zeroext i1 @_Z4dpf1ii(i32 noundef %29, i32 noundef %30)
  %32 = zext i1 %31 to i32
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = call noundef i32 @_Z4dpf2ii(i32 noundef %34, i32 noundef %35)
  %37 = add nsw i32 %32, %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = call noundef i32 @_Z4dpf2ii(i32 noundef %38, i32 noundef %40)
  %42 = add nsw i32 %37, %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = call noundef i32 @_Z4dpf2ii(i32 noundef %44, i32 noundef %46)
  %48 = sub nsw i32 %42, %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp2, i64 0, i64 %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [5000 x i32], ptr %51, i64 0, i64 %53
  store i32 %48, ptr %54, align 4, !tbaa !5
  store i32 %48, ptr %3, align 4
  br label %55

55:                                               ; preds = %28, %20, %9
  %56 = load i32, ptr %3, align 4
  ret i32 %56
}

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

!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"}


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

@dp2 = external dso_local local_unnamed_addr global [5000 x [5000 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4dpf1ii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4dpf2ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %1, %0
  br i1 %3, label %common.ret19, label %4

4:                                                ; preds = %2
  %5 = sext i32 %0 to i64
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp2, i64 0, i64 %5, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, -1
  br i1 %.not, label %9, label %common.ret19

common.ret19:                                     ; preds = %4, %2, %9
  %common.ret19.op = phi i32 [ %19, %9 ], [ 0, %2 ], [ %8, %4 ]
  ret i32 %common.ret19.op

9:                                                ; preds = %4
  %10 = tail call noundef zeroext i1 @_Z4dpf1ii(i32 noundef %0, i32 noundef %1)
  %11 = zext i1 %10 to i32
  %12 = add nsw i32 %0, 1
  %13 = tail call noundef i32 @_Z4dpf2ii(i32 noundef %12, i32 noundef %1)
  %14 = add nsw i32 %13, %11
  %15 = add nsw i32 %1, -1
  %16 = tail call noundef i32 @_Z4dpf2ii(i32 noundef %0, i32 noundef %15)
  %17 = add nsw i32 %14, %16
  %18 = tail call noundef i32 @_Z4dpf2ii(i32 noundef %12, i32 noundef %15)
  %19 = sub i32 %17, %18
  store i32 %19, ptr %7, align 4, !tbaa !5
  br label %common.ret19
}

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

!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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass