; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/308 Division 2/Problem B (B)

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

@n = external dso_local global i64, align 8
@cnt = external dso_local global i64, align 8
@pp = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp slt i64 %4, 10
  br i1 %5, label %6, label %10

6:                                                ; preds = %0
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %7)
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  br label %47

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

11:                                               ; preds = %40, %10
  %12 = load i64, ptr @pp, align 8, !tbaa !5
  %13 = load i64, ptr @n, align 8, !tbaa !5
  %14 = icmp sle i64 %12, %13
  br i1 %14, label %15, label %43

15:                                               ; preds = %11
  %16 = load i64, ptr @pp, align 8, !tbaa !5
  %17 = mul nsw i64 %16, 10
  %18 = load i64, ptr @n, align 8, !tbaa !5
  %19 = icmp sle i64 %17, %18
  br i1 %19, label %20, label %31

20:                                               ; preds = %15
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr @pp, align 8, !tbaa !5
  %23 = mul nsw i64 %22, 10
  %24 = load i64, ptr @pp, align 8, !tbaa !5
  %25 = sub nsw i64 %23, %24
  %26 = mul nsw i64 %21, %25
  %27 = load i64, ptr @cnt, align 8, !tbaa !5
  %28 = add nsw i64 %27, %26
  store i64 %28, ptr @cnt, align 8, !tbaa !5
  %29 = load i64, ptr @pp, align 8, !tbaa !5
  %30 = mul nsw i64 %29, 10
  store i64 %30, ptr @pp, align 8, !tbaa !5
  br label %40

31:                                               ; preds = %15
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = load i64, ptr @n, align 8, !tbaa !5
  %34 = load i64, ptr @pp, align 8, !tbaa !5
  %35 = sub nsw i64 %33, %34
  %36 = add nsw i64 %35, 1
  %37 = mul nsw i64 %32, %36
  %38 = load i64, ptr @cnt, align 8, !tbaa !5
  %39 = add nsw i64 %38, %37
  store i64 %39, ptr @cnt, align 8, !tbaa !5
  br label %43

40:                                               ; preds = %20
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !9

43:                                               ; preds = %31, %11
  %44 = load i64, ptr @cnt, align 8, !tbaa !5
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %44)
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %45, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %47

47:                                               ; preds = %43, %6
  %48 = load i32, ptr %1, align 4
  ret i32 %48
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 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)) #2

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

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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" }

@n = external dso_local global i64, align 8
@cnt = external dso_local local_unnamed_addr global i64, align 8
@pp = external dso_local local_unnamed_addr global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = icmp slt i64 %2, 10
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %0
  store i64 9, ptr @cnt, align 8, !tbaa !5
  %pp.promoted = load i64, ptr @pp, align 8, !tbaa !5
  %.not12 = icmp sgt i64 %pp.promoted, %2
  br i1 %.not12, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %5 = mul nsw i64 %pp.promoted, 10
  %.not917 = icmp sgt i64 %5, %2
  br i1 %.not917, label %.lr.ph._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %6 = phi i64 [ %13, %.lr.ph ], [ %5, %.lr.ph.preheader ]
  %7 = phi i64 [ %11, %.lr.ph ], [ 9, %.lr.ph.preheader ]
  %8 = phi i64 [ %6, %.lr.ph ], [ %pp.promoted, %.lr.ph.preheader ]
  %.01318 = phi i64 [ %12, %.lr.ph ], [ 2, %.lr.ph.preheader ]
  %9 = mul i64 %.01318, 9
  %10 = mul i64 %9, %8
  %11 = add nsw i64 %7, %10
  %12 = add nuw nsw i64 %.01318, 1
  %13 = mul nsw i64 %6, 10
  %.not9 = icmp sgt i64 %13, %2
  br i1 %.not9, label %.lr.ph._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph._crit_edge.loopexit:                       ; preds = %.lr.ph
  store i64 %11, ptr @cnt, align 8, !tbaa !5
  store i64 %6, ptr @pp, align 8, !tbaa !5
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph._crit_edge.loopexit, %.lr.ph.preheader
  %.013.lcssa = phi i64 [ 2, %.lr.ph.preheader ], [ %12, %.lr.ph._crit_edge.loopexit ]
  %.lcssa16 = phi i64 [ %pp.promoted, %.lr.ph.preheader ], [ %6, %.lr.ph._crit_edge.loopexit ]
  %.lcssa = phi i64 [ 9, %.lr.ph.preheader ], [ %11, %.lr.ph._crit_edge.loopexit ]
  %14 = add nuw nsw i64 %2, 1
  %15 = sub i64 %14, %.lcssa16
  %16 = mul nsw i64 %15, %.013.lcssa
  %17 = add nsw i64 %.lcssa, %16
  store i64 %17, ptr @cnt, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph._crit_edge, %4, %0
  %.sink15 = phi i64 [ %2, %0 ], [ 9, %4 ], [ %17, %.lr.ph._crit_edge ]
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.sink15)
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 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 #1 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)) #2

attributes #0 = { 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 #1 = { 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 #2 = { 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" }

!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 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass