; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1159)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [101 x %struct.Node], 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
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %57, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %60

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

10:                                               ; preds = %25, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %28

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.Node, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %19, ptr noundef %23)
  br label %25

25:                                               ; preds = %15
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

28:                                               ; preds = %14
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.Node, ptr @a, i64 %30
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @a, ptr noundef %31)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %54, %28
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %32
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp sge i32 %42, %43
  br i1 %44, label %45, label %53

45:                                               ; preds = %37
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !13
  store i32 %52, ptr %4, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %45, %37
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !5
  br label %32, !llvm.loop !14

57:                                               ; preds = %36
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %6, !llvm.loop !15

60:                                               ; preds = %6
  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 @_ZSt4sortIP4NodeEvT_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 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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.Node = type { i32, i32 }

@n = external dso_local global i32, align 4
@a = external dso_local global [101 x %struct.Node], 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 = icmp eq i32 %1, 1
  br i1 %2, label %.preheader, label %._crit_edge24

.preheader:                                       ; preds = %0, %._crit_edge22
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader.._crit_edge_crit_edge

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre = sext i32 %3 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %5 = getelementptr inbounds %struct.Node, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @a, ptr noundef nonnull %5)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph21.preheader, label %._crit_edge22

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %6 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %6, 1
  br i1 %8, label %._crit_edge22.loopexit.unr-lcssa, label %.lr.ph21.preheader.new

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

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %9 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9, ptr noundef nonnull %10)
  %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 !9

._crit_edge22.loopexit.unr-lcssa:                 ; preds = %33, %.lr.ph21.preheader
  %.113.lcssa.ph = phi i32 [ poison, %.lr.ph21.preheader ], [ %.113.1, %33 ]
  %indvars.iv27.unr = phi i64 [ 0, %.lr.ph21.preheader ], [ %indvars.iv.next28.1, %33 ]
  %.01118.unr = phi i32 [ 0, %.lr.ph21.preheader ], [ %.1.1, %33 ]
  %.01217.unr = phi i32 [ 0, %.lr.ph21.preheader ], [ %.113.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge22, label %.lr.ph21.epil

.lr.ph21.epil:                                    ; preds = %._crit_edge22.loopexit.unr-lcssa
  %15 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv27.unr
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %.not.epil = icmp slt i32 %16, %.01118.unr
  %17 = add nsw i32 %.01217.unr, 1
  %spec.select = select i1 %.not.epil, i32 %.01217.unr, i32 %17
  br label %._crit_edge22

._crit_edge22:                                    ; preds = %.lr.ph21.epil, %._crit_edge22.loopexit.unr-lcssa, %._crit_edge
  %.012.lcssa = phi i32 [ 0, %._crit_edge ], [ %.113.lcssa.ph, %._crit_edge22.loopexit.unr-lcssa ], [ %spec.select, %.lr.ph21.epil ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.012.lcssa)
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %.preheader, label %._crit_edge24, !llvm.loop !13

.lr.ph21:                                         ; preds = %33, %.lr.ph21.preheader.new
  %indvars.iv27 = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %indvars.iv.next28.1, %33 ]
  %.01118 = phi i32 [ 0, %.lr.ph21.preheader.new ], [ %.1.1, %33 ]
  %.01217 = phi i32 [ 0, %.lr.ph21.preheader.new ], [ %.113.1, %33 ]
  %niter = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %niter.next.1, %33 ]
  %21 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv27
  %22 = load i32, ptr %21, align 16, !tbaa !11
  %.not = icmp slt i32 %22, %.01118
  br i1 %.not, label %.lr.ph21.1, label %23

23:                                               ; preds = %.lr.ph21
  %24 = add nsw i32 %.01217, 1
  %25 = getelementptr inbounds i8, ptr %21, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !14
  br label %.lr.ph21.1

.lr.ph21.1:                                       ; preds = %.lr.ph21, %23
  %.113 = phi i32 [ %24, %23 ], [ %.01217, %.lr.ph21 ]
  %.1 = phi i32 [ %26, %23 ], [ %.01118, %.lr.ph21 ]
  %indvars.iv.next28 = or disjoint i64 %indvars.iv27, 1
  %27 = getelementptr inbounds [101 x %struct.Node], ptr @a, i64 0, i64 %indvars.iv.next28
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %.not.1 = icmp slt i32 %28, %.1
  br i1 %.not.1, label %33, label %29

29:                                               ; preds = %.lr.ph21.1
  %30 = add nsw i32 %.113, 1
  %31 = getelementptr inbounds i8, ptr %27, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %29, %.lr.ph21.1
  %.113.1 = phi i32 [ %30, %29 ], [ %.113, %.lr.ph21.1 ]
  %.1.1 = phi i32 [ %32, %29 ], [ %.1, %.lr.ph21.1 ]
  %indvars.iv.next28.1 = add nuw nsw i64 %indvars.iv27, 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_edge22.loopexit.unr-lcssa, label %.lr.ph21, !llvm.loop !15

._crit_edge24:                                    ; preds = %._crit_edge22, %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 @_ZSt4sortIP4NodeEvT_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 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4}
!13 = distinct !{!13, !10}
!14 = !{!12, !6, i64 4}
!15 = distinct !{!15, !10}


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