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

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

@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@sum = external dso_local global i64, align 8
@mod = 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @a)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) @b)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %8 = load i64, ptr @b, align 8, !tbaa !5
  %9 = add nsw i64 %8, 1
  store i64 %9, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %14, %0
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr @a, align 8, !tbaa !5
  %13 = icmp sle i64 %11, %12
  br i1 %13, label %14, label %26

14:                                               ; preds = %10
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr @mod, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = srem i64 %19, %18
  store i64 %20, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr @b, align 8, !tbaa !5
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  store i64 %23, ptr %2, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !9

26:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %44, %26
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr @b, align 8, !tbaa !5
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %27
  %34 = load i64, ptr @sum, align 8, !tbaa !5
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %35, %37
  %39 = load i64, ptr @mod, align 8, !tbaa !5
  %40 = srem i64 %38, %39
  %41 = add nsw i64 %34, %40
  %42 = load i64, ptr @mod, align 8, !tbaa !5
  %43 = srem i64 %41, %42
  store i64 %43, ptr @sum, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %33
  %45 = load i32, ptr %5, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !11
  br label %27, !llvm.loop !13

47:                                               ; preds = %32
  %48 = load i64, ptr @sum, align 8, !tbaa !5
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %48)
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %49, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  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)) #2 align 2

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

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

@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@sum = external dso_local local_unnamed_addr global i64, align 8
@mod = 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) @a)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @b)
  %3 = load i64, ptr @b, align 8, !tbaa !5
  %4 = load i64, ptr @a, align 8, !tbaa !5
  %.not14 = icmp slt i64 %4, 1
  br i1 %.not14, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %5 = add nsw i64 %3, 1
  %6 = load i64, ptr @mod, align 8, !tbaa !5
  %xtraiter = and i64 %4, 1
  %7 = icmp eq i64 %4, 1
  br i1 %7, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %4, 9223372036854775806
  br label %14

.preheader.loopexit.unr-lcssa:                    ; preds = %14, %.lr.ph
  %.lcssa25.ph = phi i64 [ poison, %.lr.ph ], [ %19, %14 ]
  %.01017.unr = phi i64 [ 0, %.lr.ph ], [ %19, %14 ]
  %.01215.unr = phi i64 [ %5, %.lr.ph ], [ %20, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %8 = add nsw i64 %.01017.unr, %.01215.unr
  %9 = srem i64 %8, %6
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %0
  %.010.lcssa = phi i64 [ 0, %0 ], [ %.lcssa25.ph, %.preheader.loopexit.unr-lcssa ], [ %9, %.preheader.loopexit.epilog-lcssa ]
  %10 = icmp sgt i64 %3, 1
  %sum.promoted = load i64, ptr @sum, align 8, !tbaa !5
  br i1 %10, label %.lr.ph19, label %.preheader._crit_edge

.lr.ph19:                                         ; preds = %.preheader
  %11 = load i64, ptr @mod, align 8, !tbaa !5
  %12 = add nsw i64 %3, -1
  %xtraiter28 = and i64 %12, 1
  %13 = icmp eq i64 %3, 2
  br i1 %13, label %._crit_edge.unr-lcssa, label %.lr.ph19.new

.lr.ph19.new:                                     ; preds = %.lr.ph19
  %unroll_iter31 = and i64 %12, -2
  br label %28

14:                                               ; preds = %14, %.lr.ph.new
  %.01017 = phi i64 [ 0, %.lr.ph.new ], [ %19, %14 ]
  %.01215 = phi i64 [ %5, %.lr.ph.new ], [ %20, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %14 ]
  %15 = add nsw i64 %.01017, %.01215
  %16 = srem i64 %15, %6
  %17 = add nsw i64 %.01215, %3
  %18 = add nsw i64 %16, %17
  %19 = srem i64 %18, %6
  %20 = add nsw i64 %17, %3
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %14, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %28, %.lr.ph19
  %.lcssa.ph = phi i64 [ poison, %.lr.ph19 ], [ %37, %28 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph19 ], [ %indvars.iv.next.1, %28 ]
  %.unr = phi i64 [ %sum.promoted, %.lr.ph19 ], [ %37, %28 ]
  %lcmp.mod29.not = icmp eq i64 %xtraiter28, 0
  br i1 %lcmp.mod29.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %21 = mul nsw i64 %indvars.iv.unr, %.010.lcssa
  %22 = srem i64 %21, %11
  %23 = add nsw i64 %22, %.unr
  %24 = srem i64 %23, %11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %24, %._crit_edge.epilog-lcssa ]
  store i64 %.lcssa, ptr @sum, align 8, !tbaa !5
  br label %.preheader._crit_edge

.preheader._crit_edge:                            ; preds = %.preheader, %._crit_edge
  %25 = phi i64 [ %.lcssa, %._crit_edge ], [ %sum.promoted, %.preheader ]
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %25)
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %26, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

28:                                               ; preds = %28, %.lr.ph19.new
  %indvars.iv = phi i64 [ 1, %.lr.ph19.new ], [ %indvars.iv.next.1, %28 ]
  %29 = phi i64 [ %sum.promoted, %.lr.ph19.new ], [ %37, %28 ]
  %niter32 = phi i64 [ 0, %.lr.ph19.new ], [ %niter32.next.1, %28 ]
  %30 = mul nsw i64 %indvars.iv, %.010.lcssa
  %31 = srem i64 %30, %11
  %32 = add nsw i64 %31, %29
  %33 = srem i64 %32, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = mul nsw i64 %indvars.iv.next, %.010.lcssa
  %35 = srem i64 %34, %11
  %36 = add nsw i64 %35, %33
  %37 = srem i64 %36, %11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter32.next.1 = add i64 %niter32, 2
  %niter32.ncmp.1 = icmp eq i64 %niter32.next.1, %unroll_iter31
  br i1 %niter32.ncmp.1, label %._crit_edge.unr-lcssa, label %28, !llvm.loop !11
}

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


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