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

; 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 [12500 x i32], align 16
@f = external dso_local global [100001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@delta = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([100001 x i32], ptr @f, i64 0, i64 1), 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 %6

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

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %30, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @tot, align 4, !tbaa !5
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sub nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %16, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sdiv i32 100000, %31
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %77, %30
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = icmp sle i32 %41, %42
  br label %44

44:                                               ; preds = %37, %33
  %45 = phi i1 [ false, %33 ], [ %43, %37 ]
  br i1 %45, label %47, label %46

46:                                               ; preds = %44
  store i32 5, ptr %3, align 4
  br label %80

47:                                               ; preds = %44
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %51, %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = mul nsw i32 %60, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %66
  store i32 %59, ptr %67, align 4, !tbaa !5
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = srem i32 %68, %72
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %47
  store i32 5, ptr %3, align 4
  br label %80

76:                                               ; preds = %47
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %33, !llvm.loop !9

80:                                               ; preds = %75, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

85:                                               ; preds = %9
  %86 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %87

87:                                               ; preds = %113, %85
  %88 = load i32, ptr @t, align 4, !tbaa !5
  %89 = add nsw i32 %88, -1
  store i32 %89, ptr @t, align 4, !tbaa !5
  %90 = icmp ne i32 %88, 0
  br i1 %90, label %91, label %118

91:                                               ; preds = %87
  store i64 0, ptr @ans, align 8, !tbaa !12
  store i64 1, ptr @delta, align 8, !tbaa !12
  %92 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %93

93:                                               ; preds = %112, %91
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr @n, align 4, !tbaa !5
  %96 = icmp ne i32 %94, 0
  br i1 %96, label %97, label %113

97:                                               ; preds = %93
  %98 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p, ptr noundef @q)
  %99 = load i32, ptr @p, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = load i32, ptr @q, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = mul nsw i64 %103, %105
  %107 = load i64, ptr @ans, align 8, !tbaa !12
  %108 = add nsw i64 %107, %106
  store i64 %108, ptr @ans, align 8, !tbaa !12
  %109 = load i32, ptr @p, align 4, !tbaa !5
  %110 = icmp eq i32 %109, 2
  br i1 %110, label %111, label %112

111:                                              ; preds = %97
  store i64 0, ptr @delta, align 8, !tbaa !12
  br label %112

112:                                              ; preds = %111, %97
  br label %93, !llvm.loop !14

113:                                              ; preds = %93
  %114 = load i64, ptr @ans, align 8, !tbaa !12
  %115 = load i64, ptr @delta, align 8, !tbaa !12
  %116 = add nsw i64 %114, %115
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %116)
  br label %87, !llvm.loop !15

118:                                              ; preds = %87
  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

declare i32 @printf(ptr noundef, ...) #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 = { 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 = { 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}
!15 = distinct !{!15, !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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [12500 x i32], align 16
@f = external dso_local local_unnamed_addr global [100001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@delta = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %5

1:                                                ; preds = %.critedge
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not28 = icmp eq i32 %3, 0
  br i1 %.not28, label %._crit_edge31, label %.lr.ph30

5:                                                ; preds = %0, %.critedge
  %indvars.iv33 = phi i64 [ 2, %0 ], [ %indvars.iv.next34, %.critedge ]
  %6 = phi i32 [ %tot.promoted, %0 ], [ %18, %.critedge ]
  %7 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %indvars.iv33
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %9, label %._crit_edge36

._crit_edge36:                                    ; preds = %5
  %.pre37 = trunc nuw nsw i64 %indvars.iv33 to i32
  br label %17

9:                                                ; preds = %5
  %10 = add nsw i32 %6, 1
  store i32 %10, ptr @tot, align 4, !tbaa !5
  %11 = sext i32 %6 to i64
  %12 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %11
  %13 = trunc nuw nsw i64 %indvars.iv33 to i32
  store i32 %13, ptr %12, align 4, !tbaa !5
  %14 = add nsw i64 %indvars.iv33, -1
  %15 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %7, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge36, %9
  %.pre-phi = phi i32 [ %.pre37, %._crit_edge36 ], [ %13, %9 ]
  %18 = phi i32 [ %6, %._crit_edge36 ], [ %10, %9 ]
  %19 = udiv i32 100000, %.pre-phi
  %20 = icmp sgt i32 %18, 0
  br i1 %20, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %17
  %21 = zext nneg i32 %18 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %24 ]
  %22 = getelementptr inbounds [12500 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not21 = icmp sgt i32 %23, %19
  br i1 %.not21, label %.critedge, label %24

24:                                               ; preds = %.lr.ph
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = sext i32 %23 to i64
  %27 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, %25
  %30 = mul nsw i32 %23, %.pre-phi
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  %33 = srem i32 %.pre-phi, %23
  %34 = icmp ne i32 %33, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = icmp ult i64 %indvars.iv.next, %21
  %or.cond = select i1 %34, i1 %35, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %24, %17
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next34, 100001
  br i1 %exitcond.not, label %1, label %5, !llvm.loop !11

.lr.ph30:                                         ; preds = %1, %._crit_edge
  store i64 0, ptr @ans, align 8, !tbaa !12
  store i64 1, ptr @delta, align 8, !tbaa !12
  %36 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @n, align 4, !tbaa !5
  %.not1926 = icmp eq i32 %37, 0
  br i1 %.not1926, label %.lr.ph30.._crit_edge_crit_edge, label %.lr.ph27

.lr.ph30.._crit_edge_crit_edge:                   ; preds = %.lr.ph30
  %.pre = load i64, ptr @ans, align 8, !tbaa !12
  br label %._crit_edge

.lr.ph27:                                         ; preds = %.lr.ph30, %52
  %39 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p, ptr noundef nonnull @q)
  %40 = load i32, ptr @p, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = load i32, ptr @q, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %46, %44
  %48 = load i64, ptr @ans, align 8, !tbaa !12
  %49 = add nsw i64 %47, %48
  store i64 %49, ptr @ans, align 8, !tbaa !12
  %50 = icmp eq i32 %40, 2
  br i1 %50, label %51, label %52

51:                                               ; preds = %.lr.ph27
  store i64 0, ptr @delta, align 8, !tbaa !12
  br label %52

52:                                               ; preds = %51, %.lr.ph27
  %53 = load i32, ptr @n, align 4, !tbaa !5
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr @n, align 4, !tbaa !5
  %.not19 = icmp eq i32 %53, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph27, !llvm.loop !14

._crit_edge:                                      ; preds = %52, %.lr.ph30.._crit_edge_crit_edge
  %55 = phi i64 [ %.pre, %.lr.ph30.._crit_edge_crit_edge ], [ %49, %52 ]
  %56 = load i64, ptr @delta, align 8, !tbaa !12
  %57 = add nsw i64 %56, %55
  %58 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %57)
  %59 = load i32, ptr @t, align 4, !tbaa !5
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %59, 0
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !15

._crit_edge31:                                    ; preds = %._crit_edge, %1
  ret i32 0
}

; 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 = 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}
!15 = distinct !{!15, !10}


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