; LLVM IR from AnneLivia/Competitive-Programming :: Online Judges/URI (3061)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@v = external dso_local global [1002 x [1002 x i32]], align 16
@vi = external dso_local global [1002 x [1002 x i32]], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@qtd = external dso_local global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3bfsii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr @qtd, align 4, !tbaa !5
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 4 dereferenceable(4) @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %39, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %42

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %35, %16
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %38

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1002 x [1002 x i32]], ptr @v, i64 0, i64 %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1002 x i32], ptr %25, i64 0, i64 %27
  store i32 0, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1002 x [1002 x i32]], ptr @vi, i64 0, i64 %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1002 x i32], ptr %31, i64 0, i64 %33
  store i32 0, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %22
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !9

38:                                               ; preds = %21
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !11

42:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %66, %42
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %69

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %62, %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr @m, align 4, !tbaa !5
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %65

54:                                               ; preds = %49
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1002 x [1002 x i32]], ptr @v, i64 0, i64 %56
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1002 x i32], ptr %57, i64 0, i64 %59
  %61 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %60)
  br label %62

62:                                               ; preds = %54
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %49, !llvm.loop !12

65:                                               ; preds = %53
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %43, !llvm.loop !13

69:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %100, %69
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = load i32, ptr @n, align 4, !tbaa !5
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %103

75:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %96, %75
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr @m, align 4, !tbaa !5
  %79 = icmp slt i32 %77, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %76
  store i32 17, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %99

81:                                               ; preds = %76
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1002 x [1002 x i32]], ptr @v, i64 0, i64 %83
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1002 x i32], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = icmp eq i32 %88, 1
  br i1 %89, label %90, label %95

90:                                               ; preds = %81
  %91 = load i32, ptr @qtd, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr @qtd, align 4, !tbaa !5
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z3bfsii(i32 noundef %93, i32 noundef %94)
  br label %95

95:                                               ; preds = %90, %81
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %8, align 4, !tbaa !5
  br label %76, !llvm.loop !14

99:                                               ; preds = %80
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %7, align 4, !tbaa !5
  br label %70, !llvm.loop !15

103:                                              ; preds = %74
  %104 = load i32, ptr @qtd, align 4, !tbaa !5
  %105 = sub nsw i32 %104, 1
  %106 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %105)
  %107 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %106, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #3

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #4

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 norecurse 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 = { "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 #4 = { inlinehint 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 #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@v = external dso_local global [1002 x [1002 x i32]], align 16
@vi = external dso_local local_unnamed_addr global [1002 x [1002 x i32]], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@qtd = external dso_local local_unnamed_addr global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3bfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  store i32 1, ptr @qtd, align 4, !tbaa !5
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 4 dereferenceable(4) @m)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not34 = icmp slt i32 %3, 0
  br i1 %.not34, label %._crit_edge43, label %.preheader31.lr.ph

.preheader31.lr.ph:                               ; preds = %0
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %.not2732 = icmp slt i32 %4, 0
  br i1 %.not2732, label %.preheader30, label %.preheader31.preheader

.preheader31.preheader:                           ; preds = %.preheader31.lr.ph
  %5 = add nuw i32 %4, 1
  %6 = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %6, 2
  %8 = add nuw i32 %3, 1
  %wide.trip.count = zext i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %9 = icmp ult i32 %3, 3
  br i1 %9, label %.preheader30.loopexit.unr-lcssa, label %.preheader31.preheader.new

.preheader31.preheader.new:                       ; preds = %.preheader31.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %.preheader31

.preheader31:                                     ; preds = %.preheader31, %.preheader31.preheader.new
  %indvar = phi i64 [ 0, %.preheader31.preheader.new ], [ %indvar.next.3, %.preheader31 ]
  %niter = phi i64 [ 0, %.preheader31.preheader.new ], [ %niter.next.3, %.preheader31 ]
  %10 = mul nuw nsw i64 %indvar, 4008
  %scevgep47 = getelementptr i8, ptr @vi, i64 %10
  %scevgep = getelementptr i8, ptr @v, i64 %10
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %scevgep, i8 0, i64 %7, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %scevgep47, i8 0, i64 %7, i1 false), !tbaa !5
  %11 = mul nuw i64 %indvar, 4008
  %12 = add nuw i64 %11, 4008
  %scevgep47.1 = getelementptr i8, ptr @vi, i64 %12
  %scevgep.1 = getelementptr i8, ptr @v, i64 %12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep.1, i8 0, i64 %7, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep47.1, i8 0, i64 %7, i1 false), !tbaa !5
  %13 = mul nuw i64 %indvar, 4008
  %14 = add nuw i64 %13, 8016
  %scevgep47.2 = getelementptr i8, ptr @vi, i64 %14
  %scevgep.2 = getelementptr i8, ptr @v, i64 %14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %scevgep.2, i8 0, i64 %7, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %scevgep47.2, i8 0, i64 %7, i1 false), !tbaa !5
  %15 = mul nuw i64 %indvar, 4008
  %16 = add nuw i64 %15, 12024
  %scevgep47.3 = getelementptr i8, ptr @vi, i64 %16
  %scevgep.3 = getelementptr i8, ptr @v, i64 %16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep.3, i8 0, i64 %7, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep47.3, i8 0, i64 %7, i1 false), !tbaa !5
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader30.loopexit.unr-lcssa, label %.preheader31, !llvm.loop !9

