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

; 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
@pos = external dso_local global i32, align 4
@p = external dso_local global [200001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @pos)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  br label %5

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

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

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %12
  %14 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 0
  call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %14)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %17
  %19 = getelementptr inbounds %"struct.std::pair", ptr %18, i32 0, i32 1
  store i32 %15, ptr %19, align 4, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %21
  %23 = getelementptr inbounds %"struct.std::pair", ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %28, label %26

26:                                               ; preds = %10
  %27 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %27, ptr @pos, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %26, %10
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !12

32:                                               ; preds = %9
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %"struct.std::pair", ptr @p, i64 %34
  %36 = getelementptr inbounds %"struct.std::pair", ptr %35, i64 1
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef @p, ptr noundef %36)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %49, %32
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %37
  %43 = load i32, ptr @pos, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %44
  %46 = getelementptr inbounds %"struct.std::pair", ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %47)
  br label %49

49:                                               ; preds = %42
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !5
  %52 = load i32, ptr @pos, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %53
  %55 = getelementptr inbounds %"struct.std::pair", ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !9
  store i32 %56, ptr @pos, align 4, !tbaa !5
  br label %37, !llvm.loop !14

57:                                               ; preds = %41
  %58 = call i32 @putchar(i32 noundef 10)
  ret i32 0
}

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { "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 #5 = { 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 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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
@pos = external dso_local global i32, align 4
@p = external dso_local global [200001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @n)
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) @pos)
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not13 = icmp slt i32 %1, 0
  br i1 %.not13, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre22 = sext i32 %1 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre22, %.._crit_edge_crit_edge ], [ %12, %10 ]
  %2 = getelementptr inbounds %"struct.std::pair", ptr @p, i64 %.pre-phi
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  tail call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef nonnull @p, ptr noundef nonnull %3)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not1115 = icmp slt i32 %4, 1
  br i1 %.not1115, label %._crit_edge19, label %.lr.ph18.preheader

.lr.ph18.preheader:                               ; preds = %._crit_edge
  %.pre = load i32, ptr @pos, align 4, !tbaa !5
  br label %.lr.ph18

.lr.ph:                                           ; preds = %0, %10
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ 0, %0 ]
  %5 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %indvars.iv
  tail call void @_Z4scanRi(ptr noundef nonnull align 4 dereferenceable(4) %5)
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %7, ptr %6, align 4, !tbaa !9
  %8 = load i32, ptr %5, align 8, !tbaa !11
  %.not12 = icmp eq i32 %8, 0
  br i1 %.not12, label %9, label %10

9:                                                ; preds = %.lr.ph
  store i32 %7, ptr @pos, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %.lr.ph, %9
  %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
  %.not.not = icmp slt i64 %indvars.iv, %12
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge19:                                    ; preds = %.lr.ph18, %._crit_edge
  %13 = tail call i32 @putchar(i32 noundef 10)
  ret i32 0

.lr.ph18:                                         ; preds = %.lr.ph18.preheader, %.lr.ph18
  %14 = phi i32 [ %23, %.lr.ph18 ], [ %.pre, %.lr.ph18.preheader ]
  %.016 = phi i32 [ %19, %.lr.ph18 ], [ 1, %.lr.ph18.preheader ]
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %15
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %17)
  %19 = add nuw nsw i32 %.016, 1
  %20 = load i32, ptr @pos, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200001 x %"struct.std::pair"], ptr @p, i64 0, i64 %21, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %23, ptr @pos, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %.not11.not = icmp slt i32 %.016, %24
  br i1 %.not11.not, label %.lr.ph18, label %._crit_edge19, !llvm.loop !14
}

; 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 #3

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { 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 #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" }
attributes #3 = { 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 #4 = { 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" }

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


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