; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/117 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_ostream" = type { ptr, %"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 }

@d = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@day = external dso_local global [2000 x i32], align 16
@cnt = external dso_local global i32, align 4
@cur = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_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 i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @d)
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %16, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %19

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %14)
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

19:                                               ; preds = %10
  %20 = load i32, ptr @day, align 16, !tbaa !5
  store i32 %20, ptr @cur, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %46, %19
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %49

26:                                               ; preds = %21
  %27 = load i32, ptr @cur, align 4, !tbaa !5
  %28 = load i32, ptr @d, align 4, !tbaa !5
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %26
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr @cur, align 4, !tbaa !5
  br label %45

35:                                               ; preds = %26
  %36 = load i32, ptr @d, align 4, !tbaa !5
  %37 = load i32, ptr @cur, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  %39 = load i32, ptr @cnt, align 4, !tbaa !5
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr @cnt, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr @cur, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %35, %30
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !11

49:                                               ; preds = %25
  %50 = load i32, ptr @cnt, align 4, !tbaa !5
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %50)
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %51, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3 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 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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}


; 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_ostream" = type { ptr, %"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 }

@d = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@day = external dso_local global [2000 x i32], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4
@cur = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@_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 i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @d)
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %5 = load i32, ptr @day, align 16, !tbaa !5
  store i32 %5, ptr @cur, align 4, !tbaa !5
  br label %._crit_edge._crit_edge

._crit_edge:                                      ; preds = %.lr.ph
  %6 = load i32, ptr @day, align 16, !tbaa !5
  store i32 %6, ptr @cur, align 4, !tbaa !5
  %7 = icmp sgt i32 %13, 1
  br i1 %7, label %.lr.ph15, label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge.thread, %._crit_edge
  %.pre = load i32, ptr @cnt, align 4, !tbaa !5
  br label %21

.lr.ph15:                                         ; preds = %._crit_edge
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !5
  %8 = load i32, ptr @d, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %13 to i64
  %9 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %9, 1
  %10 = icmp eq i32 %13, 2
  br i1 %10, label %._crit_edge16.unr-lcssa, label %.lr.ph15.new

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %11 = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %indvars.iv
  %12 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge16.unr-lcssa:                          ; preds = %37, %.lr.ph15
  %.lcssa.ph = phi i32 [ poison, %.lr.ph15 ], [ %38, %37 ]
  %storemerge.lcssa.ph = phi i32 [ poison, %.lr.ph15 ], [ %storemerge.1, %37 ]
  %indvars.iv19.unr = phi i64 [ 1, %.lr.ph15 ], [ %indvars.iv.next20.1, %37 ]
  %storemerge1112.unr = phi i32 [ %6, %.lr.ph15 ], [ %storemerge.1, %37 ]
  %.unr = phi i32 [ %cnt.promoted, %.lr.ph15 ], [ %38, %37 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge16, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge16.unr-lcssa
  %16 = icmp eq i32 %storemerge1112.unr, %8
  br i1 %16, label %._crit_edge16.epilog-lcssa, label %17

17:                                               ; preds = %.epil.preheader
  %18 = sub i32 %8, %storemerge1112.unr
  %19 = add nsw i32 %18, %.unr
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  br label %._crit_edge16.epilog-lcssa

._crit_edge16.epilog-lcssa:                       ; preds = %17, %.epil.preheader
  %20 = phi i32 [ %.unr, %.epil.preheader ], [ %19, %17 ]
  %storemerge.in.epil = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %indvars.iv19.unr
  %storemerge.epil = load i32, ptr %storemerge.in.epil, align 4, !tbaa !5
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %._crit_edge16.unr-lcssa, %._crit_edge16.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge16.unr-lcssa ], [ %20, %._crit_edge16.epilog-lcssa ]
  %storemerge.lcssa = phi i32 [ %storemerge.lcssa.ph, %._crit_edge16.unr-lcssa ], [ %storemerge.epil, %._crit_edge16.epilog-lcssa ]
  store i32 %storemerge.lcssa, ptr @cur, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %._crit_edge._crit_edge, %._crit_edge16
  %22 = phi i32 [ %.pre, %._crit_edge._crit_edge ], [ %.lcssa, %._crit_edge16 ]
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %22)
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

25:                                               ; preds = %37, %.lr.ph15.new
  %indvars.iv19 = phi i64 [ 1, %.lr.ph15.new ], [ %indvars.iv.next20.1, %37 ]
  %storemerge1112 = phi i32 [ %6, %.lr.ph15.new ], [ %storemerge.1, %37 ]
  %26 = phi i32 [ %cnt.promoted, %.lr.ph15.new ], [ %38, %37 ]
  %niter = phi i64 [ 0, %.lr.ph15.new ], [ %niter.next.1, %37 ]
  %27 = icmp eq i32 %storemerge1112, %8
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = sub i32 %8, %storemerge1112
  %30 = add nsw i32 %29, %26
  store i32 %30, ptr @cnt, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %25, %28
  %32 = phi i32 [ %26, %25 ], [ %30, %28 ]
  %storemerge.in = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %indvars.iv19
  %storemerge = load i32, ptr %storemerge.in, align 4, !tbaa !5
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %33 = icmp eq i32 %storemerge, %8
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = sub i32 %8, %storemerge
  %36 = add nsw i32 %35, %32
  store i32 %36, ptr @cnt, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %34, %31
  %38 = phi i32 [ %32, %31 ], [ %36, %34 ]
  %storemerge.in.1 = getelementptr inbounds [2000 x i32], ptr @day, i64 0, i64 %indvars.iv.next20
  %storemerge.1 = load i32, ptr %storemerge.in.1, align 4, !tbaa !5
  %indvars.iv.next20.1 = add nuw nsw i64 %indvars.iv19, 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.unr-lcssa, label %25, !llvm.loop !11
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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 #3 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 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 = { nofree nounwind "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 = { 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 = { 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 = !{!"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}


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