.preheader30.loopexit.unr-lcssa:                  ; preds = %.preheader31, %.preheader31.preheader
  %indvar.unr = phi i64 [ 0, %.preheader31.preheader ], [ %indvar.next.3, %.preheader31 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader30, label %.preheader31.epil

.preheader31.epil:                                ; preds = %.preheader30.loopexit.unr-lcssa, %.preheader31.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader31.epil ], [ %indvar.unr, %.preheader30.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader31.epil ], [ 0, %.preheader30.loopexit.unr-lcssa ]
  %17 = mul nuw nsw i64 %indvar.epil, 4008
  %scevgep47.epil = getelementptr i8, ptr @vi, i64 %17
  %scevgep.epil = getelementptr i8, ptr @v, i64 %17
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep.epil, i8 0, i64 %7, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep47.epil, i8 0, i64 %7, i1 false), !tbaa !5
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader30, label %.preheader31.epil, !llvm.loop !11

.preheader30:                                     ; preds = %.preheader30.loopexit.unr-lcssa, %.preheader31.epil, %.preheader31.lr.ph
  %18 = icmp ne i32 %3, 0
  %19 = load i32, ptr @m, align 4
  %20 = icmp sgt i32 %19, 0
  %or.cond = select i1 %18, i1 %20, i1 false
  br i1 %or.cond, label %.preheader29, label %._crit_edge43

.preheader29:                                     ; preds = %.preheader30, %._crit_edge37
  %21 = phi i32 [ %26, %._crit_edge37 ], [ %3, %.preheader30 ]
  %22 = phi i32 [ %27, %._crit_edge37 ], [ %19, %.preheader30 ]
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %._crit_edge37 ], [ 0, %.preheader30 ]
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge37

.preheader28:                                     ; preds = %._crit_edge37
  %24 = icmp sgt i32 %26, 0
  %.pr = load i32, ptr @m, align 4
  %25 = icmp sgt i32 %.pr, 0
  %or.cond66 = select i1 %24, i1 %25, i1 false
  br i1 %or.cond66, label %.preheader, label %._crit_edge43

._crit_edge37.loopexit:                           ; preds = %.lr.ph
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge37

._crit_edge37:                                    ; preds = %._crit_edge37.loopexit, %.preheader29
  %26 = phi i32 [ %.pre, %._crit_edge37.loopexit ], [ %21, %.preheader29 ]
  %27 = phi i32 [ %32, %._crit_edge37.loopexit ], [ %22, %.preheader29 ]
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %28 = sext i32 %26 to i64
  %29 = icmp slt i64 %indvars.iv.next52, %28
  br i1 %29, label %.preheader29, label %.preheader28, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader29, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader29 ]
  %30 = getelementptr inbounds [1002 x [1002 x i32]], ptr @v, i64 0, i64 %indvars.iv51, i64 %indvars.iv
  %31 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %30)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %._crit_edge37.loopexit, !llvm.loop !15

.preheader:                                       ; preds = %.preheader28, %._crit_edge41
  %35 = phi i32 [ %44, %._crit_edge41 ], [ %26, %.preheader28 ]
  %36 = phi i32 [ %45, %._crit_edge41 ], [ %.pr, %.preheader28 ]
  %37 = phi i32 [ %46, %._crit_edge41 ], [ %.pr, %.preheader28 ]
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %._crit_edge41 ], [ 0, %.preheader28 ]
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %.lr.ph40, label %._crit_edge41

.lr.ph40:                                         ; preds = %.preheader
  %39 = trunc nuw nsw i64 %indvars.iv57 to i32
  br label %49

._crit_edge43:                                    ; preds = %._crit_edge41, %0, %.preheader30, %.preheader28
  %40 = load i32, ptr @qtd, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  %42 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %41)
  %43 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %42, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

._crit_edge41.loopexit:                           ; preds = %58
  %.pre61 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge41

._crit_edge41:                                    ; preds = %._crit_edge41.loopexit, %.preheader
  %44 = phi i32 [ %.pre61, %._crit_edge41.loopexit ], [ %35, %.preheader ]
  %45 = phi i32 [ %59, %._crit_edge41.loopexit ], [ %36, %.preheader ]
  %46 = phi i32 [ %59, %._crit_edge41.loopexit ], [ %37, %.preheader ]
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %47 = sext i32 %44 to i64
  %48 = icmp slt i64 %indvars.iv.next58, %47
  br i1 %48, label %.preheader, label %._crit_edge43, !llvm.loop !16

49:                                               ; preds = %.lr.ph40, %58
  %50 = phi i32 [ %36, %.lr.ph40 ], [ %59, %58 ]
  %indvars.iv54 = phi i64 [ 0, %.lr.ph40 ], [ %indvars.iv.next55, %58 ]
  %51 = getelementptr inbounds [1002 x [1002 x i32]], ptr @v, i64 0, i64 %indvars.iv57, i64 %indvars.iv54
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %58

54:                                               ; preds = %49
  %55 = load i32, ptr @qtd, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @qtd, align 4, !tbaa !5
  %57 = trunc nuw nsw i64 %indvars.iv54 to i32
  tail call void @_Z3bfsii(i32 noundef %39, i32 noundef %57)
  %.pre60 = load i32, ptr @m, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %49, %54
  %59 = phi i32 [ %50, %49 ], [ %.pre60, %54 ]
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %60 = sext i32 %59 to i64
  %61 = icmp slt i64 %indvars.iv.next55, %60
  br i1 %61, label %49, label %._crit_edge41.loopexit, !llvm.loop !17
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 norecurse 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 = { "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 = { inlinehint 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10, !14}
!14 = !{!"llvm.loop.unswitch.partial.disable"}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10, !14}
!17 = distinct !{!17, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass