; LLVM IR from tangjz/acm-icpc :: lydsy (4338)

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

@tot = external dso_local global i32, align 4
@prime = external dso_local global [44722 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@vis = external dso_local global [44723 x i8], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 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 noundef i32 @_Z4calciii(i32 noundef, i32 noundef, i32 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %64, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 44722
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [44723 x i8], ptr @vis, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %24, label %18

18:                                               ; preds = %12
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %18, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sdiv i32 44722, %25
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %59, %24
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr @tot, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %27
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br label %38

38:                                               ; preds = %31, %27
  %39 = phi i1 [ false, %27 ], [ %37, %31 ]
  br i1 %39, label %41, label %40

40:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  br label %62

41:                                               ; preds = %38
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = mul nsw i32 %42, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [44723 x i8], ptr @vis, i64 0, i64 %48
  store i8 1, ptr %49, align 1, !tbaa !9
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = srem i32 %50, %54
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %41
  store i32 5, ptr %3, align 4
  br label %62

58:                                               ; preds = %41
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !13

62:                                               ; preds = %57, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !15

67:                                               ; preds = %11
  %68 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @b, ptr noundef @mod)
  %69 = load i32, ptr @m, align 4, !tbaa !5
  %70 = load i32, ptr @b, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = sub nsw i32 %71, 1
  %73 = load i32, ptr @m, align 4, !tbaa !5
  %74 = load i32, ptr @mod, align 4, !tbaa !5
  %75 = call noundef i32 @_Z4calciii(i32 noundef %72, i32 noundef %73, i32 noundef %74)
  store i32 %75, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %76 = load i32, ptr @ans, align 4, !tbaa !5
  store i32 %76, ptr %7, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %100, %67
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = load i32, ptr @n, align 4, !tbaa !5
  %80 = icmp slt i32 %78, %79
  br i1 %80, label %82, label %81

81:                                               ; preds = %77
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %103

82:                                               ; preds = %77
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = add nsw i32 %83, -1
  store i32 %84, ptr %7, align 4, !tbaa !5
  %85 = icmp slt i32 %84, 0
  br i1 %85, label %86, label %90

86:                                               ; preds = %82
  %87 = load i32, ptr @mod, align 4, !tbaa !5
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = add nsw i32 %88, %87
  store i32 %89, ptr %7, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %86, %82
  %91 = load i32, ptr @ans, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = mul nsw i64 %92, %94
  %96 = load i32, ptr @mod, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = srem i64 %95, %97
  %99 = trunc i64 %98 to i32
  store i32 %99, ptr @ans, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %90
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %6, align 4, !tbaa !5
  br label %77, !llvm.loop !16

103:                                              ; preds = %81
  %104 = load i32, ptr @ans, align 4, !tbaa !5
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %104)
  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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [44722 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [44723 x i8], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calciii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %15

1:                                                ; preds = %.critedge
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @b, ptr noundef nonnull @mod)
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = load i32, ptr @b, align 4, !tbaa !5
  %5 = add i32 %3, -1
  %6 = add i32 %5, %4
  %7 = load i32, ptr @mod, align 4, !tbaa !5
  %8 = tail call noundef i32 @_Z4calciii(i32 noundef %6, i32 noundef %3, i32 noundef %7)
  store i32 %8, ptr @ans, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.lr.ph30, label %46

.lr.ph30:                                         ; preds = %1
  %11 = load i32, ptr @mod, align 4
  %12 = sext i32 %11 to i64
  %13 = add nsw i32 %9, -1
  %xtraiter = and i32 %13, 1
  %14 = icmp eq i32 %9, 2
  br i1 %14, label %._crit_edge.unr-lcssa, label %.lr.ph30.new

.lr.ph30.new:                                     ; preds = %.lr.ph30
  %unroll_iter = and i32 %13, -2
  br label %49

15:                                               ; preds = %0, %.critedge
  %indvars.iv32 = phi i64 [ 2, %0 ], [ %indvars.iv.next33, %.critedge ]
  %16 = phi i32 [ %tot.promoted, %0 ], [ %26, %.critedge ]
  %17 = getelementptr inbounds [44723 x i8], ptr @vis, i64 0, i64 %indvars.iv32
  %18 = load i8, ptr %17, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %._crit_edge36, label %20

._crit_edge36:                                    ; preds = %15
  %.pre = trunc nuw nsw i64 %indvars.iv32 to i32
  br label %25

20:                                               ; preds = %15
  %21 = add nsw i32 %16, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %16 to i64
  %23 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %22
  %24 = trunc nuw nsw i64 %indvars.iv32 to i32
  store i32 %24, ptr %23, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %._crit_edge36, %20
  %.pre-phi = phi i32 [ %.pre, %._crit_edge36 ], [ %24, %20 ]
  %26 = phi i32 [ %16, %._crit_edge36 ], [ %21, %20 ]
  %.rhs.trunc = trunc nuw i32 %.pre-phi to i16
  %27 = udiv i16 -20814, %.rhs.trunc
  %.zext = zext i16 %27 to i32
  %28 = icmp sgt i32 %26, 0
  br i1 %28, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %25
  %29 = zext nneg i32 %26 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %32 ]
  %30 = getelementptr inbounds [44722 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not = icmp sgt i32 %31, %.zext
  br i1 %.not, label %.critedge, label %32

32:                                               ; preds = %.lr.ph
  %33 = mul nsw i32 %31, %.pre-phi
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [44723 x i8], ptr @vis, i64 0, i64 %34
  store i8 1, ptr %35, align 1, !tbaa !9
  %36 = srem i32 %.pre-phi, %31
  %37 = icmp ne i32 %36, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = icmp ult i64 %indvars.iv.next, %29
  %or.cond = select i1 %37, i1 %38, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %32, %25
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next33, 44723
  br i1 %exitcond.not, label %1, label %15, !llvm.loop !15

._crit_edge.unr-lcssa:                            ; preds = %49, %.lr.ph30
  %.lcssa.ph = phi i32 [ poison, %.lr.ph30 ], [ %63, %49 ]
  %.029.unr = phi i32 [ %8, %.lr.ph30 ], [ %.1.1, %49 ]
  %.unr = phi i32 [ %8, %.lr.ph30 ], [ %63, %49 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %39 = add nsw i32 %.029.unr, -1
  %.inv.epil = icmp sgt i32 %.029.unr, 0
  %40 = select i1 %.inv.epil, i32 0, i32 %11
  %.1.epil = add nsw i32 %39, %40
  %41 = sext i32 %.unr to i64
  %42 = sext i32 %.1.epil to i64
  %43 = mul nsw i64 %42, %41
  %44 = srem i64 %43, %12
  %45 = trunc nsw i64 %44 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %45, %._crit_edge.epilog-lcssa ]
  store i32 %.lcssa, ptr @ans, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %._crit_edge, %1
  %47 = phi i32 [ %.lcssa, %._crit_edge ], [ %8, %1 ]
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %47)
  ret i32 0

49:                                               ; preds = %49, %.lr.ph30.new
  %.029 = phi i32 [ %8, %.lr.ph30.new ], [ %.1.1, %49 ]
  %50 = phi i32 [ %8, %.lr.ph30.new ], [ %63, %49 ]
  %niter = phi i32 [ 0, %.lr.ph30.new ], [ %niter.next.1, %49 ]
  %51 = add nsw i32 %.029, -1
  %.inv = icmp sgt i32 %.029, 0
  %52 = select i1 %.inv, i32 0, i32 %11
  %.1 = add nsw i32 %51, %52
  %53 = sext i32 %50 to i64
  %54 = sext i32 %.1 to i64
  %55 = mul nsw i64 %54, %53
  %56 = srem i64 %55, %12
  %57 = add nsw i32 %.1, -1
  %.inv.1 = icmp sgt i32 %.1, 0
  %58 = select i1 %.inv.1, i32 0, i32 %11
  %.1.1 = add nsw i32 %57, %58
  %sext = shl i64 %56, 32
  %59 = ashr exact i64 %sext, 32
  %60 = sext i32 %.1.1 to i64
  %61 = mul nsw i64 %59, %60
  %62 = srem i64 %61, %12
  %63 = trunc nsw i64 %62 to i32
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %49, !llvm.loop !16
}

; 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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