; LLVM IR from tangjz/acm-icpc :: hdu (6011)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [27 x %"struct.std::pair"], 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 [7 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 i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %9

9:                                                ; preds = %76, %0
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !5
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %79

13:                                               ; preds = %9
  %14 = 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 %15

15:                                               ; preds = %30, %13
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %33

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [27 x %"struct.std::pair"], ptr @a, i64 0, i64 %22
  %24 = getelementptr inbounds %"struct.std::pair", ptr %23, i32 0, i32 0
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [27 x %"struct.std::pair"], ptr @a, i64 0, i64 %26
  %28 = getelementptr inbounds %"struct.std::pair", ptr %27, i32 0, i32 1
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %24, ptr noundef %28)
  br label %30

30:                                               ; preds = %20
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %15, !llvm.loop !9

33:                                               ; preds = %19
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %35
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef @a, ptr noundef %36)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %73, %33
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = icmp sge i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  store i32 7, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %76

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

44:                                               ; preds = %69, %43
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [27 x %"struct.std::pair"], ptr @a, i64 0, i64 %47
  %49 = getelementptr inbounds %"struct.std::pair", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp slt i32 %45, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %44
  store i32 10, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %72

53:                                               ; preds = %44
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [27 x %"struct.std::pair"], ptr @a, i64 0, i64 %55
  %57 = getelementptr inbounds %"struct.std::pair", ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !15
  %59 = sext i32 %58 to i64
  %60 = load i64, ptr %4, align 8, !tbaa !11
  %61 = add nsw i64 %60, %59
  store i64 %61, ptr %4, align 8, !tbaa !11
  %62 = load i64, ptr %4, align 8, !tbaa !11
  %63 = icmp sge i64 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %53
  %65 = load i64, ptr %4, align 8, !tbaa !11
  %66 = load i64, ptr %3, align 8, !tbaa !11
  %67 = add nsw i64 %66, %65
  store i64 %67, ptr %3, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %64, %53
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !5
  br label %44, !llvm.loop !16

72:                                               ; preds = %52
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %5, align 4, !tbaa !5
  br label %39, !llvm.loop !17

76:                                               ; preds = %42
  %77 = load i64, ptr %3, align 8, !tbaa !11
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %9, !llvm.loop !18

79:                                               ; preds = %9
  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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 4}
!14 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !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.std::pair" = type { i32, i32 }

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [27 x %"struct.std::pair"], 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 [7 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not35 = icmp eq i32 %2, 0
  br i1 %.not35, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %0, %._crit_edge33
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.lr.ph37.._crit_edge_crit_edge

.lr.ph37.._crit_edge_crit_edge:                   ; preds = %.lr.ph37
  %.pre = sext i32 %5 to i64
  br label %._crit_edge

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

.preheader.preheader:                             ; preds = %._crit_edge
  %10 = zext nneg i32 %8 to i64
  br label %.preheader

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

.loopexit:                                        ; preds = %scalar.ph, %middle.block, %.preheader
  %.118.lcssa = phi i64 [ %.01730, %.preheader ], [ %36, %middle.block ], [ %spec.select, %scalar.ph ]
  %.1.lcssa = phi i64 [ %.01631, %.preheader ], [ %ind.end47, %middle.block ], [ %40, %scalar.ph ]
  %17 = icmp sgt i64 %indvars.iv42, 1
  br i1 %17, label %.preheader, label %._crit_edge33, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %indvars.iv42 = phi i64 [ %10, %.preheader.preheader ], [ %indvars.iv.next43, %.loopexit ]
  %.01631 = phi i64 [ 0, %.preheader.preheader ], [ %.1.lcssa, %.loopexit ]
  %.01730 = phi i64 [ 0, %.preheader.preheader ], [ %.118.lcssa, %.loopexit ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, -1
  %18 = getelementptr inbounds [27 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv.next43
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %.preheader
  %22 = load i32, ptr %18, align 8, !tbaa !14
  %23 = sext i32 %22 to i64
  %24 = zext nneg i32 %20 to i64
  %min.iters.check = icmp ult i32 %20, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph26
  %.025.ph = phi i32 [ 0, %.lr.ph26 ], [ %ind.end, %middle.block ]
  %.124.ph = phi i64 [ %.01631, %.lr.ph26 ], [ %ind.end47, %middle.block ]
  %.11823.ph = phi i64 [ %.01730, %.lr.ph26 ], [ %36, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph26
  %n.vec = and i64 %24, 2147483644
  %ind.end = trunc nuw nsw i64 %n.vec to i32
  %25 = mul nsw i64 %n.vec, %23
  %ind.end47 = add i64 %.01631, %25
  %.splatinsert = insertelement <2 x i64> poison, i64 %.01631, i64 0
  %.splat = shufflevector <2 x i64> %.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %.splatinsert49 = insertelement <2 x i64> poison, i64 %23, i64 0
  %.splat50 = shufflevector <2 x i64> %.splatinsert49, <2 x i64> poison, <2 x i32> zeroinitializer
  %26 = mul nuw <2 x i64> %.splat50, <i64 0, i64 1>
  %induction = add <2 x i64> %.splat, %26
  %27 = shl nsw i64 %23, 1
  %.splatinsert51 = insertelement <2 x i64> poison, i64 %27, i64 0
  %.splat52 = shufflevector <2 x i64> %.splatinsert51, <2 x i64> poison, <2 x i32> zeroinitializer
  %28 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.01730, i64 0
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %23, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ %induction, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %28, %vector.ph ], [ %33, %vector.body ]
  %vec.phi54 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %34, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, %.splat52
  %29 = add nsw <2 x i64> %vec.ind, %broadcast.splat
  %30 = add nsw <2 x i64> %step.add, %broadcast.splat
  %31 = tail call <2 x i64> @llvm.smax.v2i64(<2 x i64> %29, <2 x i64> zeroinitializer)
  %32 = tail call <2 x i64> @llvm.smax.v2i64(<2 x i64> %30, <2 x i64> zeroinitializer)
  %33 = add <2 x i64> %31, %vec.phi
  %34 = add <2 x i64> %32, %vec.phi54
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %step.add, %.splat52
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %34, %33
  %36 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %24
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

._crit_edge33:                                    ; preds = %.loopexit, %._crit_edge
  %.017.lcssa = phi i64 [ 0, %._crit_edge ], [ %.118.lcssa, %.loopexit ]
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.017.lcssa)
  %38 = load i32, ptr @t, align 4, !tbaa !5
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %38, 0
  br i1 %.not, label %._crit_edge38, label %.lr.ph37, !llvm.loop !18

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.025 = phi i32 [ %42, %scalar.ph ], [ %.025.ph, %scalar.ph.preheader ]
  %.124 = phi i64 [ %40, %scalar.ph ], [ %.124.ph, %scalar.ph.preheader ]
  %.11823 = phi i64 [ %spec.select, %scalar.ph ], [ %.11823.ph, %scalar.ph.preheader ]
  %40 = add nsw i64 %.124, %23
  %41 = tail call i64 @llvm.smax.i64(i64 %40, i64 0)
  %spec.select = add nsw i64 %41, %.11823
  %42 = add nuw nsw i32 %.025, 1
  %exitcond.not = icmp eq i32 %42, %20
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !19

._crit_edge38:                                    ; preds = %._crit_edge33, %0
  ret i32 0
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.smax.v2i64(<2 x i64>, <2 x i64>) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}
!12 = !{!13, !6, i64 4}
!13 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!14 = !{!13, !6, i64 0}
!15 = distinct !{!15, !10, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10, !17, !16}


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