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

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

@p = external dso_local global i32, align 4
@nk = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@sz = external dso_local global i32, align 4
@pp = external dso_local global i64, align 8
@prod = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@mod = external dso_local global i64, align 8
@f = external dso_local global [20 x i64], align 16
@N = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4calcx(i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %2

2:                                                ; preds = %5, %0
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @M, ptr noundef @N)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %5, label %12

5:                                                ; preds = %2
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i64 1, ptr @mod, align 8, !tbaa !5
  store i32 18, ptr @nk, align 4, !tbaa !9
  store i32 18, ptr @n, align 4, !tbaa !9
  store i32 2, ptr @p, align 4, !tbaa !9
  store i64 262144, ptr @pp, align 8, !tbaa !5
  store i32 512, ptr @sz, align 4, !tbaa !9
  %6 = load i64, ptr @pp, align 8, !tbaa !5
  call void @_Z4calcx(i64 noundef %6)
  %7 = load i64, ptr @f, align 16, !tbaa !5
  store i64 %7, ptr @prod, align 8, !tbaa !5
  call void @_Z5solvev()
  store i32 5, ptr @p, align 4, !tbaa !9
  store i64 3814697265625, ptr @pp, align 8, !tbaa !5
  store i32 1953125, ptr @sz, align 4, !tbaa !9
  %8 = load i64, ptr @pp, align 8, !tbaa !5
  call void @_Z4calcx(i64 noundef %8)
  %9 = load i64, ptr @f, align 16, !tbaa !5
  store i64 %9, ptr @prod, align 8, !tbaa !5
  call void @_Z5solvev()
  %10 = load i64, ptr @ans, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %10)
  br label %2, !llvm.loop !11

12:                                               ; preds = %2
  ret i32 0
}

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

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

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

@p = external dso_local local_unnamed_addr global i32, align 4
@nk = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@sz = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local local_unnamed_addr global i64, align 8
@prod = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@mod = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global [20 x i64], align 16
@N = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4calcx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @M, ptr noundef nonnull @N)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i64 1, ptr @mod, align 8, !tbaa !5
  store i32 18, ptr @nk, align 4, !tbaa !9
  store i32 18, ptr @n, align 4, !tbaa !9
  store i32 2, ptr @p, align 4, !tbaa !9
  store i64 262144, ptr @pp, align 8, !tbaa !5
  store i32 512, ptr @sz, align 4, !tbaa !9
  tail call void @_Z4calcx(i64 noundef 262144)
  %3 = load i64, ptr @f, align 16, !tbaa !5
  store i64 %3, ptr @prod, align 8, !tbaa !5
  tail call void @_Z5solvev()
  store i32 5, ptr @p, align 4, !tbaa !9
  store i64 3814697265625, ptr @pp, align 8, !tbaa !5
  store i32 1953125, ptr @sz, align 4, !tbaa !9
  tail call void @_Z4calcx(i64 noundef 3814697265625)
  %4 = load i64, ptr @f, align 16, !tbaa !5
  store i64 %4, ptr @prod, align 8, !tbaa !5
  tail call void @_Z5solvev()
  %5 = load i64, ptr @ans, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %5)
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @M, ptr noundef nonnull @N)
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %0
  ret i32 0
}

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

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

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass