; LLVM IR from tangjz/acm-icpc :: lydsy (2408)

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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@o = external dso_local global i32, align 4
@p = external dso_local global [500010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, 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) #4
  br label %25

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %13
  %15 = getelementptr inbounds %"struct.std::pair", ptr %14, i32 0, i32 0
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15)
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %19
  %21 = getelementptr inbounds %"struct.std::pair", ptr %20, i32 0, i32 1
  store i32 %17, ptr %21, align 4, !tbaa !9
  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 !11

25:                                               ; preds = %10
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %"struct.std::pair", ptr @p, i64 %27
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef @p, ptr noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %49, %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %52

34:                                               ; preds = %29
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %36
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr @o, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %41
  %43 = getelementptr inbounds %"struct.std::pair", ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = icmp slt i32 %39, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %34
  %47 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %47, ptr @o, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %46, %34
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %29, !llvm.loop !14

52:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %73, %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %81

58:                                               ; preds = %53
  %59 = load i32, ptr @o, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %60
  %62 = getelementptr inbounds %"struct.std::pair", ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = sub nsw i32 %65, 1
  %67 = icmp eq i32 %64, %66
  %68 = zext i1 %67 to i64
  %69 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !15
  %71 = sext i8 %70 to i32
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %63, i32 noundef %71)
  br label %73

73:                                               ; preds = %58
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !5
  %76 = load i32, ptr @o, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %77
  %79 = getelementptr inbounds %"struct.std::pair", ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !9
  store i32 %80, ptr @o, align 4, !tbaa !5
  br label %53, !llvm.loop !16

81:                                               ; preds = %57
  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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef, ptr noundef) #3

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 = { 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 = !{!10, !6, i64 4}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}


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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@o = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local global [500010 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %4 = getelementptr inbounds %"struct.std::pair", ptr @p, i64 %.pre-phi
  tail call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef nonnull @p, ptr noundef nonnull %4)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph22.preheader, label %._crit_edge25

.lr.ph22.preheader:                               ; preds = %._crit_edge
  %o.promoted = load i32, ptr @o, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %5, 1
  br i1 %7, label %.preheader.unr-lcssa, label %.lr.ph22.preheader.new

.lr.ph22.preheader.new:                           ; preds = %.lr.ph22.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph22

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

.preheader.unr-lcssa:                             ; preds = %39, %.lr.ph22.preheader
  %.01217.lcssa.ph = phi i32 [ poison, %.lr.ph22.preheader ], [ %.01217.1, %39 ]
  %indvars.iv28.unr = phi i64 [ 0, %.lr.ph22.preheader ], [ %indvars.iv.next29.1, %39 ]
  %.0121819.unr = phi i32 [ %o.promoted, %.lr.ph22.preheader ], [ %.01217.1, %39 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph22.epil

.lr.ph22.epil:                                    ; preds = %.preheader.unr-lcssa
  %15 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %indvars.iv28.unr
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = sext i32 %.0121819.unr to i64
  %18 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %17
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp slt i32 %16, %19
  br i1 %20, label %21, label %.preheader

21:                                               ; preds = %.lr.ph22.epil
  %22 = trunc nuw nsw i64 %indvars.iv28.unr to i32
  store i32 %22, ptr @o, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph22.epil, %21, %.preheader.unr-lcssa
  %.01217.lcssa = phi i32 [ %.01217.lcssa.ph, %.preheader.unr-lcssa ], [ %.0121819.unr, %.lr.ph22.epil ], [ %22, %21 ]
  br i1 %6, label %.lr.ph24, label %._crit_edge25

.lr.ph22:                                         ; preds = %39, %.lr.ph22.preheader.new
  %indvars.iv28 = phi i64 [ 0, %.lr.ph22.preheader.new ], [ %indvars.iv.next29.1, %39 ]
  %.0121819 = phi i32 [ %o.promoted, %.lr.ph22.preheader.new ], [ %.01217.1, %39 ]
  %niter = phi i64 [ 0, %.lr.ph22.preheader.new ], [ %niter.next.1, %39 ]
  %23 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %indvars.iv28
  %24 = load i32, ptr %23, align 16, !tbaa !13
  %25 = sext i32 %.0121819 to i64
  %26 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %25
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = icmp slt i32 %24, %27
  br i1 %28, label %29, label %.lr.ph22.1

29:                                               ; preds = %.lr.ph22
  %30 = trunc nuw nsw i64 %indvars.iv28 to i32
  store i32 %30, ptr @o, align 4, !tbaa !5
  br label %.lr.ph22.1

.lr.ph22.1:                                       ; preds = %.lr.ph22, %29
  %.01217 = phi i32 [ %.0121819, %.lr.ph22 ], [ %30, %29 ]
  %indvars.iv.next29 = or disjoint i64 %indvars.iv28, 1
  %31 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %indvars.iv.next29
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = sext i32 %.01217 to i64
  %34 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %33
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = icmp slt i32 %32, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %.lr.ph22.1
  %38 = trunc nuw nsw i64 %indvars.iv.next29 to i32
  store i32 %38, ptr @o, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %37, %.lr.ph22.1
  %.01217.1 = phi i32 [ %.01217, %.lr.ph22.1 ], [ %38, %37 ]
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 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 %.preheader.unr-lcssa, label %.lr.ph22, !llvm.loop !14

._crit_edge25:                                    ; preds = %.lr.ph24, %._crit_edge, %.preheader
  ret i32 0

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %40 = phi i32 [ %56, %.lr.ph24 ], [ %.01217.lcssa, %.preheader ]
  %41 = phi i32 [ %57, %.lr.ph24 ], [ %5, %.preheader ]
  %.023 = phi i32 [ %52, %.lr.ph24 ], [ 0, %.preheader ]
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %42
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = add nsw i32 %41, -1
  %46 = icmp eq i32 %.023, %45
  %47 = zext i1 %46 to i64
  %48 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !15
  %50 = sext i8 %49 to i32
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %44, i32 noundef %50)
  %52 = add nuw nsw i32 %.023, 1
  %53 = load i32, ptr @o, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [500010 x %"struct.std::pair"], ptr @p, i64 0, i64 %54, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !9
  store i32 %56, ptr @o, align 4, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = icmp slt i32 %52, %57
  br i1 %58, label %.lr.ph24, label %._crit_edge25, !llvm.loop !16
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { 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" }

!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, !6, i64 4}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}


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