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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@a = external dso_local global [10000001 x i32], align 16
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = 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
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @v, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @p)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

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

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = load i32, ptr @b, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %18, %20
  %22 = load i32, ptr @c, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = add nsw i64 %21, %23
  %25 = load i32, ptr @p, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = srem i64 %24, %26
  %28 = trunc i64 %27 to i32
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %12
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

35:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %89, %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %63, %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %42
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr @m, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br label %50

50:                                               ; preds = %46, %42
  %51 = phi i1 [ false, %42 ], [ %49, %46 ]
  br i1 %51, label %52, label %66

52:                                               ; preds = %50
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr @v, align 4, !tbaa !5
  %58 = icmp sge i32 %56, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %52
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %59, %52
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %42, !llvm.loop !11

66:                                               ; preds = %50
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %69 = icmp eq i32 %67, %68
  br i1 %69, label %70, label %78

70:                                               ; preds = %66
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sub nsw i32 %71, %72
  %74 = add nsw i32 %73, 2
  %75 = sext i32 %74 to i64
  %76 = load i64, ptr @ans, align 8, !tbaa !12
  %77 = add nsw i64 %76, %75
  store i64 %77, ptr @ans, align 8, !tbaa !12
  br label %78

78:                                               ; preds = %70, %66
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr @v, align 4, !tbaa !5
  %84 = icmp sge i32 %82, %83
  br i1 %84, label %85, label %88

85:                                               ; preds = %78
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = add nsw i32 %86, -1
  store i32 %87, ptr %5, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %85, %78
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %3, align 4, !tbaa !5
  br label %36, !llvm.loop !14

92:                                               ; preds = %40
  %93 = load i64, ptr @ans, align 8, !tbaa !12
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %93)
  ret i32 0
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@a = external dso_local global [10000001 x i32], align 16
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = 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 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @v, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @p)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not25 = icmp slt i32 %2, 1
  br i1 %.not25, label %.preheader23.._crit_edge37_crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %3 = load i32, ptr @b, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = load i32, ptr @c, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = load i32, ptr @p, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %.pre = load i32, ptr @a, align 16, !tbaa !5
  %9 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %9, 1
  %10 = icmp eq i32 %2, 1
  br i1 %10, label %.preheader23.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %9, 2147483646
  br label %22

.preheader23.unr-lcssa:                           ; preds = %22, %.lr.ph
  %.unr = phi i32 [ %.pre, %.lr.ph ], [ %34, %22 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader23, label %.preheader23.epilog-lcssa

.preheader23.epilog-lcssa:                        ; preds = %.preheader23.unr-lcssa
  %11 = sext i32 %.unr to i64
  %12 = mul nsw i64 %4, %11
  %13 = add nsw i64 %12, %6
  %14 = srem i64 %13, %8
  %15 = trunc nsw i64 %14 to i32
  %16 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %indvars.iv.unr
  store i32 %15, ptr %16, align 4, !tbaa !5
  br label %.preheader23

.preheader23:                                     ; preds = %.preheader23.unr-lcssa, %.preheader23.epilog-lcssa
  br i1 %.not25, label %.preheader23.._crit_edge37_crit_edge, label %.preheader.lr.ph

.preheader23.._crit_edge37_crit_edge:             ; preds = %0, %.preheader23
  %.pre47 = load i64, ptr @ans, align 8, !tbaa !9
  br label %._crit_edge37

.preheader.lr.ph:                                 ; preds = %.preheader23
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !9
  %17 = load i32, ptr @m, align 4
  %18 = load i32, ptr @v, align 4
  %19 = add nuw i32 %2, 2
  %20 = zext nneg i32 %2 to i64
  %21 = add nuw i32 %2, 1
  %wide.trip.count45 = zext i32 %21 to i64
  br label %.preheader

22:                                               ; preds = %22, %.lr.ph.new
  %23 = phi i32 [ %.pre, %.lr.ph.new ], [ %34, %22 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %22 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %22 ]
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %4, %24
  %26 = add nsw i64 %25, %6
  %27 = srem i64 %26, %8
  %28 = trunc nsw i64 %27 to i32
  %29 = getelementptr inbounds [10000001 x i32], ptr @a, 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 = shl i64 %27, 32
  %30 = ashr exact i64 %sext, 32
  %31 = mul nsw i64 %30, %4
  %32 = add nsw i64 %31, %6
  %33 = srem i64 %32, %8
  %34 = trunc nsw i64 %33 to i32
  %35 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  store i32 %34, ptr %35, 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 %.preheader23.unr-lcssa, label %22, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.lr.ph, %55
  %indvars.iv42 = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next43, %55 ]
  %.036 = phi i32 [ 0, %.preheader.lr.ph ], [ %spec.select22, %55 ]
  %.01535 = phi i32 [ 1, %.preheader.lr.ph ], [ %.116.lcssa, %55 ]
  %36 = phi i64 [ %ans.promoted, %.preheader.lr.ph ], [ %56, %55 ]
  %37 = icmp sle i32 %.01535, %2
  %38 = icmp slt i32 %.036, %17
  %39 = select i1 %37, i1 %38, i1 false
  br i1 %39, label %.lr.ph29.preheader, label %._crit_edge

.lr.ph29.preheader:                               ; preds = %.preheader
  %40 = sext i32 %.01535 to i64
  br label %.lr.ph29

._crit_edge37:                                    ; preds = %55, %.preheader23.._crit_edge37_crit_edge
  %41 = phi i64 [ %.pre47, %.preheader23.._crit_edge37_crit_edge ], [ %56, %55 ]
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %41)
  ret i32 0

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.lr.ph29
  %indvars.iv39 = phi i64 [ %40, %.lr.ph29.preheader ], [ %indvars.iv.next40, %.lr.ph29 ]
  %.128 = phi i32 [ %.036, %.lr.ph29.preheader ], [ %spec.select, %.lr.ph29 ]
  %43 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %indvars.iv39
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %.not21 = icmp sge i32 %44, %18
  %45 = zext i1 %.not21 to i32
  %spec.select = add nsw i32 %.128, %45
  %indvars.iv.next40 = add nsw i64 %indvars.iv39, 1
  %46 = icmp slt i64 %indvars.iv39, %20
  %47 = icmp slt i32 %spec.select, %17
  %48 = select i1 %46, i1 %47, i1 false
  br i1 %48, label %.lr.ph29, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph29
  %49 = trunc nsw i64 %indvars.iv.next40 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.116.lcssa = phi i32 [ %.01535, %.preheader ], [ %49, %._crit_edge.loopexit ]
  %.1.lcssa = phi i32 [ %.036, %.preheader ], [ %spec.select, %._crit_edge.loopexit ]
  %50 = icmp eq i32 %.1.lcssa, %17
  br i1 %50, label %51, label %55

51:                                               ; preds = %._crit_edge
  %52 = sub i32 %19, %.116.lcssa
  %53 = sext i32 %52 to i64
  %54 = add nsw i64 %36, %53
  store i64 %54, ptr @ans, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %51, %._crit_edge
  %56 = phi i64 [ %54, %51 ], [ %36, %._crit_edge ]
  %57 = getelementptr inbounds [10000001 x i32], ptr @a, i64 0, i64 %indvars.iv42
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %.not20 = icmp sge i32 %58, %18
  %59 = sext i1 %.not20 to i32
  %spec.select22 = add nsw i32 %.1.lcssa, %59
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count45
  br i1 %exitcond46.not, label %._crit_edge37, label %.preheader, !llvm.loop !14
}

; 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 = !{!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}


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