; LLVM IR from tangjz/acm-icpc :: hdu (5446)

; 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
@k = external dso_local global i32, align 4
@prime = external dso_local global i32, align 4
@fact = external dso_local global [100001 x i32], align 16
@inv = external dso_local global [100001 x i32], align 16
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@mod = 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 [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; 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 uwtable
declare dso_local void @_Z3crtRxS_xx(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z1Cxx(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %7

7:                                                ; preds = %88, %0
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @t, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %91

11:                                               ; preds = %7
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @k)
  store i64 0, ptr @ans, align 8, !tbaa !9
  store i64 1, ptr @mod, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %85, %11
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @k, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 4, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %88

18:                                               ; preds = %13
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @prime)
  store i32 1, ptr @fact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %42, %18
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr @prime, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %45

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @fact, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %31, %33
  %35 = load i32, ptr @prime, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = srem i64 %34, %36
  %38 = trunc i64 %37 to i32
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100001 x i32], ptr @fact, i64 0, i64 %40
  store i32 %38, ptr %41, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %25
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !11

45:                                               ; preds = %24
  store i32 1, ptr getelementptr inbounds ([100001 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %75, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr @prime, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %78

51:                                               ; preds = %46
  %52 = load i32, ptr @prime, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = load i32, ptr @prime, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = sdiv i64 %55, %57
  %59 = load i32, ptr @prime, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = srem i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100001 x i32], ptr @inv, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = mul nsw i64 %58, %65
  %67 = load i32, ptr @prime, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = srem i64 %66, %68
  %70 = sub nsw i64 %53, %69
  %71 = trunc i64 %70 to i32
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100001 x i32], ptr @inv, i64 0, i64 %73
  store i32 %71, ptr %74, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %51
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !13

78:                                               ; preds = %50
  %79 = load i64, ptr @n, align 8, !tbaa !9
  %80 = load i64, ptr @m, align 8, !tbaa !9
  %81 = call noundef i32 @_Z1Cxx(i64 noundef %79, i64 noundef %80)
  %82 = sext i32 %81 to i64
  %83 = load i32, ptr @prime, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  call void @_Z3crtRxS_xx(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) @mod, i64 noundef %82, i64 noundef %84)
  br label %85

85:                                               ; preds = %78
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !14

88:                                               ; preds = %17
  %89 = load i64, ptr @ans, align 8, !tbaa !9
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %89)
  br label %7, !llvm.loop !15

91:                                               ; preds = %7
  ret i32 0
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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
@k = external dso_local global i32, align 4
@prime = external dso_local global i32, align 4
@fact = external dso_local local_unnamed_addr global [100001 x i32], align 16
@inv = external dso_local local_unnamed_addr global [100001 x i32], align 16
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@mod = 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 [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3crtRxS_xx(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z1Cxx(i64 noundef, i64 noundef) 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not25 = icmp eq i32 %2, 0
  br i1 %.not25, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %0, %._crit_edge24
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @k)
  store i64 0, ptr @ans, align 8, !tbaa !9
  store i64 1, ptr @mod, align 8, !tbaa !9
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph23, label %._crit_edge24

._crit_edge24.loopexit:                           ; preds = %._crit_edge20
  %.pre = load i64, ptr @ans, align 8, !tbaa !9
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit, %.lr.ph27
  %7 = phi i64 [ %.pre, %._crit_edge24.loopexit ], [ 0, %.lr.ph27 ]
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %7)
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !11

.lr.ph23:                                         ; preds = %.lr.ph27, %._crit_edge20
  %.01321 = phi i32 [ %41, %._crit_edge20 ], [ 0, %.lr.ph27 ]
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @prime)
  store i32 1, ptr @fact, align 16, !tbaa !5
  %12 = load i32, ptr @prime, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph23
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br label %._crit_edge20

.lr.ph:                                           ; preds = %.lr.ph23
  %14 = zext nneg i32 %12 to i64
  %15 = add nsw i64 %14, -1
  %xtraiter = and i64 %15, 1
  %16 = icmp eq i32 %12, 2
  br i1 %16, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %15, -2
  br label %23

._crit_edge.unr-lcssa:                            ; preds = %23, %.lr.ph
  %.unr = phi i64 [ 1, %.lr.ph ], [ %32, %23 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %sext.epil = shl i64 %.unr, 32
  %17 = ashr exact i64 %sext.epil, 32
  %18 = mul nsw i64 %17, %indvars.iv.unr
  %19 = srem i64 %18, %14
  %20 = trunc nsw i64 %19 to i32
  %21 = getelementptr inbounds [100001 x i32], ptr @fact, i64 0, i64 %indvars.iv.unr
  store i32 %20, ptr %21, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  %.not35 = icmp eq i32 %12, 2
  br i1 %.not35, label %._crit_edge20, label %.lr.ph19

.lr.ph19:                                         ; preds = %._crit_edge
  %22 = zext nneg i32 %12 to i64
  br label %44

23:                                               ; preds = %23, %.lr.ph.new
  %24 = phi i64 [ 1, %.lr.ph.new ], [ %32, %23 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %23 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %23 ]
  %sext = shl i64 %24, 32
  %25 = ashr exact i64 %sext, 32
  %26 = mul nsw i64 %25, %indvars.iv
  %27 = srem i64 %26, %14
  %28 = trunc nsw i64 %27 to i32
  %29 = getelementptr inbounds [100001 x i32], ptr @fact, i64 0, i64 %indvars.iv
  store i32 %28, ptr %29, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext.1 = shl i64 %27, 32
  %30 = ashr exact i64 %sext.1, 32
  %31 = mul nsw i64 %30, %indvars.iv.next
  %32 = srem i64 %31, %14
  %33 = trunc nsw i64 %32 to i32
  %34 = getelementptr inbounds [100001 x i32], ptr @fact, i64 0, i64 %indvars.iv.next
  store i32 %33, ptr %34, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %23, !llvm.loop !13

._crit_edge20:                                    ; preds = %44, %._crit_edge.thread, %._crit_edge
  %35 = load i64, ptr @n, align 8, !tbaa !9
  %36 = load i64, ptr @m, align 8, !tbaa !9
  %37 = tail call noundef i32 @_Z1Cxx(i64 noundef %35, i64 noundef %36)
  %38 = sext i32 %37 to i64
  %39 = load i32, ptr @prime, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  tail call void @_Z3crtRxS_xx(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) @mod, i64 noundef %38, i64 noundef %40)
  %41 = add nuw nsw i32 %.01321, 1
  %42 = load i32, ptr @k, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %.lr.ph23, label %._crit_edge24.loopexit, !llvm.loop !14

44:                                               ; preds = %.lr.ph19, %44
  %indvars.iv30 = phi i64 [ 2, %.lr.ph19 ], [ %indvars.iv.next31, %44 ]
  %45 = udiv i64 %22, %indvars.iv30
  %46 = trunc nuw nsw i64 %indvars.iv30 to i32
  %47 = urem i32 %12, %46
  %48 = zext nneg i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @inv, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %45, %51
  %53 = srem i64 %52, %22
  %54 = trunc i64 %53 to i32
  %55 = sub i32 %12, %54
  %56 = getelementptr inbounds [100001 x i32], ptr @inv, i64 0, i64 %indvars.iv30
  store i32 %55, ptr %56, align 4, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %22
  br i1 %exitcond34.not, label %._crit_edge20, label %44, !llvm.loop !15

._crit_edge28:                                    ; preds = %._crit_edge24, %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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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