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

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

@cnt = external dso_local global [5 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", 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
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %21, %0
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = srem i32 %15, 5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %14
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !11

24:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %50, %24
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %53

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = srem i32 %31, 5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %44

34:                                               ; preds = %30
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = srem i32 %35, 5
  %37 = sub nsw i32 5, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = add nsw i64 %42, %41
  store i64 %43, ptr %4, align 8, !tbaa !5
  br label %49

44:                                               ; preds = %30
  %45 = load i32, ptr @cnt, align 16, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = add nsw i64 %47, %46
  store i64 %48, ptr %4, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %44, %34
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !9
  br label %25, !llvm.loop !13

53:                                               ; preds = %29
  %54 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z2trIxJEEvT_DpRKT0_(i64 noundef %54)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2trIxJEEvT_DpRKT0_(i64 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@cnt = external dso_local local_unnamed_addr global [5 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %.not15 = icmp slt i32 %5, 1
  br i1 %.not15, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %xtraiter = and i32 %5, 1
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %5, 2147483646
  br label %.lr.ph

.preheader.loopexit.unr-lcssa.loopexit:           ; preds = %.lr.ph
  %7 = urem i32 %25, 5
  %8 = zext nneg i32 %7 to i64
  br label %.preheader.loopexit.unr-lcssa

.preheader.loopexit.unr-lcssa:                    ; preds = %.preheader.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.01016.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %8, %.preheader.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa
  %9 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %.01016.unr
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %9, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %0
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %.not1317 = icmp slt i32 %12, 1
  br i1 %.not1317, label %._crit_edge, label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %.preheader
  %xtraiter22 = and i32 %12, 1
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph20.preheader.new

.lr.ph20.preheader.new:                           ; preds = %.lr.ph20.preheader
  %unroll_iter25 = and i32 %12, 2147483646
  br label %.lr.ph20

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01016 = phi i32 [ 1, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %14 = urem i32 %.01016, 5
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = add nuw i32 %.01016, 1
  %20 = urem i32 %19, 5
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !5
  %25 = add nuw i32 %.01016, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph20
  %26 = urem i32 %39, 5
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph20.preheader
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph20.preheader ], [ %.1.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.019.unr = phi i32 [ 1, %.lr.ph20.preheader ], [ %26, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01118.unr = phi i64 [ 0, %.lr.ph20.preheader ], [ %.1.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod23.not = icmp eq i32 %xtraiter22, 0
  br i1 %lcmp.mod23.not, label %._crit_edge, label %.lr.ph20.epil

.lr.ph20.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %.not14.epil = icmp eq i32 %.019.unr, 0
  %27 = sub nuw nsw i32 5, %.019.unr
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %28
  %.pn.in.in.epil = select i1 %.not14.epil, ptr @cnt, ptr %29
  %.pn.in.epil = load i32, ptr %.pn.in.in.epil, align 4, !tbaa !5
  %.pn.epil = sext i32 %.pn.in.epil to i64
  %.1.epil = add nsw i64 %.01118.unr, %.pn.epil
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph20.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.011.lcssa = phi i64 [ 0, %.preheader ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %.lr.ph20.epil ]
  call void @_Z2trIxJEEvT_DpRKT0_(i64 noundef %.011.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

.lr.ph20:                                         ; preds = %.lr.ph20, %.lr.ph20.preheader.new
  %.019 = phi i32 [ 1, %.lr.ph20.preheader.new ], [ %39, %.lr.ph20 ]
  %.01118 = phi i64 [ 0, %.lr.ph20.preheader.new ], [ %.1.1, %.lr.ph20 ]
  %niter26 = phi i32 [ 0, %.lr.ph20.preheader.new ], [ %niter26.next.1, %.lr.ph20 ]
  %30 = urem i32 %.019, 5
  %.not14 = icmp eq i32 %30, 0
  %31 = sub nuw nsw i32 5, %30
  %32 = zext nneg i32 %31 to i64
  %33 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %32
  %.pn.in.in = select i1 %.not14, ptr @cnt, ptr %33
  %.pn.in = load i32, ptr %.pn.in.in, align 4, !tbaa !5
  %.pn = sext i32 %.pn.in to i64
  %.1 = add nsw i64 %.01118, %.pn
  %34 = add nuw i32 %.019, 1
  %35 = urem i32 %34, 5
  %.not14.1 = icmp eq i32 %35, 0
  %36 = sub nuw nsw i32 5, %35
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds [5 x i32], ptr @cnt, i64 0, i64 %37
  %.pn.in.in.1 = select i1 %.not14.1, ptr @cnt, ptr %38
  %.pn.in.1 = load i32, ptr %.pn.in.in.1, align 4, !tbaa !5
  %.pn.1 = sext i32 %.pn.in.1 to i64
  %.1.1 = add nsw i64 %.1, %.pn.1
  %39 = add nuw i32 %.019, 2
  %niter26.next.1 = add i32 %niter26, 2
  %niter26.ncmp.1 = icmp eq i32 %niter26.next.1, %unroll_iter25
  br i1 %niter26.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph20, !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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2trIxJEEvT_DpRKT0_(i64 noundef) local_unnamed_addr #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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}


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