; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-23 (A)

; 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::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@qsize = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@seq = external dso_local global [40001 x i32], align 16
@str = external dso_local global [40001 x [4 x i8]], align 16
@Q = external dso_local global %"class.std::deque", align 8
@flag = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [7 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 [10 x i8], align 1
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 10, ptr %2) #6
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @k)
  br label %9

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

13:                                               ; preds = %9
  %14 = load i32, ptr @tot, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @tot, align 4, !tbaa !5
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %16
  %18 = getelementptr inbounds [4 x i8], ptr %17, i64 0, i64 0
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  %22 = load i32, ptr @qsize, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @qsize, align 4, !tbaa !5
  br label %9, !llvm.loop !9

24:                                               ; preds = %9
  br label %25

25:                                               ; preds = %29, %24
  %26 = load i32, ptr @qsize, align 4, !tbaa !5
  %27 = load i32, ptr @k, align 4, !tbaa !5
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr @cnt, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @cnt, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %34
  store i32 %31, ptr %35, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %36 = load i32, ptr @qsize, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @qsize, align 4, !tbaa !5
  br label %25, !llvm.loop !11

38:                                               ; preds = %25
  br label %39

39:                                               ; preds = %128, %38
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @m, align 4, !tbaa !5
  %42 = icmp ne i32 %40, 0
  br i1 %42, label %43, label %129

43:                                               ; preds = %39
  %44 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 0
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %44)
  %46 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 0
  %47 = load i8, ptr %46, align 1, !tbaa !12
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 82
  br i1 %49, label %50, label %57

50:                                               ; preds = %43
  %51 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %52 = trunc i8 %51 to i1
  %53 = zext i1 %52 to i32
  %54 = xor i32 %53, 1
  %55 = icmp ne i32 %54, 0
  %56 = zext i1 %55 to i8
  store i8 %56, ptr @flag, align 1, !tbaa !13
  br label %128

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

58:                                               ; preds = %77, %57
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !12
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %65, label %64

64:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %80

65:                                               ; preds = %58
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !12
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 41
  br i1 %71, label %72, label %76

72:                                               ; preds = %65
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 %74
  store i8 0, ptr %75, align 1, !tbaa !12
  br label %76

76:                                               ; preds = %72, %65
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %58, !llvm.loop !17

80:                                               ; preds = %64
  %81 = load i32, ptr @tot, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr @tot, align 4, !tbaa !5
  %83 = sext i32 %81 to i64
  %84 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %83
  %85 = getelementptr inbounds [4 x i8], ptr %84, i64 0, i64 0
  %86 = getelementptr inbounds [10 x i8], ptr %2, i64 0, i64 0
  %87 = getelementptr inbounds i8, ptr %86, i64 4
  %88 = call ptr @strcpy(ptr noundef %85, ptr noundef %87) #6
  %89 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %90 = trunc i8 %89 to i1
  br i1 %90, label %91, label %109

91:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %92 = load i32, ptr @tot, align 4, !tbaa !5
  %93 = sub nsw i32 %92, 1
  store i32 %93, ptr %5, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %94 = load i32, ptr @qsize, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr @qsize, align 4, !tbaa !5
  %96 = load i32, ptr @qsize, align 4, !tbaa !5
  %97 = load i32, ptr @k, align 4, !tbaa !5
  %98 = icmp sgt i32 %96, %97
  br i1 %98, label %99, label %108

99:                                               ; preds = %91
  %100 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE4backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = load i32, ptr @cnt, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr @cnt, align 4, !tbaa !5
  %104 = sext i32 %102 to i64
  %105 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %104
  store i32 %101, ptr %105, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %106 = load i32, ptr @qsize, align 4, !tbaa !5
  %107 = add nsw i32 %106, -1
  store i32 %107, ptr @qsize, align 4, !tbaa !5
  br label %108

108:                                              ; preds = %99, %91
  br label %127

109:                                              ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %110 = load i32, ptr @tot, align 4, !tbaa !5
  %111 = sub nsw i32 %110, 1
  store i32 %111, ptr %6, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %112 = load i32, ptr @qsize, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr @qsize, align 4, !tbaa !5
  %114 = load i32, ptr @qsize, align 4, !tbaa !5
  %115 = load i32, ptr @k, align 4, !tbaa !5
  %116 = icmp sgt i32 %114, %115
  br i1 %116, label %117, label %126

117:                                              ; preds = %109
  %118 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = load i32, ptr @cnt, align 4, !tbaa !5
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr @cnt, align 4, !tbaa !5
  %122 = sext i32 %120 to i64
  %123 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %122
  store i32 %119, ptr %123, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %124 = load i32, ptr @qsize, align 4, !tbaa !5
  %125 = add nsw i32 %124, -1
  store i32 %125, ptr @qsize, align 4, !tbaa !5
  br label %126

126:                                              ; preds = %117, %109
  br label %127

127:                                              ; preds = %126, %108
  br label %128

128:                                              ; preds = %127, %50
  br label %39, !llvm.loop !18

129:                                              ; preds = %39
  %130 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %131 = trunc i8 %130 to i1
  br i1 %131, label %132, label %146

132:                                              ; preds = %129
  br label %133

133:                                              ; preds = %136, %132
  %134 = load i32, ptr @qsize, align 4, !tbaa !5
  %135 = icmp ne i32 %134, 0
  br i1 %135, label %136, label %145

136:                                              ; preds = %133
  %137 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE4backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %138 = load i32, ptr %137, align 4, !tbaa !5
  %139 = load i32, ptr @cnt, align 4, !tbaa !5
  %140 = add nsw i32 %139, 1
  store i32 %140, ptr @cnt, align 4, !tbaa !5
  %141 = sext i32 %139 to i64
  %142 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %141
  store i32 %138, ptr %142, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %143 = load i32, ptr @qsize, align 4, !tbaa !5
  %144 = add nsw i32 %143, -1
  store i32 %144, ptr @qsize, align 4, !tbaa !5
  br label %133, !llvm.loop !19

145:                                              ; preds = %133
  br label %160

146:                                              ; preds = %129
  br label %147

147:                                              ; preds = %150, %146
  %148 = load i32, ptr @qsize, align 4, !tbaa !5
  %149 = icmp ne i32 %148, 0
  br i1 %149, label %150, label %159

150:                                              ; preds = %147
  %151 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %152 = load i32, ptr %151, align 4, !tbaa !5
  %153 = load i32, ptr @cnt, align 4, !tbaa !5
  %154 = add nsw i32 %153, 1
  store i32 %154, ptr @cnt, align 4, !tbaa !5
  %155 = sext i32 %153 to i64
  %156 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %155
  store i32 %152, ptr %156, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %157 = load i32, ptr @qsize, align 4, !tbaa !5
  %158 = add nsw i32 %157, -1
  store i32 %158, ptr @qsize, align 4, !tbaa !5
  br label %147, !llvm.loop !20

159:                                              ; preds = %147
  br label %160

160:                                              ; preds = %159, %145
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %161 = load i32, ptr @cnt, align 4, !tbaa !5
  %162 = sub nsw i32 %161, 1
  store i32 %162, ptr %7, align 4, !tbaa !5
  br label %163

163:                                              ; preds = %176, %160
  %164 = load i32, ptr %7, align 4, !tbaa !5
  %165 = icmp sge i32 %164, 0
  br i1 %165, label %167, label %166

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

167:                                              ; preds = %163
  %168 = load i32, ptr %7, align 4, !tbaa !5
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %169
  %171 = load i32, ptr %170, align 4, !tbaa !5
  %172 = sext i32 %171 to i64
  %173 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %172
  %174 = getelementptr inbounds [4 x i8], ptr %173, i64 0, i64 0
  %175 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %174)
  br label %176

176:                                              ; preds = %167
  %177 = load i32, ptr %7, align 4, !tbaa !5
  %178 = add nsw i32 %177, -1
  store i32 %178, ptr %7, align 4, !tbaa !5
  br label %163, !llvm.loop !21

179:                                              ; preds = %166
  call void @llvm.lifetime.end.p0(i64 10, ptr %2) #6
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) #3 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) #4 align 2

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #5

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = { 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 = { 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 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !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::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@qsize = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local local_unnamed_addr global [40001 x i32], align 16
@str = external dso_local global [40001 x [4 x i8]], align 16
@Q = external dso_local global %"class.std::deque", align 8
@flag = external dso_local local_unnamed_addr global i8, align 1
@.str = external hidden unnamed_addr constant [7 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 = alloca [10 x i8], align 1
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %1) #6
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @k)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @n, align 4, !tbaa !5
  %.not20 = icmp eq i32 %6, 0
  br i1 %.not20, label %..preheader19_crit_edge, label %.lr.ph

..preheader19_crit_edge:                          ; preds = %0
  %.pre = load i32, ptr @qsize, align 4, !tbaa !5
  br label %.preheader19

.preheader19:                                     ; preds = %.lr.ph, %..preheader19_crit_edge
  %8 = phi i32 [ %.pre, %..preheader19_crit_edge ], [ %19, %.lr.ph ]
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %10 = icmp sgt i32 %8, %9
  br i1 %10, label %.lr.ph21, label %.preheader18

.lr.ph:                                           ; preds = %0, %.lr.ph
  %11 = load i32, ptr @tot, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @tot, align 4, !tbaa !5
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %14)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %16 = load i32, ptr @tot, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %2, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  %18 = load i32, ptr @qsize, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @qsize, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %.preheader19, label %.lr.ph, !llvm.loop !9

.preheader18:                                     ; preds = %.lr.ph21, %.preheader19
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @m, align 4, !tbaa !5
  %.not922 = icmp eq i32 %22, 0
  br i1 %.not922, label %._crit_edge, label %.lr.ph23

.lr.ph23:                                         ; preds = %.preheader18
  %24 = getelementptr inbounds i8, ptr %1, i64 4
  br label %35

.lr.ph21:                                         ; preds = %.preheader19, %.lr.ph21
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr @cnt, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @cnt, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %29
  store i32 %26, ptr %30, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %31 = load i32, ptr @qsize, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr @qsize, align 4, !tbaa !5
  %33 = load i32, ptr @k, align 4, !tbaa !5
  %34 = icmp sgt i32 %32, %33
  br i1 %34, label %.lr.ph21, label %.preheader18, !llvm.loop !11

35:                                               ; preds = %.lr.ph23, %80
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %37 = load i8, ptr %1, align 1, !tbaa !12
  %38 = icmp eq i8 %37, 82
  br i1 %38, label %39, label %.preheader

39:                                               ; preds = %35
  %40 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %41 = xor i8 %40, 1
  store i8 %41, ptr @flag, align 1, !tbaa !13
  br label %80

.preheader:                                       ; preds = %35, %53
  %indvars.iv = phi i64 [ %indvars.iv.next, %53 ], [ 5, %35 ]
  %42 = getelementptr inbounds [10 x i8], ptr %1, i64 0, i64 %indvars.iv
  %43 = load i8, ptr %42, align 1, !tbaa !12
  switch i8 %43, label %53 [
    i8 0, label %44
    i8 41, label %52
  ]

44:                                               ; preds = %.preheader
  %45 = load i32, ptr @tot, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @tot, align 4, !tbaa !5
  %47 = sext i32 %45 to i64
  %48 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %47
  %49 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %48, ptr noundef nonnull dereferenceable(1) %24) #6
  %50 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %51 = trunc nuw i8 %50 to i1
  br i1 %51, label %54, label %67

52:                                               ; preds = %.preheader
  store i8 0, ptr %42, align 1, !tbaa !12
  br label %53

53:                                               ; preds = %.preheader, %52
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %.preheader, !llvm.loop !17

54:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  store i32 %45, ptr %3, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  %55 = load i32, ptr @qsize, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @qsize, align 4, !tbaa !5
  %57 = load i32, ptr @k, align 4, !tbaa !5
  %.not14 = icmp slt i32 %55, %57
  br i1 %.not14, label %80, label %58

58:                                               ; preds = %54
  %59 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE4backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr @cnt, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr @cnt, align 4, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %65 = load i32, ptr @qsize, align 4, !tbaa !5
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr @qsize, align 4, !tbaa !5
  br label %80

67:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  store i32 %45, ptr %4, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(80) @Q, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  %68 = load i32, ptr @qsize, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @qsize, align 4, !tbaa !5
  %70 = load i32, ptr @k, align 4, !tbaa !5
  %.not13 = icmp slt i32 %68, %70
  br i1 %.not13, label %80, label %71

71:                                               ; preds = %67
  %72 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr @cnt, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr @cnt, align 4, !tbaa !5
  %76 = sext i32 %74 to i64
  %77 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %76
  store i32 %73, ptr %77, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %78 = load i32, ptr @qsize, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr @qsize, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %58, %54, %71, %67, %39
  %81 = load i32, ptr @m, align 4, !tbaa !5
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr @m, align 4, !tbaa !5
  %.not9 = icmp eq i32 %81, 0
  br i1 %.not9, label %._crit_edge, label %35, !llvm.loop !18

._crit_edge:                                      ; preds = %80, %.preheader18
  %83 = load i8, ptr @flag, align 1, !tbaa !13, !range !15, !noundef !16
  %84 = trunc nuw i8 %83 to i1
  %.pr = load i32, ptr @qsize, align 4, !tbaa !5
  %.not1126 = icmp eq i32 %.pr, 0
  br i1 %84, label %thread-pre-split, label %thread-pre-split15

thread-pre-split:                                 ; preds = %._crit_edge
  br i1 %.not1126, label %.loopexit, label %.lr.ph27

.lr.ph27:                                         ; preds = %thread-pre-split, %.lr.ph27
  %85 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE4backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load i32, ptr @cnt, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr @cnt, align 4, !tbaa !5
  %89 = sext i32 %87 to i64
  %90 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %89
  store i32 %86, ptr %90, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %91 = load i32, ptr @qsize, align 4, !tbaa !5
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr @qsize, align 4, !tbaa !5
  %.not11 = icmp eq i32 %92, 0
  br i1 %.not11, label %.loopexit, label %.lr.ph27, !llvm.loop !19

thread-pre-split15:                               ; preds = %._crit_edge
  br i1 %.not1126, label %.loopexit, label %.lr.ph25

.lr.ph25:                                         ; preds = %thread-pre-split15, %.lr.ph25
  %93 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = load i32, ptr @cnt, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr @cnt, align 4, !tbaa !5
  %97 = sext i32 %95 to i64
  %98 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %97
  store i32 %94, ptr %98, align 4, !tbaa !5
  call void @_ZNSt5dequeIiSaIiEE9pop_frontEv(ptr noundef nonnull align 8 dereferenceable(80) @Q) #6
  %99 = load i32, ptr @qsize, align 4, !tbaa !5
  %100 = add nsw i32 %99, -1
  store i32 %100, ptr @qsize, align 4, !tbaa !5
  %.not10 = icmp eq i32 %100, 0
  br i1 %.not10, label %.loopexit, label %.lr.ph25, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph25, %.lr.ph27, %thread-pre-split15, %thread-pre-split
  %101 = load i32, ptr @cnt, align 4, !tbaa !5
  %102 = icmp sgt i32 %101, 0
  br i1 %102, label %.lr.ph30.preheader, label %._crit_edge31

.lr.ph30.preheader:                               ; preds = %.loopexit
  %103 = zext nneg i32 %101 to i64
  br label %.lr.ph30

._crit_edge31:                                    ; preds = %.lr.ph30, %.loopexit
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %1) #6
  ret i32 0

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %.lr.ph30
  %indvars.iv34 = phi i64 [ %103, %.lr.ph30.preheader ], [ %indvars.iv.next35, %.lr.ph30 ]
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %104 = getelementptr inbounds [40001 x i32], ptr @seq, i64 0, i64 %indvars.iv.next35
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [40001 x [4 x i8]], ptr @str, i64 0, i64 %106
  %108 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %107)
  %109 = icmp ugt i64 %indvars.iv34, 1
  br i1 %109, label %.lr.ph30, label %._crit_edge31, !llvm.loop !21
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIiSaIiEE10push_frontEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5dequeIiSaIiEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #4 align 2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3 align 2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !10}


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