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

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

@n = external dso_local global i32, align 4
@s = external dso_local global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %9

9:                                                ; preds = %100, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @s)
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %12, label %103

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

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

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %26

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr @a, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %21)
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

26:                                               ; preds = %17
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr @a, i64 %28
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %29)
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %97, %26
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %100

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %93, %35
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 10, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %96

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = icmp sgt i32 %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  store i32 12, ptr %4, align 4
  br label %90

52:                                               ; preds = %43
  br label %53

53:                                               ; preds = %83, %52
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %84

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = add nsw i32 %58, %59
  %61 = ashr i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = add nsw i32 %65, %69
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = add nsw i32 %70, %74
  %76 = load i32, ptr @s, align 4, !tbaa !5
  %77 = icmp sgt i32 %75, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %57
  %79 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %79, ptr %7, align 4, !tbaa !5
  br label %83

80:                                               ; preds = %57
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %6, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %80, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %53, !llvm.loop !11

84:                                               ; preds = %53
  %85 = load i32, ptr @n, align 4, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = sub nsw i32 %85, %86
  %88 = load i32, ptr @ans, align 4, !tbaa !5
  %89 = add nsw i32 %88, %87
  store i32 %89, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %90

90:                                               ; preds = %84, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %91 = load i32, ptr %4, align 4
  switch i32 %91, label %104 [
    i32 0, label %92
    i32 12, label %93
  ]

92:                                               ; preds = %90
  br label %93

93:                                               ; preds = %92, %90
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %5, align 4, !tbaa !5
  br label %38, !llvm.loop !12

96:                                               ; preds = %42
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %3, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !13

100:                                              ; preds = %34
  %101 = load i32, ptr @ans, align 4, !tbaa !5
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %101)
  br label %9, !llvm.loop !14

103:                                              ; preds = %9
  ret i32 0

104:                                              ; preds = %90
  unreachable
}

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 @_ZSt4sortIPiEvT_S1_(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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!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"

@n = external dso_local global i32, align 4
@s = external dso_local global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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, ptr noundef nonnull @s)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.preheader30, label %._crit_edge50

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

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

._crit_edge:                                      ; preds = %.lr.ph, %.preheader30.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader30.._crit_edge_crit_edge ], [ %15, %.lr.ph ]
  %5 = getelementptr inbounds i32, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %5)
  store i32 0, ptr @ans, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph48, label %._crit_edge49

.lr.ph48:                                         ; preds = %._crit_edge
  %8 = add nsw i32 %6, -1
  %9 = load i32, ptr @s, align 4
  %10 = zext nneg i32 %8 to i64
  %11 = zext nneg i32 %6 to i64
  %wide.trip.count61 = zext nneg i32 %6 to i64
  br label %21

.lr.ph:                                           ; preds = %.preheader30, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader30 ]
  %12 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, 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 = %44, %21
  %ans.promoted41 = phi i32 [ %ans.promoted4445, %21 ], [ %ans.promoted42, %44 ]
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond62.not = icmp eq i64 %indvars.iv.next59, %wide.trip.count61
  br i1 %exitcond62.not, label %._crit_edge49, label %21, !llvm.loop !11

._crit_edge49:                                    ; preds = %.loopexit, %._crit_edge
  %17 = phi i32 [ 0, %._crit_edge ], [ %ans.promoted41, %.loopexit ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %17)
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @s)
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %.preheader30, label %._crit_edge50, !llvm.loop !12

21:                                               ; preds = %.lr.ph48, %.loopexit
  %indvars.iv58 = phi i64 [ 0, %.lr.ph48 ], [ %indvars.iv.next59, %.loopexit ]
  %indvars.iv53 = phi i64 [ 1, %.lr.ph48 ], [ %indvars.iv.next54, %.loopexit ]
  %ans.promoted4445 = phi i32 [ 0, %.lr.ph48 ], [ %ans.promoted41, %.loopexit ]
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %22 = icmp ult i64 %indvars.iv.next59, %11
  br i1 %22, label %.lr.ph39, label %.loopexit

.lr.ph39:                                         ; preds = %21
  %23 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %indvars.iv58
  br label %24

24:                                               ; preds = %.lr.ph39, %44
  %indvars.iv55 = phi i64 [ %indvars.iv53, %.lr.ph39 ], [ %indvars.iv.next56, %44 ]
  %ans.promoted43 = phi i32 [ %ans.promoted4445, %.lr.ph39 ], [ %ans.promoted42, %44 ]
  %25 = phi i32 [ %ans.promoted4445, %.lr.ph39 ], [ %45, %44 ]
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %.not = icmp ult i64 %indvars.iv55, %10
  br i1 %.not, label %.preheader, label %44

.preheader:                                       ; preds = %24
  %26 = trunc nuw i64 %indvars.iv.next56 to i32
  %27 = icmp sgt i32 %8, %26
  br i1 %27, label %.lr.ph34, label %._crit_edge35

.lr.ph34:                                         ; preds = %.preheader
  %28 = load i32, ptr %23, align 4, !tbaa !5
  %29 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %indvars.iv55
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, %28
  br label %32

32:                                               ; preds = %.lr.ph34, %32
  %.02133 = phi i32 [ %8, %.lr.ph34 ], [ %.1, %32 ]
  %.02232 = phi i32 [ %26, %.lr.ph34 ], [ %.123, %32 ]
  %33 = add nsw i32 %.02133, %.02232
  %34 = ashr i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %31, %37
  %39 = icmp sgt i32 %38, %9
  %40 = add nsw i32 %34, 1
  %.123 = select i1 %39, i32 %.02232, i32 %40
  %.1 = select i1 %39, i32 %34, i32 %.02133
  %41 = icmp slt i32 %.123, %.1
  br i1 %41, label %32, label %._crit_edge35, !llvm.loop !13

._crit_edge35:                                    ; preds = %32, %.preheader
  %.022.lcssa = phi i32 [ %26, %.preheader ], [ %.123, %32 ]
  %42 = sub i32 %6, %.022.lcssa
  %43 = add nsw i32 %42, %25
  store i32 %43, ptr @ans, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %24, %._crit_edge35
  %ans.promoted42 = phi i32 [ %ans.promoted43, %24 ], [ %43, %._crit_edge35 ]
  %45 = phi i32 [ %25, %24 ], [ %43, %._crit_edge35 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count61
  br i1 %exitcond.not, label %.loopexit, label %24, !llvm.loop !14

._crit_edge50:                                    ; preds = %._crit_edge49, %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 @_ZSt4sortIPiEvT_S1_(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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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