; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/124 Division 1/Problem B/B.ll (Z3dfsiiii)

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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@grid = external dso_local global [1501 x [1501 x i32]], align 16
@v = external dso_local global [1501 x [1501 x %"struct.std::pair"]], align 16
@vi = external dso_local global [1501 x [1501 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::pair", align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr %8, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1501 x [1501 x i32]], ptr @grid, i64 0, i64 %12
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1501 x i32], ptr %13, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  br label %116

20:                                               ; preds = %4
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1501 x [1501 x i32]], ptr @vi, i64 0, i64 %22
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1501 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %53

29:                                               ; preds = %20
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1501 x [1501 x %"struct.std::pair"]], ptr @v, i64 0, i64 %31
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1501 x %"struct.std::pair"], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds %"struct.std::pair", ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = icmp ne i32 %37, %38
  br i1 %39, label %51, label %40

40:                                               ; preds = %29
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1501 x [1501 x %"struct.std::pair"]], ptr @v, i64 0, i64 %42
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1501 x %"struct.std::pair"], ptr %43, i64 0, i64 %45
  %47 = getelementptr inbounds %"struct.std::pair", ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = icmp ne i32 %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %40, %29
  store i1 true, ptr %5, align 1
  br label %116

52:                                               ; preds = %40
  store i1 false, ptr %5, align 1
  br label %116

53:                                               ; preds = %20
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1501 x [1501 x i32]], ptr @vi, i64 0, i64 %55
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1501 x i32], ptr %56, i64 0, i64 %58
  store i32 1, ptr %59, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %60 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  store i64 %60, ptr %10, align 4
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1501 x [1501 x %"struct.std::pair"]], ptr @v, i64 0, i64 %62
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1501 x %"struct.std::pair"], ptr %63, i64 0, i64 %65
  %67 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %66, ptr noundef nonnull align 4 dereferenceable(8) %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = srem i32 %72, %73
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %69, i32 noundef %70, i32 noundef %74, i32 noundef %75)
  br i1 %76, label %77, label %78

77:                                               ; preds = %53
  store i1 true, ptr %5, align 1
  br label %116

78:                                               ; preds = %53
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = sub nsw i32 %79, 1
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = sub nsw i32 %82, 1
  %84 = load i32, ptr @n, align 4, !tbaa !5
  %85 = add nsw i32 %83, %84
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = srem i32 %85, %86
  %88 = load i32, ptr %9, align 4, !tbaa !5
  %89 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %80, i32 noundef %81, i32 noundef %87, i32 noundef %88)
  br i1 %89, label %90, label %91

90:                                               ; preds = %78
  store i1 true, ptr %5, align 1
  br label %116

91:                                               ; preds = %78
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  %95 = load i32, ptr %8, align 4, !tbaa !5
  %96 = load i32, ptr %9, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  %98 = load i32, ptr @m, align 4, !tbaa !5
  %99 = srem i32 %97, %98
  %100 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %92, i32 noundef %94, i32 noundef %95, i32 noundef %99)
  br i1 %100, label %101, label %102

101:                                              ; preds = %91
  store i1 true, ptr %5, align 1
  br label %116

102:                                              ; preds = %91
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = sub nsw i32 %104, 1
  %106 = load i32, ptr %8, align 4, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !5
  %108 = sub nsw i32 %107, 1
  %109 = load i32, ptr @m, align 4, !tbaa !5
  %110 = add nsw i32 %108, %109
  %111 = load i32, ptr @m, align 4, !tbaa !5
  %112 = srem i32 %110, %111
  %113 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %103, i32 noundef %105, i32 noundef %106, i32 noundef %112)
  br i1 %113, label %114, label %115

114:                                              ; preds = %102
  store i1 true, ptr %5, align 1
  br label %116

115:                                              ; preds = %102
  store i1 false, ptr %5, align 1
  br label %116

116:                                              ; preds = %115, %114, %101, %90, %77, %52, %51, %19
  %117 = load i1, ptr %5, align 1
  ret i1 %117
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2 align 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@grid = external dso_local local_unnamed_addr global [1501 x [1501 x i32]], align 16
@v = external dso_local global [1501 x [1501 x %"struct.std::pair"]], align 16
@vi = external dso_local local_unnamed_addr global [1501 x [1501 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.std::pair", align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %2 to i64
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds [1501 x [1501 x i32]], ptr @grid, i64 0, i64 %8, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %59, label %13

13:                                               ; preds = %4
  %14 = getelementptr inbounds [1501 x [1501 x i32]], ptr @vi, i64 0, i64 %8, i64 %9
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %22, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds [1501 x [1501 x %"struct.std::pair"]], ptr @v, i64 0, i64 %8, i64 %9
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %.not20 = icmp eq i32 %18, %0
  br i1 %.not20, label %19, label %59

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %17, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %.not21 = icmp ne i32 %21, %1
  br label %59

22:                                               ; preds = %13
  store i32 1, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %23 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  store i64 %23, ptr %7, align 8
  %24 = getelementptr inbounds [1501 x [1501 x %"struct.std::pair"]], ptr @v, i64 0, i64 %8, i64 %9
  %25 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %24, ptr noundef nonnull align 4 dereferenceable(8) %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = add nsw i32 %2, 1
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = srem i32 %29, %30
  %32 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %27, i32 noundef %28, i32 noundef %31, i32 noundef %3)
  br i1 %32, label %59, label %33

33:                                               ; preds = %22
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = add nsw i32 %2, -1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  %40 = srem i32 %39, %38
  %41 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %35, i32 noundef %36, i32 noundef %40, i32 noundef %3)
  br i1 %41, label %59, label %42

42:                                               ; preds = %33
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = add nsw i32 %3, 1
  %47 = load i32, ptr @m, align 4, !tbaa !5
  %48 = srem i32 %46, %47
  %49 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %43, i32 noundef %45, i32 noundef %2, i32 noundef %48)
  br i1 %49, label %59, label %50

50:                                               ; preds = %42
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = add nsw i32 %52, -1
  %54 = add nsw i32 %3, -1
  %55 = load i32, ptr @m, align 4, !tbaa !5
  %56 = add nsw i32 %54, %55
  %57 = srem i32 %56, %55
  %58 = call noundef zeroext i1 @_Z3dfsiiii(i32 noundef %51, i32 noundef %53, i32 noundef %2, i32 noundef %57)
  br label %59

59:                                               ; preds = %19, %50, %42, %33, %22, %16, %4
  %.0 = phi i1 [ false, %4 ], [ true, %16 ], [ true, %22 ], [ true, %33 ], [ true, %42 ], [ %58, %50 ], [ %.not21, %19 ]
  ret i1 %.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: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 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 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass