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

; 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.Seg = type { i32, i32 }

@n = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@p = external dso_local global [50001 x %struct.Seg], align 16
@.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
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = 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 %5

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

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

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.Seg, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Seg, ptr %17, i32 0, i32 1
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %14, ptr noundef %18)
  br label %20

20:                                               ; preds = %10
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

23:                                               ; preds = %9
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.Seg, ptr @p, i64 %25
  call void @_ZSt4sortIP3SegEvT_S2_(ptr noundef @p, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %27

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

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

32:                                               ; preds = %27
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Seg, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr @last, align 4, !tbaa !5
  %39 = icmp sge i32 %37, %38
  br i1 %39, label %40, label %48

40:                                               ; preds = %32
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Seg, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !13
  store i32 %45, ptr @last, align 4, !tbaa !5
  %46 = load i32, ptr @ans, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @ans, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %40, %32
  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 %27, !llvm.loop !14

52:                                               ; preds = %31
  %53 = load i32, ptr @ans, align 4, !tbaa !5
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %53)
  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 @_ZSt4sortIP3SegEvT_S2_(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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS3Seg", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !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"

%struct.Seg = type { i32, i32 }

@n = external dso_local global i32, align 4
@last = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local global [50001 x %struct.Seg], align 16
@.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() 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 ], [ %12, %.lr.ph ]
  %4 = getelementptr inbounds %struct.Seg, ptr @p, i64 %.pre-phi
  tail call void @_ZSt4sortIP3SegEvT_S2_(ptr noundef nonnull @p, ptr noundef nonnull %4)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph13.preheader, label %._crit_edge14

.lr.ph13.preheader:                               ; preds = %._crit_edge
  %last.promoted = load i32, ptr @last, 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 %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13.preheader.new

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %8 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %indvars.iv
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %8, ptr noundef nonnull %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
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge14.loopexit.unr-lcssa:                 ; preds = %38, %.lr.ph13.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph13.preheader ], [ %39, %38 ]
  %indvars.iv17.unr = phi i64 [ 0, %.lr.ph13.preheader ], [ %indvars.iv.next18.1, %38 ]
  %.unr = phi i32 [ %last.promoted, %.lr.ph13.preheader ], [ %40, %38 ]
  %.unr23 = phi i32 [ %ans.promoted, %.lr.ph13.preheader ], [ %39, %38 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge14, label %.lr.ph13.epil

.lr.ph13.epil:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa
  %14 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %indvars.iv17.unr
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %.not.epil = icmp slt i32 %15, %.unr
  br i1 %.not.epil, label %._crit_edge14, label %16

16:                                               ; preds = %.lr.ph13.epil
  %17 = getelementptr inbounds i8, ptr %14, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !13
  store i32 %18, ptr @last, align 4, !tbaa !5
  %19 = add nsw i32 %.unr23, 1
  store i32 %19, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge14

._crit_edge14:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa, %16, %.lr.ph13.epil, %._crit_edge
  %20 = phi i32 [ %ans.promoted, %._crit_edge ], [ %.lcssa.ph, %._crit_edge14.loopexit.unr-lcssa ], [ %.unr23, %.lr.ph13.epil ], [ %19, %16 ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %20)
  ret i32 0

.lr.ph13:                                         ; preds = %38, %.lr.ph13.preheader.new
  %indvars.iv17 = phi i64 [ 0, %.lr.ph13.preheader.new ], [ %indvars.iv.next18.1, %38 ]
  %22 = phi i32 [ %last.promoted, %.lr.ph13.preheader.new ], [ %40, %38 ]
  %23 = phi i32 [ %ans.promoted, %.lr.ph13.preheader.new ], [ %39, %38 ]
  %niter = phi i64 [ 0, %.lr.ph13.preheader.new ], [ %niter.next.1, %38 ]
  %24 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %indvars.iv17
  %25 = load i32, ptr %24, align 16, !tbaa !11
  %.not = icmp slt i32 %25, %22
  br i1 %.not, label %.lr.ph13.1, label %26

26:                                               ; preds = %.lr.ph13
  %27 = getelementptr inbounds i8, ptr %24, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr @last, align 4, !tbaa !5
  %29 = add nsw i32 %23, 1
  store i32 %29, ptr @ans, align 4, !tbaa !5
  br label %.lr.ph13.1

.lr.ph13.1:                                       ; preds = %.lr.ph13, %26
  %30 = phi i32 [ %23, %.lr.ph13 ], [ %29, %26 ]
  %31 = phi i32 [ %22, %.lr.ph13 ], [ %28, %26 ]
  %indvars.iv.next18 = or disjoint i64 %indvars.iv17, 1
  %32 = getelementptr inbounds [50001 x %struct.Seg], ptr @p, i64 0, i64 %indvars.iv.next18
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %.not.1 = icmp slt i32 %33, %31
  br i1 %.not.1, label %38, label %34

34:                                               ; preds = %.lr.ph13.1
  %35 = getelementptr inbounds i8, ptr %32, i64 4
  %36 = load i32, ptr %35, align 4, !tbaa !13
  store i32 %36, ptr @last, align 4, !tbaa !5
  %37 = add nsw i32 %30, 1
  store i32 %37, ptr @ans, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %34, %.lr.ph13.1
  %39 = phi i32 [ %30, %.lr.ph13.1 ], [ %37, %34 ]
  %40 = phi i32 [ %31, %.lr.ph13.1 ], [ %36, %34 ]
  %indvars.iv.next18.1 = add nuw nsw i64 %indvars.iv17, 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 %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13, !llvm.loop !14
}

; 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 @_ZSt4sortIP3SegEvT_S2_(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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS3Seg", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !10}


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