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

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

%"class.std::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::pair" = type <{ %"struct.std::_Rb_tree_const_iterator", i8, [7 x i8] }>
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@f = external dso_local global [500002 x i32], align 16
@ord = external dso_local global [500002 x i32], align 16
@ans = external dso_local global i32, align 4
@Q = external dso_local global %"class.std::set", align 8
@s = external dso_local global [500002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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 %"struct.std::pair", align 8
  %9 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %10 = alloca i32, align 4
  %11 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef getelementptr inbounds (i8, ptr @s, i64 1))
  store i8 13, ptr @s, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 1, ptr %2, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  br label %14

14:                                               ; preds = %104, %0
  %15 = load i32, ptr %2, align 4, !tbaa !8
  %16 = load i32, ptr @n, align 4, !tbaa !8
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  %20 = load i32, ptr %3, align 4, !tbaa !8
  %21 = load i32, ptr %2, align 4, !tbaa !8
  %22 = icmp sge i32 %20, %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  br i1 %22, label %23, label %35

23:                                               ; preds = %19
  %24 = load i32, ptr %3, align 4, !tbaa !8
  %25 = load i32, ptr %2, align 4, !tbaa !8
  %26 = sub nsw i32 %24, %25
  store i32 %26, ptr %5, align 4, !tbaa !8
  %27 = load i32, ptr %4, align 4, !tbaa !8
  %28 = mul nsw i32 2, %27
  %29 = load i32, ptr %2, align 4, !tbaa !8
  %30 = sub nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %31
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %32)
  %34 = load i32, ptr %33, align 4, !tbaa !8
  br label %36

35:                                               ; preds = %19
  br label %36

36:                                               ; preds = %35, %23
  %37 = phi i32 [ %34, %23 ], [ 0, %35 ]
  %38 = load i32, ptr %2, align 4, !tbaa !8
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %39
  store i32 %37, ptr %40, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %41

41:                                               ; preds = %76, %36
  %42 = load i32, ptr %2, align 4, !tbaa !8
  %43 = load i32, ptr %2, align 4, !tbaa !8
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !8
  %47 = add nsw i32 %42, %46
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr @n, align 4, !tbaa !8
  %50 = icmp sle i32 %48, %49
  br i1 %50, label %51, label %74

51:                                               ; preds = %41
  %52 = load i32, ptr %2, align 4, !tbaa !8
  %53 = load i32, ptr %2, align 4, !tbaa !8
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !8
  %57 = add nsw i32 %52, %56
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [500002 x i8], ptr @s, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !5
  %62 = sext i8 %61 to i32
  %63 = load i32, ptr %2, align 4, !tbaa !8
  %64 = load i32, ptr %2, align 4, !tbaa !8
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !8
  %68 = sub nsw i32 %63, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [500002 x i8], ptr @s, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !5
  %72 = sext i8 %71 to i32
  %73 = icmp eq i32 %62, %72
  br label %74

74:                                               ; preds = %51, %41
  %75 = phi i1 [ false, %41 ], [ %73, %51 ]
  br i1 %75, label %76, label %82

76:                                               ; preds = %74
  %77 = load i32, ptr %2, align 4, !tbaa !8
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !8
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %79, align 4, !tbaa !8
  br label %41, !llvm.loop !10

82:                                               ; preds = %74
  %83 = load i32, ptr %2, align 4, !tbaa !8
  %84 = load i32, ptr %2, align 4, !tbaa !8
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !8
  %88 = add nsw i32 %83, %87
  %89 = load i32, ptr %3, align 4, !tbaa !8
  %90 = icmp sgt i32 %88, %89
  br i1 %90, label %91, label %99

91:                                               ; preds = %82
  %92 = load i32, ptr %2, align 4, !tbaa !8
  %93 = load i32, ptr %2, align 4, !tbaa !8
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !8
  %97 = add nsw i32 %92, %96
  store i32 %97, ptr %3, align 4, !tbaa !8
  %98 = load i32, ptr %2, align 4, !tbaa !8
  store i32 %98, ptr %4, align 4, !tbaa !8
  br label %99

99:                                               ; preds = %91, %82
  %100 = load i32, ptr %2, align 4, !tbaa !8
  %101 = load i32, ptr %2, align 4, !tbaa !8
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %102
  store i32 %100, ptr %103, align 4, !tbaa !8
  br label %104

104:                                              ; preds = %99
  %105 = load i32, ptr %2, align 4, !tbaa !8
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %2, align 4, !tbaa !8
  br label %14, !llvm.loop !12

107:                                              ; preds = %18
  %108 = load i32, ptr @n, align 4, !tbaa !8
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds i32, ptr @ord, i64 %109
  %111 = getelementptr inbounds i32, ptr %110, i64 1
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef getelementptr inbounds (i32, ptr @ord, i64 1), ptr noundef %111, ptr noundef @_Z3cmpRKiS0_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 1, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 1, ptr %7, align 4, !tbaa !8
  br label %112

112:                                              ; preds = %174, %107
  %113 = load i32, ptr %6, align 4, !tbaa !8
  %114 = load i32, ptr @n, align 4, !tbaa !8
  %115 = icmp sle i32 %113, %114
  br i1 %115, label %117, label %116

116:                                              ; preds = %112
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %177

117:                                              ; preds = %112
  br label %118

118:                                              ; preds = %148, %117
  %119 = load i32, ptr %7, align 4, !tbaa !8
  %120 = load i32, ptr @n, align 4, !tbaa !8
  %121 = icmp sle i32 %119, %120
  br i1 %121, label %122, label %137

122:                                              ; preds = %118
  %123 = load i32, ptr %7, align 4, !tbaa !8
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %124
  %126 = load i32, ptr %125, align 4, !tbaa !8
  %127 = load i32, ptr %7, align 4, !tbaa !8
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %128
  %130 = load i32, ptr %129, align 4, !tbaa !8
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %131
  %133 = load i32, ptr %132, align 4, !tbaa !8
  %134 = sub nsw i32 %126, %133
  %135 = load i32, ptr %6, align 4, !tbaa !8
  %136 = icmp sle i32 %134, %135
  br label %137

137:                                              ; preds = %122, %118
  %138 = phi i1 [ false, %118 ], [ %136, %122 ]
  br i1 %138, label %139, label %151

139:                                              ; preds = %137
  %140 = load i32, ptr %7, align 4, !tbaa !8
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %141
  %143 = call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48) @Q, ptr noundef nonnull align 4 dereferenceable(4) %142)
  %144 = getelementptr inbounds { ptr, i8 }, ptr %8, i32 0, i32 0
  %145 = extractvalue { ptr, i8 } %143, 0
  store ptr %145, ptr %144, align 8
  %146 = getelementptr inbounds { ptr, i8 }, ptr %8, i32 0, i32 1
  %147 = extractvalue { ptr, i8 } %143, 1
  store i8 %147, ptr %146, align 8
  br label %148

148:                                              ; preds = %139
  %149 = load i32, ptr %7, align 4, !tbaa !8
  %150 = add nsw i32 %149, 1
  store i32 %150, ptr %7, align 4, !tbaa !8
  br label %118, !llvm.loop !13

151:                                              ; preds = %137
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %152 = load i32, ptr %6, align 4, !tbaa !8
  %153 = load i32, ptr %6, align 4, !tbaa !8
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %154
  %156 = load i32, ptr %155, align 4, !tbaa !8
  %157 = sdiv i32 %156, 2
  %158 = add nsw i32 %152, %157
  store i32 %158, ptr %10, align 4, !tbaa !8
  %159 = call ptr @_ZNSt3setIiSt4lessIiESaIiEE11upper_boundERKi(ptr noundef nonnull align 8 dereferenceable(48) @Q, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %160 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %9, i32 0, i32 0
  store ptr %159, ptr %160, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %161 = call ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @Q) #7
  %162 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %11, i32 0, i32 0
  store ptr %161, ptr %162, align 8
  %163 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br i1 %163, label %164, label %173

164:                                              ; preds = %151
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %165 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt23_Rb_tree_const_iteratorIiEmmEv(ptr noundef nonnull align 8 dereferenceable(8) %9) #7
  %166 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %165) #7
  %167 = load i32, ptr %166, align 4, !tbaa !8
  %168 = load i32, ptr %6, align 4, !tbaa !8
  %169 = sub nsw i32 %167, %168
  %170 = mul nsw i32 %169, 4
  store i32 %170, ptr %12, align 4, !tbaa !8
  %171 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %172 = load i32, ptr %171, align 4, !tbaa !8
  store i32 %172, ptr @ans, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %173

173:                                              ; preds = %164, %151
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  br label %174

174:                                              ; preds = %173
  %175 = load i32, ptr %6, align 4, !tbaa !8
  %176 = add nsw i32 %175, 1
  store i32 %176, ptr %6, align 4, !tbaa !8
  br label %112, !llvm.loop !14

177:                                              ; preds = %116
  %178 = load i32, ptr @ans, align 4, !tbaa !8
  %179 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %178)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #6 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt3setIiSt4lessIiESaIiEE11upper_boundERKi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #6 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt23_Rb_tree_const_iteratorIiEmmEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

declare i32 @printf(ptr noundef, ...) #2

attributes #0 = { 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 #1 = { 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 #2 = { "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 willreturn memory(argmem: readwrite) }
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 = { 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 #6 = { 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 #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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

%"class.std::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@f = external dso_local global [500002 x i32], align 16
@ord = external dso_local global [500002 x i32], align 16
@ans = external dso_local global i32, align 4
@Q = external dso_local global %"class.std::set", align 8
@s = external dso_local global [500002 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %3 = alloca i32, align 4
  %4 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %5 = alloca i32, align 4
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull getelementptr inbounds (i8, ptr @s, i64 1))
  store i8 13, ptr @s, align 16, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !8
  %.not56 = icmp slt i32 %7, 1
  br i1 %.not56, label %.._crit_edge_crit_edge, label %.lr.ph60

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre88 = sext i32 %7 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.critedge, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre88, %.._crit_edge_crit_edge ], [ %.pre-phi92, %.critedge ]
  %8 = getelementptr inbounds i32, ptr @ord, i64 %.pre-phi
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  call void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @ord, i64 4), ptr noundef nonnull %9, ptr noundef nonnull @_Z3cmpRKiS0_)
  %10 = load i32, ptr @n, align 4, !tbaa !8
  %.not4668 = icmp slt i32 %10, 1
  br i1 %.not4668, label %._crit_edge71, label %.preheader

.lr.ph60:                                         ; preds = %0, %.critedge
  %11 = phi i32 [ %21, %.critedge ], [ %7, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ 1, %0 ]
  %.03758 = phi i32 [ %spec.select51, %.critedge ], [ 0, %0 ]
  %.04157 = phi i32 [ %spec.select, %.critedge ], [ undef, %0 ]
  %12 = zext nneg i32 %.03758 to i64
  %.not49 = icmp ugt i64 %indvars.iv, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  %.pre89 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %.not49, label %.lr.ph60._crit_edge, label %13

13:                                               ; preds = %.lr.ph60
  %14 = sub nsw i32 %.03758, %.pre89
  store i32 %14, ptr %1, align 4, !tbaa !8
  %15 = shl nsw i32 %.04157, 1
  %16 = sext i32 %15 to i64
  %17 = sub nsw i64 %16, %indvars.iv
  %18 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %17
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %18)
  %20 = load i32, ptr %19, align 4, !tbaa !8
  %.pre = load i32, ptr @n, align 4, !tbaa !8
  br label %.lr.ph60._crit_edge

.lr.ph60._crit_edge:                              ; preds = %.lr.ph60, %13
  %21 = phi i32 [ %.pre, %13 ], [ %11, %.lr.ph60 ]
  %22 = phi i32 [ %20, %13 ], [ 0, %.lr.ph60 ]
  %23 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  %24 = add nsw i32 %22, %.pre89
  %.not50.not53 = icmp slt i32 %24, %21
  br i1 %.not50.not53, label %.lr.ph.preheader, label %..critedge_crit_edge

..critedge_crit_edge:                             ; preds = %.lr.ph60._crit_edge
  %.pre91 = sext i32 %21 to i64
  br label %.critedge

.lr.ph.preheader:                                 ; preds = %.lr.ph60._crit_edge
  %25 = sext i32 %22 to i64
  %26 = add nsw i64 %indvars.iv, %25
  %27 = sext i32 %21 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %indvars.iv75 = phi i64 [ %25, %.lr.ph.preheader ], [ %indvars.iv.next76, %34 ]
  %indvars.iv73 = phi i64 [ %26, %.lr.ph.preheader ], [ %indvars.iv.next74, %34 ]
  %indvars.iv.next74 = add nsw i64 %indvars.iv73, 1
  %28 = getelementptr inbounds [500002 x i8], ptr @s, i64 0, i64 %indvars.iv.next74
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = sub nsw i64 %indvars.iv, %indvars.iv75
  %31 = getelementptr inbounds [500002 x i8], ptr @s, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = icmp eq i8 %29, %32
  br i1 %33, label %34, label %.critedge.loopexit.split.loop.exit93

34:                                               ; preds = %.lr.ph
  %indvars.iv.next76 = add nsw i64 %indvars.iv75, 1
  %35 = trunc nsw i64 %indvars.iv.next76 to i32
  store i32 %35, ptr %23, align 4, !tbaa !8
  %36 = add nsw i64 %indvars.iv.next76, %indvars.iv
  %.not50.not = icmp slt i64 %36, %27
  br i1 %.not50.not, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge.loopexit.split.loop.exit93:             ; preds = %.lr.ph
  %37 = trunc nsw i64 %indvars.iv73 to i32
  br label %.critedge

.critedge:                                        ; preds = %34, %.critedge.loopexit.split.loop.exit93, %..critedge_crit_edge
  %.pre-phi92 = phi i64 [ %.pre91, %..critedge_crit_edge ], [ %27, %.critedge.loopexit.split.loop.exit93 ], [ %27, %34 ]
  %.lcssa = phi i32 [ %24, %..critedge_crit_edge ], [ %37, %.critedge.loopexit.split.loop.exit93 ], [ %21, %34 ]
  %38 = icmp sgt i32 %.lcssa, %.03758
  %spec.select = select i1 %38, i32 %.pre89, i32 %.04157
  %spec.select51 = call i32 @llvm.smax.i32(i32 %.lcssa, i32 %.03758)
  %39 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %indvars.iv
  store i32 %.pre89, ptr %39, align 4, !tbaa !8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not.not = icmp slt i64 %indvars.iv, %.pre-phi92
  br i1 %.not.not, label %.lr.ph60, label %._crit_edge, !llvm.loop !12

.preheader:                                       ; preds = %._crit_edge, %71
  %40 = phi i32 [ %72, %71 ], [ %10, %._crit_edge ]
  %indvars.iv84 = phi i64 [ %indvars.iv.next85, %71 ], [ 1, %._crit_edge ]
  %.03870 = phi i32 [ %.139.lcssa, %71 ], [ 1, %._crit_edge ]
  %.not4762 = icmp sgt i32 %.03870, %40
  br i1 %.not4762, label %.critedge2, label %.lr.ph64.preheader

.lr.ph64.preheader:                               ; preds = %.preheader
  %41 = sext i32 %.03870 to i64
  br label %.lr.ph64

._crit_edge71:                                    ; preds = %71, %._crit_edge
  %42 = load i32, ptr @ans, align 4, !tbaa !8
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %42)
  ret i32 0

.lr.ph64:                                         ; preds = %.lr.ph64.preheader, %51
  %indvars.iv81 = phi i64 [ %41, %.lr.ph64.preheader ], [ %indvars.iv.next82, %51 ]
  %44 = getelementptr inbounds [500002 x i32], ptr @ord, i64 0, i64 %indvars.iv81
  %45 = load i32, ptr %44, align 4, !tbaa !8
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !8
  %49 = sub nsw i32 %45, %48
  %50 = sext i32 %49 to i64
  %.not48 = icmp slt i64 %indvars.iv84, %50
  br i1 %.not48, label %.critedge2.loopexit, label %51

51:                                               ; preds = %.lr.ph64
  %52 = call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48) @Q, ptr noundef nonnull align 4 dereferenceable(4) %44)
  %indvars.iv.next82 = add nsw i64 %indvars.iv81, 1
  %53 = load i32, ptr @n, align 4, !tbaa !8
  %54 = sext i32 %53 to i64
  %.not47.not = icmp slt i64 %indvars.iv81, %54
  br i1 %.not47.not, label %.lr.ph64, label %.critedge2.loopexit, !llvm.loop !13

.critedge2.loopexit:                              ; preds = %51, %.lr.ph64
  %.139.lcssa.ph.in = phi i64 [ %indvars.iv81, %.lr.ph64 ], [ %indvars.iv.next82, %51 ]
  %.139.lcssa.ph = trunc i64 %.139.lcssa.ph.in to i32
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.preheader
  %.139.lcssa = phi i32 [ %.03870, %.preheader ], [ %.139.lcssa.ph, %.critedge2.loopexit ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  %55 = getelementptr inbounds [500002 x i32], ptr @f, i64 0, i64 %indvars.iv84
  %56 = load i32, ptr %55, align 4, !tbaa !8
  %57 = sdiv i32 %56, 2
  %58 = trunc nuw nsw i64 %indvars.iv84 to i32
  %59 = add nsw i32 %57, %58
  store i32 %59, ptr %3, align 4, !tbaa !8
  %60 = call ptr @_ZNSt3setIiSt4lessIiESaIiEE11upper_boundERKi(ptr noundef nonnull align 8 dereferenceable(48) @Q, ptr noundef nonnull align 4 dereferenceable(4) %3)
  store ptr %60, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  %61 = call ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @Q) #8
  store ptr %61, ptr %4, align 8
  %62 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  br i1 %62, label %63, label %71

63:                                               ; preds = %.critedge2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  %64 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt23_Rb_tree_const_iteratorIiEmmEv(ptr noundef nonnull align 8 dereferenceable(8) %2) #8
  %65 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %64) #8
  %66 = load i32, ptr %65, align 4, !tbaa !8
  %67 = sub nsw i32 %66, %58
  %68 = shl nsw i32 %67, 2
  store i32 %68, ptr %5, align 4, !tbaa !8
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %70 = load i32, ptr %69, align 4, !tbaa !8
  store i32 %70, ptr @ans, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  br label %71

71:                                               ; preds = %63, %.critedge2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #8
  %indvars.iv.next85 = add nuw nsw i64 %indvars.iv84, 1
  %72 = load i32, ptr @n, align 4, !tbaa !8
  %73 = sext i32 %72 to i64
  %.not46.not = icmp slt i64 %indvars.iv84, %73
  br i1 %.not46.not, label %.preheader, label %._crit_edge71, !llvm.loop !14
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbRKiS2_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNSt3setIiSt4lessIiESaIiEE11upper_boundERKi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt23_Rb_tree_const_iteratorIiEmmEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #6 = { 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 #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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