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

; 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 [2 x i32], align 4
@ans = external dso_local global i32, align 4
@p = external dso_local global [151 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) #5
  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) #5
  br label %23

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [151 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 [151 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) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %71, %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) #5
  br label %74

32:                                               ; preds = %27
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [151 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 [151 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 %65

48:                                               ; preds = %32
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [151 x %struct.Seg], ptr @p, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Seg, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @last, i64 0, i64 1), align 4, !tbaa !5
  %55 = icmp sge i32 %53, %54
  br i1 %55, label %56, label %64

56:                                               ; preds = %48
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [151 x %struct.Seg], ptr @p, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Seg, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !13
  store i32 %61, ptr getelementptr inbounds ([2 x i32], ptr @last, i64 0, i64 1), align 4, !tbaa !5
  %62 = load i32, ptr @ans, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr @ans, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %56, %48
  br label %65

65:                                               ; preds = %64, %40
  %66 = load i32, ptr @last, align 4, !tbaa !5
  %67 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @last, i64 0, i64 1), align 4, !tbaa !5
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %65
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) getelementptr inbounds ([2 x i32], ptr @last, i64 0, i64 1)) #5
  br label %70

70:                                               ; preds = %69, %65
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !14

74:                                               ; preds = %31
  %75 = load i32, ptr @ans, align 4, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %75)
  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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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 = { inlinehint mustprogress 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 #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 = 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 global [2 x i32], align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local global [151 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
  %.pre27 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre27, %.._crit_edge_crit_edge ], [ %11, %.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
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph17.preheader, label %._crit_edge18

.lr.ph17.preheader:                               ; preds = %._crit_edge
  %.pre24 = load i32, ptr @last, align 4, !tbaa !5
  br label %.lr.ph17

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

._crit_edge18:                                    ; preds = %36, %._crit_edge
  %13 = load i32, ptr @ans, align 4, !tbaa !5
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %13)
  ret i32 0

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %36
  %15 = phi i32 [ %5, %.lr.ph17.preheader ], [ %37, %36 ]
  %16 = phi i32 [ %.pre24, %.lr.ph17.preheader ], [ %38, %36 ]
  %indvars.iv21 = phi i64 [ 0, %.lr.ph17.preheader ], [ %indvars.iv.next22, %36 ]
  %17 = getelementptr inbounds [151 x %struct.Seg], ptr @p, i64 0, i64 %indvars.iv21
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %.not = icmp slt i32 %18, %16
  br i1 %.not, label %24, label %19

19:                                               ; preds = %.lr.ph17
  %20 = getelementptr inbounds i8, ptr %17, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !13
  store i32 %21, ptr @last, align 4, !tbaa !5
  %22 = load i32, ptr @ans, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @ans, align 4, !tbaa !5
  %.pre25 = load i32, ptr getelementptr inbounds (i8, ptr @last, i64 4), align 4, !tbaa !5
  br label %31

24:                                               ; preds = %.lr.ph17
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @last, i64 4), align 4, !tbaa !5
  %.not13 = icmp slt i32 %18, %25
  br i1 %.not13, label %31, label %26

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %17, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr getelementptr inbounds (i8, ptr @last, i64 4), align 4, !tbaa !5
  %29 = load i32, ptr @ans, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @ans, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %24, %26, %19
  %32 = phi i32 [ %25, %24 ], [ %28, %26 ], [ %.pre25, %19 ]
  %33 = phi i32 [ %16, %24 ], [ %16, %26 ], [ %21, %19 ]
  %34 = icmp slt i32 %33, %32
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) getelementptr inbounds (i8, ptr @last, i64 4)) #4
  %.pre = load i32, ptr @last, align 4, !tbaa !5
  %.pre26 = load i32, ptr @n, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %31, %35
  %37 = phi i32 [ %15, %31 ], [ %.pre26, %35 ]
  %38 = phi i32 [ %33, %31 ], [ %.pre, %35 ]
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %39 = sext i32 %37 to i64
  %40 = icmp slt i64 %indvars.iv.next22, %39
  br i1 %40, label %.lr.ph17, label %._crit_edge18, !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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; 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" }
attributes #3 = { inlinehint mustprogress 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 #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}


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