; LLVM IR from tangjz/acm-icpc :: uoj (113)

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

@n = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@op = external dso_local global [3 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @sum, align 4, !tbaa !5
  store i32 1, ptr @cnt, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %4

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

8:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %39

9:                                                ; preds = %4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @op)
  %11 = load i8, ptr @op, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 38
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  %15 = load i32, ptr @cnt, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @cnt, align 4, !tbaa !5
  br label %35

17:                                               ; preds = %9
  %18 = load i32, ptr @sum, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = load i32, ptr @cnt, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = mul nsw i64 %19, %21
  %23 = srem i64 %22, 998244353
  %24 = trunc i64 %23 to i32
  store i32 %24, ptr @sum, align 4, !tbaa !5
  store i32 1, ptr @cnt, align 4, !tbaa !5
  %25 = load i32, ptr @sum, align 4, !tbaa !5
  %26 = load i32, ptr @ans, align 4, !tbaa !5
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr @ans, align 4, !tbaa !5
  %28 = icmp sge i32 %27, 998244353
  br i1 %28, label %29, label %33

29:                                               ; preds = %17
  %30 = load i32, ptr @ans, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 998244353
  store i32 %31, ptr @ans, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br label %33

33:                                               ; preds = %29, %17
  %34 = phi i1 [ false, %17 ], [ %32, %29 ]
  br label %35

35:                                               ; preds = %33, %14
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !10

39:                                               ; preds = %8
  %40 = load i32, ptr @sum, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = load i32, ptr @cnt, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %41, %43
  %45 = srem i64 %44, 998244353
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr @sum, align 4, !tbaa !5
  %47 = load i32, ptr @sum, align 4, !tbaa !5
  %48 = load i32, ptr @ans, align 4, !tbaa !5
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr @ans, align 4, !tbaa !5
  %50 = icmp sge i32 %49, 998244353
  br i1 %50, label %51, label %55

51:                                               ; preds = %39
  %52 = load i32, ptr @ans, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 998244353
  store i32 %53, ptr @ans, align 4, !tbaa !5
  %54 = icmp ne i32 %53, 0
  br label %55

55:                                               ; preds = %51, %39
  %56 = phi i1 [ false, %39 ], [ %54, %51 ]
  %57 = load i32, ptr @ans, align 4, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %57)
  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 i32 @printf(ptr noundef, ...) #1

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

@n = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@op = external dso_local global [3 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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 @n)
  store i32 1, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @sum, align 4, !tbaa !5
  store i32 1, ptr @cnt, align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not4 = icmp slt i32 %2, 2
  br i1 %.not4, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %33
  %.pre = load i32, ptr @sum, align 4, !tbaa !5
  %.pre6 = load i32, ptr @ans, align 4, !tbaa !5
  %3 = sext i32 %.pre to i64
  %4 = sext i32 %34 to i64
  %5 = mul nsw i64 %4, %3
  %6 = srem i64 %5, 998244353
  %7 = trunc nsw i64 %6 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %8 = phi i32 [ %.pre6, %._crit_edge.loopexit ], [ 1, %0 ]
  %9 = phi i32 [ %7, %._crit_edge.loopexit ], [ 1, %0 ]
  store i32 %9, ptr @sum, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = icmp sgt i32 %10, 998244352
  %12 = add nsw i32 %10, -998244353
  %spec.select = select i1 %11, i32 %12, i32 %10
  store i32 %spec.select, ptr @ans, align 4, !tbaa !5
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %spec.select)
  ret i32 0

.lr.ph:                                           ; preds = %0, %33
  %.05 = phi i32 [ %35, %33 ], [ 2, %0 ]
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @op)
  %15 = load i8, ptr @op, align 1, !tbaa !9
  %16 = icmp eq i8 %15, 38
  br i1 %16, label %17, label %20

17:                                               ; preds = %.lr.ph
  %18 = load i32, ptr @cnt, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  br label %33

20:                                               ; preds = %.lr.ph
  %21 = load i32, ptr @sum, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = load i32, ptr @cnt, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %24, %22
  %26 = srem i64 %25, 998244353
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr @sum, align 4, !tbaa !5
  store i32 1, ptr @cnt, align 4, !tbaa !5
  %28 = load i32, ptr @ans, align 4, !tbaa !5
  %29 = add nsw i32 %28, %27
  store i32 %29, ptr @ans, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 998244352
  br i1 %30, label %31, label %33

31:                                               ; preds = %20
  %32 = add nsw i32 %29, -998244353
  store i32 %32, ptr @ans, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %17, %31, %20
  %34 = phi i32 [ %19, %17 ], [ 1, %31 ], [ 1, %20 ]
  %35 = add nuw nsw i32 %.05, 1
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.05, %36
  br i1 %.not.not, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !10
}

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

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

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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