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

; 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
@a = external dso_local global [50001 x i32], align 16
@pos = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 2147483647, ptr %3, align 4, !tbaa !5
  br label %7

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

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr @a, i64 %14
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15)
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp slt i32 %17, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %12
  %24 = load i32, ptr %3, align 4, !tbaa !5
  br label %30

25:                                               ; preds = %12
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %25, %23
  %31 = phi i32 [ %24, %23 ], [ %29, %25 ]
  store i32 %31, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %33
  store i32 %31, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %30
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

38:                                               ; preds = %11
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  store i32 %40, ptr @pos, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %76, %38
  %42 = load i32, ptr @pos, align 4, !tbaa !5
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr @m, align 4, !tbaa !5
  %47 = icmp ne i32 %45, 0
  br label %48

48:                                               ; preds = %44, %41
  %49 = phi i1 [ false, %41 ], [ %47, %44 ]
  br i1 %49, label %50, label %81

50:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %51 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  br label %52

52:                                               ; preds = %65, %50
  %53 = load i32, ptr @pos, align 4, !tbaa !5
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %52
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr @pos, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = icmp sgt i32 %56, %60
  br label %62

62:                                               ; preds = %55, %52
  %63 = phi i1 [ false, %52 ], [ %61, %55 ]
  br i1 %63, label %64, label %68

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr @pos, align 4, !tbaa !5
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr @pos, align 4, !tbaa !5
  br label %52, !llvm.loop !11

68:                                               ; preds = %62
  %69 = load i32, ptr @pos, align 4, !tbaa !5
  %70 = icmp slt i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 5, ptr %5, align 4
  br label %73

72:                                               ; preds = %68
  store i32 0, ptr %5, align 4
  br label %73

73:                                               ; preds = %72, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %74 = load i32, ptr %5, align 4
  switch i32 %74, label %84 [
    i32 0, label %75
    i32 5, label %81
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr @pos, align 4, !tbaa !5
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr @pos, align 4, !tbaa !5
  %79 = load i32, ptr @ans, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr @ans, align 4, !tbaa !5
  br label %41, !llvm.loop !12

81:                                               ; preds = %73, %48
  %82 = load i32, ptr @ans, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %82)
  ret i32 0

84:                                               ; preds = %73
  unreachable
}

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 = distinct !{!12, !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
@a = external dso_local global [50001 x i32], align 16
@pos = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %5 = add nsw i32 %3, -1
  store i32 %5, ptr @pos, align 4, !tbaa !5
  br label %.critedge

._crit_edge:                                      ; preds = %.lr.ph
  %6 = add nsw i32 %11, -1
  store i32 %6, ptr @pos, align 4, !tbaa !5
  %7 = icmp sgt i32 %11, 0
  br i1 %7, label %.lr.ph23, label %.critedge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %.01118 = phi i32 [ %.011., %.lr.ph ], [ 2147483647, %0 ]
  %8 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %8)
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %.011. = tail call i32 @llvm.smin.i32(i32 %.01118, i32 %10)
  store i32 %.011., ptr %8, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph23:                                         ; preds = %._crit_edge, %29
  %14 = load i32, ptr @m, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %.critedge, label %16

16:                                               ; preds = %.lr.ph23
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %.pr = load i32, ptr @pos, align 4, !tbaa !5
  %18 = icmp sgt i32 %.pr, -1
  br i1 %18, label %.lr.ph20, label %.critedge2.thread

.lr.ph20:                                         ; preds = %16
  %19 = load i32, ptr %1, align 4, !tbaa !5
  br label %20

.critedge2.thread:                                ; preds = %16, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  br label %.critedge

20:                                               ; preds = %.lr.ph20, %26
  %21 = phi i32 [ %.pr, %.lr.ph20 ], [ %27, %26 ]
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [50001 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp sgt i32 %19, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = add nsw i32 %21, -1
  store i32 %27, ptr @pos, align 4, !tbaa !5
  %28 = icmp sgt i32 %21, 0
  br i1 %28, label %20, label %.critedge2.thread, !llvm.loop !11

29:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %30 = add nsw i32 %21, -1
  store i32 %30, ptr @pos, align 4, !tbaa !5
  %31 = load i32, ptr @ans, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @ans, align 4, !tbaa !5
  %.not34 = icmp eq i32 %21, 0
  br i1 %.not34, label %.critedge, label %.lr.ph23, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph23, %29, %._crit_edge.thread, %._crit_edge, %.critedge2.thread
  %33 = load i32, ptr @ans, align 4, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %33)
  ret i32 0
}

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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