; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Codeforces Round #807 (Div. 2)/B. Mark the Dust Sweeper.ll (Z5solvev)

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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %13 = call ptr @llvm.stacksave.p0()
  store ptr %13, ptr %2, align 8
  %14 = alloca i64, i64 %12, align 16
  store i64 %12, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr %14, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %15, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = mul nuw i64 8, %12
  %18 = udiv i64 %17, 8
  %19 = getelementptr inbounds i64, ptr %16, i64 %18
  store ptr %19, ptr %6, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %29, %0
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = icmp ne ptr %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %32

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %26, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %27)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %29

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %30, i32 1
  store ptr %31, ptr %5, align 8, !tbaa !9
  br label %20

32:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %60, %32
  %34 = load i64, ptr %10, align 8, !tbaa !5
  %35 = load i64, ptr %1, align 8, !tbaa !5
  %36 = sub nsw i64 %35, 1
  %37 = icmp slt i64 %34, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %63

39:                                               ; preds = %33
  %40 = load i64, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds i64, ptr %14, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %39
  %45 = load i64, ptr %8, align 8, !tbaa !5
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  br label %60

48:                                               ; preds = %44, %39
  store i64 1, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds i64, ptr %14, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %14, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = icmp eq i64 %54, 0
  %56 = zext i1 %55 to i64
  %57 = add nsw i64 %51, %56
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr %9, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %48, %47
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %10, align 8, !tbaa !5
  br label %33, !llvm.loop !11

63:                                               ; preds = %38
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %64)
  %66 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %65, ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %67 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; 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 noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
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 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call ptr @llvm.stacksave.p0()
  %5 = alloca i64, i64 %3, align 16
  %6 = getelementptr inbounds i64, ptr %5, i64 %3
  %.not20 = icmp eq i64 %3, 0
  br i1 %.not20, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 1
  br i1 %8, label %.lr.ph25.preheader, label %._crit_edge

.lr.ph25.preheader:                               ; preds = %.preheader
  %9 = add nsw i64 %7, -1
  %xtraiter = and i64 %9, 1
  %10 = icmp eq i64 %7, 2
  br i1 %10, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph25.preheader.new

.lr.ph25.preheader.new:                           ; preds = %.lr.ph25.preheader
  %unroll_iter = and i64 %9, -2
  br label %.lr.ph25

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01921 = phi ptr [ %12, %.lr.ph ], [ %5, %0 ]
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %.01921)
  %12 = getelementptr inbounds i8, ptr %.01921, i64 8
  %.not = icmp eq ptr %12, %6
  br i1 %.not, label %.preheader, label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph25, %.lr.ph25.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph25.preheader ], [ %.1.1, %.lr.ph25 ]
  %.024.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %31, %.lr.ph25 ]
  %.01623.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %.1.1, %.lr.ph25 ]
  %.01722.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %.118.1, %.lr.ph25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph25.epil

.lr.ph25.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %13 = getelementptr inbounds i64, ptr %5, i64 %.024.unr
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = or i64 %14, %.01722.unr
  %or.cond.epil.not = icmp eq i64 %15, 0
  %16 = call i64 @llvm.umax.i64(i64 %14, i64 1)
  %17 = select i1 %or.cond.epil.not, i64 0, i64 %16
  %.1.epil = add nsw i64 %17, %.01623.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph25.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.016.lcssa = phi i64 [ 0, %.preheader ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %.lr.ph25.epil ]
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.016.lcssa)
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull @.str)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret void

.lr.ph25:                                         ; preds = %.lr.ph25, %.lr.ph25.preheader.new
  %.024 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %31, %.lr.ph25 ]
  %.01623 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %.1.1, %.lr.ph25 ]
  %.01722 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %.118.1, %.lr.ph25 ]
  %niter = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %niter.next.1, %.lr.ph25 ]
  %20 = getelementptr inbounds i64, ptr %5, i64 %.024
  %21 = load i64, ptr %20, align 16, !tbaa !5
  %22 = or i64 %21, %.01722
  %or.cond = icmp ne i64 %22, 0
  %23 = call i64 @llvm.umax.i64(i64 %21, i64 1)
  %.118 = zext i1 %or.cond to i64
  %24 = select i1 %or.cond, i64 %23, i64 0
  %.1 = add nsw i64 %24, %.01623
  %25 = or disjoint i64 %.024, 1
  %26 = getelementptr inbounds i64, ptr %5, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = or i64 %27, %.118
  %or.cond.1 = icmp ne i64 %28, 0
  %29 = call i64 @llvm.umax.i64(i64 %27, i64 1)
  %.118.1 = zext i1 %or.cond.1 to i64
  %30 = select i1 %or.cond.1, i64 %29, i64 0
  %.1.1 = add nsw i64 %30, %.1
  %31 = add nuw nsw i64 %.024, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph25, !llvm.loop !9
}

; 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 noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass