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

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.__gnu_cxx::__normal_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@fa = external dso_local global [4001 x i32], align 16
@c = external dso_local global [4001 x i32], align 16
@st = external dso_local global i32, align 4
@pos = external dso_local global [2 x [4001 x i32]], align 16
@P = external dso_local global ptr, align 8
@ord = external dso_local global [4001 x i32], align 16
@f = external dso_local global [2004501 x i32], align 16
@g = external dso_local global [2004501 x i32], align 16
@s = external dso_local global [4001 x i32], align 16
@F = external dso_local global ptr, align 8
@ans = external dso_local global i32, align 4
@e = external dso_local global [4001 x %"class.std::vector"], 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 uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %5 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %45, %0
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr @fa, i64 %25
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr @c, i64 %28
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %26, ptr noundef %29)
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = icmp sge i32 %35, 0
  br i1 %36, label %37, label %44

37:                                               ; preds = %23
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %42
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %43, ptr noundef nonnull align 4 dereferenceable(4) %2)
  br label %44

44:                                               ; preds = %37, %23
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !9

48:                                               ; preds = %22
  store i32 0, ptr @st, align 4, !tbaa !5
  store ptr @pos, ptr @P, align 8, !tbaa !11
  store ptr @f, ptr @F, align 8, !tbaa !11
  call void @_Z3dfsi(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %69, %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %72

54:                                               ; preds = %49
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %56
  %58 = call ptr @_ZNSt6vectorIiSaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %57) #7
  %59 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %4, i32 0, i32 0
  store ptr %58, ptr %59, align 8
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %61
  %63 = call ptr @_ZNSt6vectorIiSaIiEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %62) #7
  %64 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %5, i32 0, i32 0
  store ptr %63, ptr %64, align 8
  %65 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %4, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8
  %67 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %5, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8
  call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_(ptr %66, ptr %68)
  br label %69

69:                                               ; preds = %54
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %3, align 4, !tbaa !5
  br label %49, !llvm.loop !13

72:                                               ; preds = %53
  store i32 0, ptr @st, align 4, !tbaa !5
  store ptr getelementptr inbounds ([2 x [4001 x i32]], ptr @pos, i64 0, i64 1), ptr @P, align 8, !tbaa !11
  store ptr @g, ptr @F, align 8, !tbaa !11
  call void @_Z3dfsi(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %89, %72
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

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

78:                                               ; preds = %73
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = load ptr, ptr @P, align 8, !tbaa !11
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr %80, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = load i32, ptr @m, align 4, !tbaa !5
  %86 = sdiv i32 %84, %85
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %87
  store i32 %79, ptr %88, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %78
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %6, align 4, !tbaa !5
  br label %73, !llvm.loop !14

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

93:                                               ; preds = %174, %92
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = load i32, ptr @n, align 4, !tbaa !5
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %98, label %97

97:                                               ; preds = %93
  store i32 11, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %180

98:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  store i32 %102, ptr %10, align 4, !tbaa !5
  %103 = load i32, ptr %10, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = icmp sge i32 %106, 0
  br i1 %107, label %108, label %116

108:                                              ; preds = %98
  %109 = load i32, ptr %10, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [4001 x i32], ptr @s, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  br label %117

116:                                              ; preds = %98
  br label %117

117:                                              ; preds = %116, %108
  %118 = phi i32 [ %115, %108 ], [ 0, %116 ]
  %119 = load i32, ptr %10, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [4001 x i32], ptr @c, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = add nsw i32 %118, %122
  %124 = load i32, ptr %10, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [4001 x i32], ptr @s, i64 0, i64 %125
  store i32 %123, ptr %126, align 4, !tbaa !5
  %127 = load i32, ptr %10, align 4, !tbaa !5
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %128
  %130 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %129) #7
  %131 = icmp ugt i64 %130, 0
  br i1 %131, label %132, label %133

132:                                              ; preds = %117
  store i32 13, ptr %9, align 4
  br label %171

133:                                              ; preds = %117
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 0, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  %134 = load i32, ptr %10, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [4001 x i32], ptr @pos, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  %138 = load i32, ptr @m, align 4, !tbaa !5
  %139 = add nsw i32 %137, %138
  %140 = sub nsw i32 %139, 1
  store i32 %140, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %141 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %141, ptr %14, align 4, !tbaa !5
  br label %142

142:                                              ; preds = %157, %133
  %143 = load i32, ptr %12, align 4, !tbaa !5
  %144 = load i32, ptr @m, align 4, !tbaa !5
  %145 = icmp slt i32 %143, %144
  br i1 %145, label %147, label %146

146:                                              ; preds = %142
  store i32 14, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %164

147:                                              ; preds = %142
  %148 = load i32, ptr %13, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [2004501 x i32], ptr @f, i64 0, i64 %149
  %151 = load i32, ptr %150, align 4, !tbaa !5
  %152 = load i32, ptr %14, align 4, !tbaa !5
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [2004501 x i32], ptr @g, i64 0, i64 %153
  %155 = load i32, ptr %154, align 4, !tbaa !5
  %156 = add nsw i32 %151, %155
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %11, i32 noundef %156)
  br label %157

157:                                              ; preds = %147
  %158 = load i32, ptr %12, align 4, !tbaa !5
  %159 = add nsw i32 %158, 1
  store i32 %159, ptr %12, align 4, !tbaa !5
  %160 = load i32, ptr %13, align 4, !tbaa !5
  %161 = add nsw i32 %160, -1
  store i32 %161, ptr %13, align 4, !tbaa !5
  %162 = load i32, ptr %14, align 4, !tbaa !5
  %163 = add nsw i32 %162, 1
  store i32 %163, ptr %14, align 4, !tbaa !5
  br label %142, !llvm.loop !15

164:                                              ; preds = %146
  %165 = load i32, ptr %11, align 4, !tbaa !5
  %166 = load i32, ptr %10, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [4001 x i32], ptr @s, i64 0, i64 %167
  %169 = load i32, ptr %168, align 4, !tbaa !5
  %170 = add nsw i32 %165, %169
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %170)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  store i32 0, ptr %9, align 4
  br label %171

171:                                              ; preds = %164, %132
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  %172 = load i32, ptr %9, align 4
  switch i32 %172, label %183 [
    i32 0, label %173
    i32 13, label %174
  ]

173:                                              ; preds = %171
  br label %174

174:                                              ; preds = %173, %171
  %175 = load i32, ptr %7, align 4, !tbaa !5
  %176 = add nsw i32 %175, 1
  store i32 %176, ptr %7, align 4, !tbaa !5
  %177 = load i32, ptr @m, align 4, !tbaa !5
  %178 = load i32, ptr %8, align 4, !tbaa !5
  %179 = add nsw i32 %178, %177
  store i32 %179, ptr %8, align 4, !tbaa !5
  br label %93, !llvm.loop !16

180:                                              ; preds = %97
  %181 = load i32, ptr @ans, align 4, !tbaa !5
  %182 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %181)
  ret i32 0

183:                                              ; preds = %171
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_(ptr, ptr) #6

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { 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 #5 = { "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 = { 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 #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 = !{!"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 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@fa = external dso_local global [4001 x i32], align 16
@c = external dso_local global [4001 x i32], align 16
@st = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local global [2 x [4001 x i32]], align 16
@P = external dso_local local_unnamed_addr global ptr, align 8
@ord = external dso_local local_unnamed_addr global [4001 x i32], align 16
@f = external dso_local global [2004501 x i32], align 16
@g = external dso_local global [2004501 x i32], align 16
@s = external dso_local local_unnamed_addr global [4001 x i32], align 16
@F = external dso_local local_unnamed_addr global ptr, align 8
@ans = external dso_local global i32, align 4
@e = external dso_local global [4001 x %"class.std::vector"], 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 uwtable
declare dso_local void @_Z3dfsi(i32 noundef) local_unnamed_addr #0

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

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  store i32 0, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %23, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  store i32 0, ptr @st, align 4, !tbaa !5
  store ptr @pos, ptr @P, align 8, !tbaa !9
  store ptr @f, ptr @F, align 8, !tbaa !9
  call void @_Z3dfsi(i32 noundef 0)
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph38, label %._crit_edge39

.lr.ph:                                           ; preds = %0, %23
  %storemerge35 = phi i32 [ %25, %23 ], [ 0, %0 ]
  %10 = sext i32 %storemerge35 to i64
  %11 = getelementptr inbounds i32, ptr @fa, i64 %10
  %12 = getelementptr inbounds i32, ptr @c, i64 %10
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11, ptr noundef nonnull %12)
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = icmp sgt i32 %17, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %.lr.ph
  %21 = zext nneg i32 %18 to i64
  %22 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %21
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %22, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph, %20
  %24 = phi i32 [ %14, %.lr.ph ], [ %.pre, %20 ]
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %1, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge39:                                    ; preds = %.lr.ph38, %._crit_edge
  store i32 0, ptr @st, align 4, !tbaa !5
  store ptr getelementptr inbounds (i8, ptr @pos, i64 16004), ptr @P, align 8, !tbaa !9
  store ptr @g, ptr @F, align 8, !tbaa !9
  call void @_Z3dfsi(i32 noundef 0)
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph42, label %._crit_edge53

.lr.ph42:                                         ; preds = %._crit_edge39
  %30 = load ptr, ptr @P, align 8, !tbaa !9
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %28 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %32 = icmp eq i32 %28, 1
  br i1 %32, label %.preheader.unr-lcssa, label %.lr.ph42.new

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

.lr.ph38:                                         ; preds = %._crit_edge, %.lr.ph38
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph38 ], [ 0, %._crit_edge ]
  %33 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %indvars.iv
  %34 = call ptr @_ZNSt6vectorIiSaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %33) #7
  %35 = call ptr @_ZNSt6vectorIiSaIiEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %33) #7
  call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_(ptr %34, ptr %35)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next, %37
  br i1 %38, label %.lr.ph38, label %._crit_edge39, !llvm.loop !13

.preheader.unr-lcssa:                             ; preds = %45, %.lr.ph42
  %indvars.iv55.unr = phi i64 [ 0, %.lr.ph42 ], [ %indvars.iv.next56.1, %45 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.epilog-lcssa

.preheader.epilog-lcssa:                          ; preds = %.preheader.unr-lcssa
  %39 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv55.unr
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sdiv i32 %40, %31
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %42
  %44 = trunc nuw nsw i64 %indvars.iv55.unr to i32
  store i32 %44, ptr %43, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.unr-lcssa, %.preheader.epilog-lcssa
  br i1 %29, label %.lr.ph52, label %._crit_edge53

45:                                               ; preds = %45, %.lr.ph42.new
  %indvars.iv55 = phi i64 [ 0, %.lr.ph42.new ], [ %indvars.iv.next56.1, %45 ]
  %niter = phi i64 [ 0, %.lr.ph42.new ], [ %niter.next.1, %45 ]
  %46 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv55
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sdiv i32 %47, %31
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %49
  %51 = trunc nuw nsw i64 %indvars.iv55 to i32
  store i32 %51, ptr %50, align 4, !tbaa !5
  %indvars.iv.next56 = or disjoint i64 %indvars.iv55, 1
  %52 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv.next56
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sdiv i32 %53, %31
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %55
  %57 = trunc nuw nsw i64 %indvars.iv.next56 to i32
  store i32 %57, ptr %56, align 4, !tbaa !5
  %indvars.iv.next56.1 = add nuw nsw i64 %indvars.iv55, 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 %.preheader.unr-lcssa, label %45, !llvm.loop !14

._crit_edge53:                                    ; preds = %97, %._crit_edge39, %.preheader
  %58 = load i32, ptr @ans, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %58)
  ret i32 0

.lr.ph52:                                         ; preds = %.preheader, %97
  %indvars.iv65 = phi i64 [ %indvars.iv.next66, %97 ], [ 0, %.preheader ]
  %.03050 = phi i32 [ %99, %97 ], [ 0, %.preheader ]
  %60 = getelementptr inbounds [4001 x i32], ptr @ord, i64 0, i64 %indvars.iv65
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [4001 x i32], ptr @fa, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = icmp sgt i32 %64, -1
  br i1 %65, label %66, label %70

66:                                               ; preds = %.lr.ph52
  %67 = zext nneg i32 %64 to i64
  %68 = getelementptr inbounds [4001 x i32], ptr @s, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %.lr.ph52, %66
  %71 = phi i32 [ %69, %66 ], [ 0, %.lr.ph52 ]
  %72 = getelementptr inbounds [4001 x i32], ptr @c, i64 0, i64 %62
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, %71
  %75 = getelementptr inbounds [4001 x i32], ptr @s, i64 0, i64 %62
  store i32 %74, ptr %75, align 4, !tbaa !5
  %76 = getelementptr inbounds [4001 x %"class.std::vector"], ptr @e, i64 0, i64 %62
  %77 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %76) #7
  %.not = icmp eq i64 %77, 0
  br i1 %.not, label %78, label %97

78:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  %79 = load i32, ptr @m, align 4, !tbaa !5
  %80 = icmp sgt i32 %79, 0
  br i1 %80, label %.lr.ph47.preheader, label %._crit_edge48

.lr.ph47.preheader:                               ; preds = %78
  %81 = getelementptr inbounds [4001 x i32], ptr @pos, i64 0, i64 %62
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = add i32 %79, %82
  %84 = sext i32 %.03050 to i64
  %85 = sext i32 %83 to i64
  br label %.lr.ph47

._crit_edge48.loopexit:                           ; preds = %.lr.ph47
  %.pre68 = load i32, ptr %2, align 4, !tbaa !5
  br label %._crit_edge48

._crit_edge48:                                    ; preds = %._crit_edge48.loopexit, %78
  %86 = phi i32 [ %.pre68, %._crit_edge48.loopexit ], [ 0, %78 ]
  %87 = load i32, ptr %75, align 4, !tbaa !5
  %88 = add nsw i32 %87, %86
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %88)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  br label %97

.lr.ph47:                                         ; preds = %.lr.ph47.preheader, %.lr.ph47
  %indvars.iv60 = phi i64 [ %85, %.lr.ph47.preheader ], [ %indvars.iv.next61, %.lr.ph47 ]
  %indvars.iv58 = phi i64 [ %84, %.lr.ph47.preheader ], [ %indvars.iv.next59, %.lr.ph47 ]
  %.02843 = phi i32 [ 0, %.lr.ph47.preheader ], [ %94, %.lr.ph47 ]
  %indvars.iv.next61 = add nsw i64 %indvars.iv60, -1
  %89 = getelementptr inbounds [2004501 x i32], ptr @f, i64 0, i64 %indvars.iv.next61
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = getelementptr inbounds [2004501 x i32], ptr @g, i64 0, i64 %indvars.iv58
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = add nsw i32 %92, %90
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %93)
  %94 = add nuw nsw i32 %.02843, 1
  %indvars.iv.next59 = add nsw i64 %indvars.iv58, 1
  %95 = load i32, ptr @m, align 4, !tbaa !5
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %.lr.ph47, label %._crit_edge48.loopexit, !llvm.loop !15

97:                                               ; preds = %70, %._crit_edge48
  %indvars.iv.next66 = add nuw nsw i64 %indvars.iv65, 1
  %98 = load i32, ptr @m, align 4, !tbaa !5
  %99 = add nsw i32 %98, %.03050
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = icmp slt i64 %indvars.iv.next66, %101
  br i1 %102, label %.lr.ph52, label %._crit_edge53, !llvm.loop !16
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_(ptr, ptr) local_unnamed_addr #6

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

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

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


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