; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Educational Codeforces Round 140 (Rated for Div. 2)/B. Block Towers/_967496a5 (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 i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %7 = 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)
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = call ptr @llvm.stacksave.p0()
  store ptr %9, ptr %2, align 8
  %10 = alloca i64, i64 %8, align 16
  store i64 %8, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %20, %0
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %1, align 8, !tbaa !5
  %14 = icmp slt i64 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %23

16:                                               ; preds = %11
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i64, ptr %10, i64 %17
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %18)
  br label %20

20:                                               ; preds = %16
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = add nsw i64 %21, 1
  store i64 %22, ptr %4, align 8, !tbaa !5
  br label %11, !llvm.loop !9

23:                                               ; preds = %15
  %24 = getelementptr inbounds i64, ptr %10, i64 1
  %25 = load i64, ptr %1, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr %10, i64 %25
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef %24, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 1, ptr %5, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %53, %23
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %1, align 8, !tbaa !5
  %30 = icmp slt i64 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %56

32:                                               ; preds = %27
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %10, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %10, i64 0
  %37 = load i64, ptr %36, align 16, !tbaa !5
  %38 = icmp sgt i64 %35, %37
  br i1 %38, label %39, label %52

39:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i64, ptr %10, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i64, ptr %10, i64 0
  %44 = load i64, ptr %43, align 16, !tbaa !5
  %45 = sub nsw i64 %42, %44
  %46 = add nsw i64 %45, 1
  %47 = sdiv i64 %46, 2
  store i64 %47, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds i64, ptr %10, i64 0
  %50 = load i64, ptr %49, align 16, !tbaa !5
  %51 = add nsw i64 %50, %48
  store i64 %51, ptr %49, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %52

52:                                               ; preds = %39, %32
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr %5, align 8, !tbaa !5
  br label %27, !llvm.loop !11

56:                                               ; preds = %31
  %57 = getelementptr inbounds i64, ptr %10, i64 0
  %58 = load i64, ptr %57, align 16, !tbaa !5
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %58)
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %59, ptr noundef @.str)
  %61 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %61)
  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 dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) #3

; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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" }

@_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) #4
  %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 = load i64, ptr %1, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %6, %0 ], [ %17, %.lr.ph ]
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  %9 = getelementptr inbounds i64, ptr %5, i64 %.lcssa
  call void @_ZSt4sortIPlEvT_S1_(ptr noundef nonnull %8, ptr noundef nonnull %9)
  %10 = load i64, ptr %1, align 8, !tbaa !5
  %11 = icmp sgt i64 %10, 1
  %.pre = load i64, ptr %5, align 16, !tbaa !5
  br i1 %11, label %.lr.ph15.preheader, label %._crit_edge16

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

.lr.ph15.preheader.new:                           ; preds = %.lr.ph15.preheader
  %unroll_iter = and i64 %12, -2
  %invariant.gep = getelementptr inbounds i8, ptr %5, i64 8
  br label %.lr.ph15

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.012 = phi i64 [ %16, %.lr.ph ], [ 0, %0 ]
  %14 = getelementptr inbounds i64, ptr %5, i64 %.012
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %14)
  %16 = add nuw nsw i64 %.012, 1
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge16.loopexit.unr-lcssa:                 ; preds = %47, %.lr.ph15.preheader
  %.lcssa22.ph = phi i64 [ poison, %.lr.ph15.preheader ], [ %48, %47 ]
  %.unr = phi i64 [ %.pre, %.lr.ph15.preheader ], [ %48, %47 ]
  %.0813.unr = phi i64 [ 1, %.lr.ph15.preheader ], [ %49, %47 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge16, label %.lr.ph15.epil

.lr.ph15.epil:                                    ; preds = %._crit_edge16.loopexit.unr-lcssa
  %19 = getelementptr inbounds i64, ptr %5, i64 %.0813.unr
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = icmp sgt i64 %20, %.unr
  br i1 %21, label %22, label %._crit_edge16

22:                                               ; preds = %.lr.ph15.epil
  %23 = add i64 %20, 1
  %24 = sub i64 %23, %.unr
  %25 = sdiv i64 %24, 2
  %26 = add nsw i64 %25, %.unr
  store i64 %26, ptr %5, align 16, !tbaa !5
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %._crit_edge16.loopexit.unr-lcssa, %22, %.lr.ph15.epil, %._crit_edge
  %27 = phi i64 [ %.pre, %._crit_edge ], [ %.lcssa22.ph, %._crit_edge16.loopexit.unr-lcssa ], [ %.unr, %.lr.ph15.epil ], [ %26, %22 ]
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %27)
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull @.str)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void

.lr.ph15:                                         ; preds = %47, %.lr.ph15.preheader.new
  %30 = phi i64 [ %.pre, %.lr.ph15.preheader.new ], [ %48, %47 ]
  %.0813 = phi i64 [ 1, %.lr.ph15.preheader.new ], [ %49, %47 ]
  %niter = phi i64 [ 0, %.lr.ph15.preheader.new ], [ %niter.next.1, %47 ]
  %31 = getelementptr inbounds i64, ptr %5, i64 %.0813
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = icmp sgt i64 %32, %30
  br i1 %33, label %34, label %.lr.ph15.1

34:                                               ; preds = %.lr.ph15
  %35 = add i64 %32, 1
  %36 = sub i64 %35, %30
  %37 = sdiv i64 %36, 2
  %38 = add nsw i64 %37, %30
  store i64 %38, ptr %5, align 16, !tbaa !5
  br label %.lr.ph15.1

.lr.ph15.1:                                       ; preds = %.lr.ph15, %34
  %39 = phi i64 [ %30, %.lr.ph15 ], [ %38, %34 ]
  %gep = getelementptr inbounds i64, ptr %invariant.gep, i64 %.0813
  %40 = load i64, ptr %gep, align 8, !tbaa !5
  %41 = icmp sgt i64 %40, %39
  br i1 %41, label %42, label %47

42:                                               ; preds = %.lr.ph15.1
  %43 = add i64 %40, 1
  %44 = sub i64 %43, %39
  %45 = sdiv i64 %44, 2
  %46 = add nsw i64 %45, %39
  store i64 %46, ptr %5, align 16, !tbaa !5
  br label %47

47:                                               ; preds = %42, %.lr.ph15.1
  %48 = phi i64 [ %39, %.lr.ph15.1 ], [ %46, %42 ]
  %49 = add nuw nsw i64 %.0813, 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_edge16.loopexit.unr-lcssa, label %.lr.ph15, !llvm.loop !11
}

; 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 dso_local void @_ZSt4sortIPlEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; 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

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 = { 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"}
!11 = distinct !{!11, !10}


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