; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1142)

; 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
@que = external dso_local global [1000010 x i32], align 16
@pos = external dso_local global [1000010 x i32], align 16
@l = external dso_local global i32, align 4
@r = 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
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %91, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %93

7:                                                ; preds = %4
  store i32 0, ptr @l, align 4, !tbaa !5
  store i32 -1, ptr @r, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  br label %8

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

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

13:                                               ; preds = %8
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr @r, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @r, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %18
  store i32 %15, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr @r, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %42, %13
  %25 = load i32, ptr @l, align 4, !tbaa !5
  %26 = load i32, ptr @r, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %40

28:                                               ; preds = %24
  %29 = load i32, ptr @l, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr @r, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  %39 = icmp sle i32 %32, %38
  br label %40

40:                                               ; preds = %28, %24
  %41 = phi i1 [ false, %24 ], [ %39, %28 ]
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = load i32, ptr @l, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @l, align 4, !tbaa !5
  br label %24, !llvm.loop !9

45:                                               ; preds = %40
  br label %46

46:                                               ; preds = %63, %45
  %47 = load i32, ptr @l, align 4, !tbaa !5
  %48 = load i32, ptr @r, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %61

50:                                               ; preds = %46
  %51 = load i32, ptr @r, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr @r, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp sge i32 %55, %59
  br label %61

61:                                               ; preds = %50, %46
  %62 = phi i1 [ false, %46 ], [ %60, %50 ]
  br i1 %62, label %63, label %82

63:                                               ; preds = %61
  %64 = load i32, ptr @r, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr @r, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %70
  store i32 %67, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr @r, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr @r, align 4, !tbaa !5
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %78
  store i32 %75, ptr %79, align 4, !tbaa !5
  %80 = load i32, ptr @r, align 4, !tbaa !5
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr @r, align 4, !tbaa !5
  br label %46, !llvm.loop !11

82:                                               ; preds = %61
  %83 = load i32, ptr @l, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %86)
  br label %88

88:                                               ; preds = %82
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !12

91:                                               ; preds = %12
  %92 = call i32 @putchar(i32 noundef 10)
  br label %4, !llvm.loop !13

93:                                               ; preds = %4
  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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #3

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 = { inlinehint 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 #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}
!13 = distinct !{!13, !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
@que = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@pos = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@l = external dso_local local_unnamed_addr global i32, align 4
@r = 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 = icmp eq i32 %2, 2
  br i1 %3, label %.lr.ph19, label %._crit_edge20

.lr.ph19:                                         ; preds = %0, %._crit_edge
  store i32 0, ptr @l, align 4, !tbaa !5
  store i32 -1, ptr @r, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph17, label %._crit_edge

._crit_edge:                                      ; preds = %.critedge2, %.lr.ph19
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %6 = call i32 @putchar(i32 noundef 10)
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %.lr.ph19, label %._crit_edge20, !llvm.loop !9

.lr.ph17:                                         ; preds = %.lr.ph19, %.critedge2
  %9 = phi i32 [ %37, %.critedge2 ], [ 0, %.lr.ph19 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = load i32, ptr @r, align 4, !tbaa !5
  %13 = add i32 %12, 1
  store i32 %13, ptr @r, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  %16 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %14
  store i32 %9, ptr %16, align 4, !tbaa !5
  %l.promoted = load i32, ptr @l, align 4, !tbaa !5
  %.not1011 = icmp sgt i32 %l.promoted, %12
  br i1 %.not1011, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph17
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = sub nsw i32 %9, %17
  %19 = sext i32 %l.promoted to i64
  br label %20

20:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ %19, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %21 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not = icmp sgt i32 %22, %18
  br i1 %.not, label %.critedge.loopexit, label %23

23:                                               ; preds = %20
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %24 = trunc i64 %indvars.iv.next to i32
  store i32 %24, ptr @l, align 4, !tbaa !5
  %exitcond.not = icmp eq i32 %13, %24
  br i1 %exitcond.not, label %.critedge..critedge2_crit_edge, label %20, !llvm.loop !11

.critedge.loopexit:                               ; preds = %20
  %25 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph17
  %.lcssa = phi i32 [ %l.promoted, %.lr.ph17 ], [ %25, %.critedge.loopexit ]
  %26 = icmp slt i32 %.lcssa, %13
  br i1 %26, label %.lr.ph14.preheader, label %.critedge..critedge2_crit_edge

.critedge..critedge2_crit_edge:                   ; preds = %23, %.critedge
  %.lcssa26 = phi i32 [ %.lcssa, %.critedge ], [ %13, %23 ]
  %.pre = sext i32 %.lcssa26 to i64
  br label %.critedge2

.lr.ph14.preheader:                               ; preds = %.critedge
  %27 = sext i32 %.lcssa to i64
  br label %.lr.ph14

.lr.ph14:                                         ; preds = %.lr.ph14.preheader, %30
  %indvars.iv22 = phi i64 [ %14, %.lr.ph14.preheader ], [ %indvars.iv.next23, %30 ]
  %indvars.iv.next23 = add nsw i64 %indvars.iv22, -1
  %28 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %indvars.iv.next23
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not9 = icmp slt i32 %29, %11
  br i1 %.not9, label %.critedge2, label %30

30:                                               ; preds = %.lr.ph14
  store i32 %11, ptr %28, align 4, !tbaa !5
  %31 = getelementptr inbounds [1000010 x i32], ptr @pos, i64 0, i64 %indvars.iv.next23
  store i32 %9, ptr %31, align 4, !tbaa !5
  %32 = trunc nsw i64 %indvars.iv.next23 to i32
  store i32 %32, ptr @r, align 4, !tbaa !5
  %33 = icmp sgt i64 %indvars.iv.next23, %27
  br i1 %33, label %.lr.ph14, label %.critedge2, !llvm.loop !12

.critedge2:                                       ; preds = %.lr.ph14, %30, %.critedge..critedge2_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.critedge..critedge2_crit_edge ], [ %27, %30 ], [ %27, %.lr.ph14 ]
  %34 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %.pre-phi
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %35)
  %37 = add nuw nsw i32 %9, 1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %.lr.ph17, label %._crit_edge, !llvm.loop !13

._crit_edge20:                                    ; preds = %._crit_edge, %0
  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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #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 = { inlinehint mustprogress nofree 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 #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}
!13 = distinct !{!13, !10}


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