; LLVM IR from tangjz/acm-icpc :: 51nod (1822)

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

@t = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@iact = external dso_local global [200002 x i32], align 16
@n = external dso_local global i64, align 8
@r = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([200002 x i32], ptr @iact, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %25, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 200002
  br i1 %6, label %8, label %7

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

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sdiv i32 985661441, %9
  %11 = sext i32 %10 to i64
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = srem i32 985661441, %12
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %11, %17
  %19 = srem i64 %18, 985661441
  %20 = trunc i64 %19 to i32
  %21 = sub nsw i32 985661441, %20
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %8
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

28:                                               ; preds = %7
  store i32 1, ptr @iact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %51, %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 200002
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %54

33:                                               ; preds = %29
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %39, %44
  %46 = srem i64 %45, 985661441
  %47 = trunc i64 %46 to i32
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %49
  store i32 %47, ptr %50, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %33
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %29, !llvm.loop !11

54:                                               ; preds = %32
  %55 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %56

56:                                               ; preds = %69, %54
  %57 = load i32, ptr @t, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr @t, align 4, !tbaa !5
  %59 = icmp ne i32 %57, 0
  br i1 %59, label %60, label %72

60:                                               ; preds = %56
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m, ptr noundef @n, ptr noundef @r)
  call void @_Z5sievev()
  %62 = load i64, ptr @r, align 8, !tbaa !12
  %63 = srem i64 %62, 985661441
  store i64 %63, ptr @r, align 8, !tbaa !12
  %64 = icmp eq i64 %63, 1
  br i1 %64, label %65, label %67

65:                                               ; preds = %60
  %66 = call noundef i32 @_Z6solve1v()
  br label %69

67:                                               ; preds = %60
  %68 = call noundef i32 @_Z6solve2v()
  br label %69

69:                                               ; preds = %67, %65
  %70 = phi i32 [ %66, %65 ], [ %68, %67 ]
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %70)
  br label %56, !llvm.loop !14

72:                                               ; preds = %56
  ret i32 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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z5sievev() #3

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z6solve1v() #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z6solve2v() #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 = { 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 = !{!"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}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !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"

@t = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@iact = external dso_local local_unnamed_addr global [200002 x i32], align 16
@n = external dso_local global i64, align 8
@r = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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() local_unnamed_addr #0 {
  store i32 1, ptr getelementptr inbounds (i8, ptr @iact, i64 4), align 4, !tbaa !5
  br label %2

1:                                                ; preds = %2
  store i32 1, ptr @iact, align 16, !tbaa !5
  br label %20

2:                                                ; preds = %0, %2
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %2 ]
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  %4 = udiv i32 985661441, %3
  %5 = zext nneg i32 %4 to i64
  %6 = urem i32 985661441, %3
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = mul nsw i64 %10, %5
  %12 = srem i64 %11, 985661441
  %13 = trunc nsw i64 %12 to i32
  %14 = sub nsw i32 985661441, %13
  %15 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 200002
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !9

16:                                               ; preds = %20
  %17 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %18 = load i32, ptr @t, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr @t, align 4, !tbaa !5
  %.not13 = icmp eq i32 %18, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

20:                                               ; preds = %28, %1
  %21 = phi i64 [ 1, %1 ], [ %33, %28 ]
  %indvars.iv15 = phi i64 [ 1, %1 ], [ %indvars.iv.next16.1, %28 ]
  %22 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %indvars.iv15
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %21, %24
  %26 = srem i64 %25, 985661441
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr %22, align 4, !tbaa !5
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %exitcond18.not = icmp eq i64 %indvars.iv.next16, 200002
  br i1 %exitcond18.not, label %16, label %28, !llvm.loop !11

28:                                               ; preds = %20
  %29 = getelementptr inbounds [200002 x i32], ptr @iact, i64 0, i64 %indvars.iv.next16
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %26, %31
  %33 = srem i64 %32, 985661441
  %34 = trunc nsw i64 %33 to i32
  store i32 %34, ptr %29, align 4, !tbaa !5
  %indvars.iv.next16.1 = add nuw nsw i64 %indvars.iv15, 2
  br label %20

.lr.ph:                                           ; preds = %16, %43
  %35 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m, ptr noundef nonnull @n, ptr noundef nonnull @r)
  tail call void @_Z5sievev()
  %36 = load i64, ptr @r, align 8, !tbaa !12
  %37 = srem i64 %36, 985661441
  store i64 %37, ptr @r, align 8, !tbaa !12
  %38 = icmp eq i64 %37, 1
  br i1 %38, label %39, label %41

39:                                               ; preds = %.lr.ph
  %40 = tail call noundef i32 @_Z6solve1v()
  br label %43

41:                                               ; preds = %.lr.ph
  %42 = tail call noundef i32 @_Z6solve2v()
  br label %43

43:                                               ; preds = %41, %39
  %44 = phi i32 [ %40, %39 ], [ %42, %41 ]
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %44)
  %46 = load i32, ptr @t, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %46, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %43, %16
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z5sievev() local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z6solve1v() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z6solve2v() local_unnamed_addr #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 = { 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 = { 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}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}


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