; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/150 Division 1/Problem C/C.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"

@cnt1 = external dso_local global i32, align 4
@cnt2 = external dso_local global i32, align 4
@g = external dso_local global [2000 x [2000 x i32]], align 16
@ok = external dso_local global [2000 x [2000 x i32]], align 16

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

7:                                                ; preds = %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @cnt1, align 4, !tbaa !5
  %10 = icmp sge i32 %8, %9
  br i1 %10, label %36, label %11

11:                                               ; preds = %7
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %36, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr @cnt2, align 4, !tbaa !5
  %17 = icmp sge i32 %15, %16
  br i1 %17, label %36, label %18

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2000 x [2000 x i32]], ptr @g, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2000 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %36, label %27

27:                                               ; preds = %18
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2000 x [2000 x i32]], ptr @ok, i64 0, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %37

36:                                               ; preds = %27, %18, %14, %11, %7, %2
  br label %56

37:                                               ; preds = %27
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2000 x [2000 x i32]], ptr @ok, i64 0, i64 %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2000 x i32], ptr %40, i64 0, i64 %42
  store i32 1, ptr %43, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %45, i32 noundef %46)
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %48, i32 noundef %49)
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  call void @_Z3dfsii(i32 noundef %50, i32 noundef %52)
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  call void @_Z3dfsii(i32 noundef %53, i32 noundef %55)
  br label %56

56:                                               ; preds = %37, %36
  ret void
}

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"

@cnt1 = external dso_local local_unnamed_addr global i32, align 4
@cnt2 = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local local_unnamed_addr global [2000 x [2000 x i32]], align 16
@ok = external dso_local local_unnamed_addr global [2000 x [2000 x i32]], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = zext nneg i32 %0 to i64
  %4 = icmp slt i32 %0, 0
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = add nuw nsw i32 %0, 1
  %6 = add nsw i32 %0, -1
  %7 = load i32, ptr @cnt1, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, %0
  %9 = icmp sgt i32 %1, -1
  %or.cond.not2328 = and i1 %9, %8
  %10 = load i32, ptr @cnt2, align 4
  %.not29 = icmp sgt i32 %10, %1
  %or.cond2030 = select i1 %or.cond.not2328, i1 %.not29, i1 false
  br i1 %or.cond2030, label %.lr.ph32, label %._crit_edge

.lr.ph32:                                         ; preds = %.lr.ph, %tailrecurse
  %.tr242531 = phi i32 [ %20, %tailrecurse ], [ %1, %.lr.ph ]
  %11 = zext nneg i32 %.tr242531 to i64
  %12 = getelementptr inbounds [2000 x [2000 x i32]], ptr @g, i64 0, i64 %3, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %._crit_edge, label %15

15:                                               ; preds = %.lr.ph32
  %16 = getelementptr inbounds [2000 x [2000 x i32]], ptr @ok, i64 0, i64 %3, i64 %11
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %15
  store i32 1, ptr %16, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef %5, i32 noundef %.tr242531)
  tail call void @_Z3dfsii(i32 noundef %6, i32 noundef %.tr242531)
  %19 = add nuw nsw i32 %.tr242531, 1
  tail call void @_Z3dfsii(i32 noundef %0, i32 noundef %19)
  %20 = add nsw i32 %.tr242531, -1
  %21 = load i32, ptr @cnt1, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, %0
  %23 = icmp sgt i32 %.tr242531, 0
  %or.cond.not23 = and i1 %23, %22
  %24 = load i32, ptr @cnt2, align 4
  %.not = icmp sge i32 %24, %.tr242531
  %or.cond20 = select i1 %or.cond.not23, i1 %.not, i1 false
  br i1 %or.cond20, label %.lr.ph32, label %._crit_edge

._crit_edge:                                      ; preds = %15, %.lr.ph32, %tailrecurse, %.lr.ph, %2
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass