; LLVM IR from tangjz/acm-icpc :: codeforces/complete (500A)

; 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
@t = external dso_local global i32, align 4
@nxt = external dso_local global [66666 x i32], align 16
@vis = external dso_local global [66666 x i32], align 16
@que = external dso_local global [66666 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
@.str.3 = external hidden unnamed_addr constant [3 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

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

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

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %14)
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %16
  store i32 %21, ptr %19, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %11
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

25:                                               ; preds = %10
  store i32 1, ptr getelementptr inbounds ([66666 x i32], ptr @vis, i64 0, i64 1), align 4, !tbaa !5
  %26 = load i32, ptr @r, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr @r, align 4, !tbaa !5
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %28
  store i32 1, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %73, %71, %25
  %31 = load i32, ptr @l, align 4, !tbaa !5
  %32 = load i32, ptr @r, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %74

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %35 = load i32, ptr @l, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @l, align 4, !tbaa !5
  %37 = sext i32 %35 to i64
  %38 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %34
  store i32 5, ptr %4, align 4
  br label %71, !llvm.loop !11

49:                                               ; preds = %34
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %54
  store i32 1, ptr %55, align 4, !tbaa !5
  %56 = load i32, ptr @t, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %49
  store i32 6, ptr %4, align 4
  br label %71

62:                                               ; preds = %49
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr @r, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr @r, align 4, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %69
  store i32 %66, ptr %70, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %71

71:                                               ; preds = %62, %61, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %72 = load i32, ptr %4, align 4
  switch i32 %72, label %83 [
    i32 0, label %73
    i32 5, label %30
    i32 6, label %74
  ]

73:                                               ; preds = %71
  br label %30, !llvm.loop !11

74:                                               ; preds = %71, %30
  %75 = load i32, ptr @t, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = icmp ne i32 %78, 0
  %80 = zext i1 %79 to i64
  %81 = select i1 %79, ptr @.str.2, ptr @.str.3
  %82 = call i32 @puts(ptr noundef %81)
  ret i32 0

83:                                               ; preds = %71
  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 @puts(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}


; 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
@t = external dso_local global i32, align 4
@nxt = external dso_local global [66666 x i32], align 16
@vis = external dso_local local_unnamed_addr global [66666 x i32], align 16
@que = external dso_local local_unnamed_addr global [66666 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
@.str.3 = external hidden unnamed_addr constant [3 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 @t)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  store i32 1, ptr getelementptr inbounds (i8, ptr @vis, i64 4), align 4, !tbaa !5
  %4 = load i32, ptr @r, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @r, align 4, !tbaa !5
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %6
  store i32 1, ptr %7, align 4, !tbaa !5
  %l.promoted = load i32, ptr @l, align 4, !tbaa !5
  %.not21 = icmp sgt i32 %l.promoted, %4
  %.pre = load i32, ptr @t, align 4
  %.pre27 = sext i32 %.pre to i64
  br i1 %.not21, label %.thread, label %.lr.ph18

.lr.ph18:                                         ; preds = %._crit_edge
  %8 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %.pre27
  %9 = sext i32 %l.promoted to i64
  br label %18

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

18:                                               ; preds = %.lr.ph18, %34
  %indvars.iv24 = phi i64 [ %9, %.lr.ph18 ], [ %indvars.iv.next25, %34 ]
  %19 = phi i32 [ %5, %.lr.ph18 ], [ %35, %34 ]
  %indvars.iv.next25 = add nsw i64 %indvars.iv24, 1
  %20 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %indvars.iv24
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [66666 x i32], ptr @nxt, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %34, !llvm.loop !11

28:                                               ; preds = %18
  store i32 1, ptr %26, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %.not11 = icmp eq i32 %29, 0
  br i1 %.not11, label %30, label %.thread.sink.split

30:                                               ; preds = %28
  %31 = add nsw i32 %19, 1
  store i32 %31, ptr @r, align 4, !tbaa !5
  %32 = sext i32 %19 to i64
  %33 = getelementptr inbounds [66666 x i32], ptr @que, i64 0, i64 %32
  store i32 %24, ptr %33, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %18, %30
  %35 = phi i32 [ %19, %18 ], [ %31, %30 ]
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next25, %36
  br i1 %37, label %18, label %.thread.sink.split

.thread.sink.split:                               ; preds = %34, %28
  %38 = trunc nsw i64 %indvars.iv.next25 to i32
  store i32 %38, ptr @l, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %.thread.sink.split, %._crit_edge
  %39 = getelementptr inbounds [66666 x i32], ptr @vis, i64 0, i64 %.pre27
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not12 = icmp eq i32 %40, 0
  %41 = select i1 %.not12, ptr @.str.3, ptr @.str.2
  %42 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %41)
  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 @puts(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}


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