; LLVM IR from lzyrapx/Competitive-Programming :: jisuanke/2018Game5 (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
@k = 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 nounwind uwtable
declare dso_local noundef i64 @_Z4calcx(i64 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 0, ptr %2, align 8, !tbaa !5
  %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) @n)
  %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) @k)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %8

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

12:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %54

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 1, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %47, %13
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr @n, align 8, !tbaa !5
  %17 = icmp sle i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %50

19:                                               ; preds = %14
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = call noundef i64 @_Z4calcx(i64 noundef %20)
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = call noundef i64 @_Z4calcx(i64 noundef %22)
  %24 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %21, i64 noundef %23)
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %26, label %46

26:                                               ; preds = %19
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = call noundef i64 @_Z4calcx(i64 noundef %27)
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = call noundef i64 @_Z4calcx(i64 noundef %29)
  %31 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %28, i64 noundef %30)
  %32 = load i64, ptr @k, align 8, !tbaa !5
  %33 = icmp sle i64 %31, %32
  br i1 %33, label %34, label %46

34:                                               ; preds = %26
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = call noundef i64 @_Z4calcx(i64 noundef %35)
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = call noundef i64 @_Z4calcx(i64 noundef %37)
  %39 = mul nsw i64 %36, %38
  %40 = icmp sgt i64 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %34
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %2, align 8, !tbaa !5
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %45 = srem i64 %44, 998244353
  store i64 %45, ptr %2, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %41, %34, %26, %19
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !9

50:                                               ; preds = %18
  br label %51

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

54:                                               ; preds = %12
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = srem i64 %55, 998244353
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %56)
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %57, i8 noundef signext 10)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %59 = load i32, ptr %1, align 4
  ret i32 %59
}

; 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)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) #0

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #4

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

attributes #0 = { mustprogress nounwind 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 = { 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 #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 = !{!"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}


; 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
@k = 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 nounwind uwtable
declare dso_local noundef i64 @_Z4calcx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %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 = 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) @k)
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %.not21 = icmp slt i64 %3, 1
  br i1 %.not21, label %._crit_edge24, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge
  %4 = phi i64 [ %8, %._crit_edge ], [ %3, %0 ]
  %.01423 = phi i64 [ %9, %._crit_edge ], [ 1, %0 ]
  %.01522 = phi i64 [ %.1.lcssa, %._crit_edge ], [ 0, %0 ]
  %.not1618 = icmp slt i64 %4, 1
  br i1 %.not1618, label %._crit_edge, label %.lr.ph

._crit_edge24.loopexit26:                         ; preds = %._crit_edge
  %5 = srem i64 %.1.lcssa, 998244353
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit26, %0
  %.015.lcssa = phi i64 [ 0, %0 ], [ %5, %._crit_edge24.loopexit26 ]
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.015.lcssa)
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %6, i8 noundef signext 10)
  ret i32 0

._crit_edge:                                      ; preds = %27, %.preheader
  %8 = phi i64 [ %4, %.preheader ], [ %29, %27 ]
  %.1.lcssa = phi i64 [ %.01522, %.preheader ], [ %.2, %27 ]
  %9 = add nuw nsw i64 %.01423, 1
  %.not.not = icmp slt i64 %.01423, %8
  br i1 %.not.not, label %.preheader, label %._crit_edge24.loopexit26, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %27
  %.020 = phi i64 [ %28, %27 ], [ 1, %.preheader ]
  %.119 = phi i64 [ %.2, %27 ], [ %.01522, %.preheader ]
  %10 = tail call noundef i64 @_Z4calcx(i64 noundef %.01423)
  %11 = tail call noundef i64 @_Z4calcx(i64 noundef %.020)
  %12 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %10, i64 noundef %11)
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %14, label %27

14:                                               ; preds = %.lr.ph
  %15 = tail call noundef i64 @_Z4calcx(i64 noundef %.01423)
  %16 = tail call noundef i64 @_Z4calcx(i64 noundef %.020)
  %17 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %15, i64 noundef %16)
  %18 = load i64, ptr @k, align 8, !tbaa !5
  %.not17 = icmp sgt i64 %17, %18
  br i1 %.not17, label %27, label %19

19:                                               ; preds = %14
  %20 = tail call noundef i64 @_Z4calcx(i64 noundef %.01423)
  %21 = tail call noundef i64 @_Z4calcx(i64 noundef %.020)
  %22 = mul nsw i64 %21, %20
  %23 = icmp sgt i64 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = add nsw i64 %.119, 1
  %26 = srem i64 %25, 998244353
  br label %27

27:                                               ; preds = %.lr.ph, %14, %19, %24
  %.2 = phi i64 [ %26, %24 ], [ %.119, %19 ], [ %.119, %14 ], [ %.119, %.lr.ph ]
  %28 = add nuw nsw i64 %.020, 1
  %29 = load i64, ptr @n, align 8, !tbaa !5
  %.not16.not = icmp slt i64 %.020, %29
  br i1 %.not16.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12
}

; 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 #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #3

; 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 #2 align 2

attributes #0 = { mustprogress nounwind 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 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" }

!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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass