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

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

@t = external dso_local global i32, align 4
@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
@l = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.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 [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
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %60, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %63

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @r, align 4, !tbaa !5
  store i32 0, ptr @l, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %57, %8
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %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 %16 to i64
  %19 = getelementptr inbounds i32, ptr @que, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %19)
  br label %21

21:                                               ; preds = %39, %15
  %22 = load i32, ptr @r, align 4, !tbaa !5
  %23 = sub nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr @l, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sub nsw i32 %26, %30
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = load i32, ptr @r, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = load i32, ptr @l, align 4, !tbaa !5
  %37 = sub nsw i32 %35, %36
  %38 = icmp sgt i32 %32, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %21
  %40 = load i32, ptr @l, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @l, align 4, !tbaa !5
  br label %21, !llvm.loop !9

42:                                               ; preds = %21
  %43 = load i32, ptr @ans, align 4, !tbaa !5
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = load i32, ptr @r, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = load i32, ptr @l, align 4, !tbaa !5
  %48 = sub nsw i32 %46, %47
  %49 = icmp slt i32 %43, %48
  br i1 %49, label %50, label %56

50:                                               ; preds = %42
  %51 = load i32, ptr @m, align 4, !tbaa !5
  %52 = load i32, ptr @r, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = load i32, ptr @l, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  store i32 %55, ptr @ans, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %50, %42
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

60:                                               ; preds = %14
  %61 = load i32, ptr @ans, align 4, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %61)
  br label %4, !llvm.loop !12

63:                                               ; 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

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

@t = external dso_local global i32, align 4
@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
@l = external dso_local local_unnamed_addr global i32, align 4
@r = 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not13 = icmp eq i32 %2, 0
  br i1 %.not13, label %._crit_edge16, label %.lr.ph15

.lr.ph15:                                         ; preds = %0, %._crit_edge12
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr @r, align 4, !tbaa !5
  store i32 0, ptr @l, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %.not38 = icmp slt i32 %5, 1
  br i1 %.not38, label %._crit_edge12, label %.lr.ph11

._crit_edge12:                                    ; preds = %38, %.lr.ph15
  %6 = phi i32 [ 0, %.lr.ph15 ], [ %39, %38 ]
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %6)
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge16, label %.lr.ph15, !llvm.loop !9

.lr.ph11:                                         ; preds = %.lr.ph15, %38
  %10 = phi i32 [ %15, %38 ], [ 0, %.lr.ph15 ]
  %.09 = phi i32 [ %40, %38 ], [ 1, %.lr.ph15 ]
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @r, align 4, !tbaa !5
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds i32, ptr @que, i64 %12
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %13)
  %15 = load i32, ptr @r, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %l.promoted = load i32, ptr @l, align 4, !tbaa !5
  %21 = sext i32 %l.promoted to i64
  %22 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 %19, %23
  %25 = sub i32 %15, %l.promoted
  %26 = add i32 %25, %20
  %.not46 = icmp slt i32 %24, %26
  br i1 %.not46, label %34, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph11, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %21, %.lr.ph11 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds [1000010 x i32], ptr @que, i64 0, i64 %indvars.iv.next
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sub nsw i32 %19, %28
  %30 = trunc nsw i64 %indvars.iv to i32
  %.neg = xor i32 %30, -1
  %31 = add i32 %15, %.neg
  %32 = add i32 %31, %20
  %.not4 = icmp slt i32 %29, %32
  br i1 %.not4, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  %33 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %33, ptr @l, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %._crit_edge, %.lr.ph11
  %.lcssa = phi i32 [ %32, %._crit_edge ], [ %26, %.lr.ph11 ]
  %35 = load i32, ptr @ans, align 4, !tbaa !5
  %36 = icmp slt i32 %35, %.lcssa
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 %.lcssa, ptr @ans, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %34, %37
  %39 = phi i32 [ %35, %34 ], [ %.lcssa, %37 ]
  %40 = add nuw nsw i32 %.09, 1
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %.not3.not = icmp slt i32 %.09, %41
  br i1 %.not3.not, label %.lr.ph11, label %._crit_edge12, !llvm.loop !12

._crit_edge16:                                    ; preds = %._crit_edge12, %0
  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 = distinct !{!12, !10}


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