; LLVM IR from Aryansh-S/USACO :: USACO/2017/January/Gold (bphoto)

; 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.__gnu_pbds::tree" = type { %"class.__gnu_pbds::basic_branch" }
%"class.__gnu_pbds::basic_branch" = type { %"class.__gnu_pbds::detail::rb_tree_set" }
%"class.__gnu_pbds::detail::rb_tree_set" = type { %"class.__gnu_pbds::detail::bin_search_tree_set" }
%"class.__gnu_pbds::detail::bin_search_tree_set" = type { %"class.__gnu_pbds::tree_order_statistics_node_update", [8 x i8], ptr, i64 }
%"class.__gnu_pbds::tree_order_statistics_node_update" = type { %"struct.__gnu_pbds::detail::branch_policy" }
%"struct.__gnu_pbds::detail::branch_policy" = type { ptr }
%struct.BIT = type { [200006 x i32] }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"struct.std::pair" = type <{ %"class.__gnu_pbds::detail::bin_search_tree_const_it_", i8, [7 x i8] }>
%"class.__gnu_pbds::detail::bin_search_tree_const_it_" = type { ptr }

@n = external dso_local global i32, align 4
@h = external dso_local global [200005 x i32], align 16
@ls = external dso_local global [200005 x i32], align 16
@rs = external dso_local global [200005 x i32], align 16
@ans = external dso_local global i32, align 4
@cc = external dso_local global %"class.__gnu_pbds::tree", align 8
@L = external dso_local global %struct.BIT, align 4
@R = external dso_local global %struct.BIT, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::pair", align 8
  %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
  %8 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.3)
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %0
  %11 = load ptr, ptr @stdin, align 8, !tbaa !5
  %12 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.3, ptr noundef %11)
  %13 = load ptr, ptr @stdout, align 8, !tbaa !5
  %14 = call ptr @freopen(ptr noundef @.str.4, ptr noundef @.str.5, ptr noundef %13)
  br label %15

15:                                               ; preds = %10, %0
  %16 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %17 = getelementptr i8, ptr %16, i64 -24
  %18 = load i64, ptr %17, align 8
  %19 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %18
  %20 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %19, ptr noundef null)
  %21 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  call void @_Z2reIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4) @n)
  %22 = load i32, ptr @n, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @h, i64 %23
  call void @_Z2inIPiEvT_S1_(ptr noundef @h, ptr noundef %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %39, %15
  %26 = load i32, ptr %2, align 4, !tbaa !11
  %27 = load i32, ptr @n, align 4, !tbaa !11
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %25
  %31 = load i32, ptr %2, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %32
  %34 = call { ptr, i8 } @_ZN10__gnu_pbds6detail11rb_tree_setIiNS_9null_typeESt4lessIiENS0_11tree_traitsIiS2_S4_NS_33tree_order_statistics_node_updateENS_11rb_tree_tagESaIcEEES8_E6insertERKi(ptr noundef nonnull align 8 dereferenceable(32) @cc, ptr noundef nonnull align 4 dereferenceable(4) %33)
  %35 = getelementptr inbounds { ptr, i8 }, ptr %3, i32 0, i32 0
  %36 = extractvalue { ptr, i8 } %34, 0
  store ptr %36, ptr %35, align 8
  %37 = getelementptr inbounds { ptr, i8 }, ptr %3, i32 0, i32 1
  %38 = extractvalue { ptr, i8 } %34, 1
  store i8 %38, ptr %37, align 8
  br label %39

39:                                               ; preds = %30
  %40 = load i32, ptr %2, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !11
  br label %25, !llvm.loop !13

42:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %57, %42
  %44 = load i32, ptr %4, align 4, !tbaa !11
  %45 = load i32, ptr @n, align 4, !tbaa !11
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %60

48:                                               ; preds = %43
  %49 = load i32, ptr %4, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %50
  %52 = call noundef i64 @_ZNK10__gnu_pbds33tree_order_statistics_node_updateINS_6detail30bin_search_tree_const_node_it_INS1_13rb_tree_node_IimSaIcEEENS1_25bin_search_tree_const_it_IPS5_iPiPKiRiRS9_Lb1ES4_EESD_S4_EESE_St4lessIiES4_E12order_of_keyESC_(ptr noundef nonnull align 8 dereferenceable(8) @cc, ptr noundef nonnull align 4 dereferenceable(4) %51)
  %53 = trunc i64 %52 to i32
  %54 = load i32, ptr %4, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %55
  store i32 %53, ptr %56, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %48
  %58 = load i32, ptr %4, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !11
  br label %43, !llvm.loop !15

60:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %61

61:                                               ; preds = %82, %60
  %62 = load i32, ptr %5, align 4, !tbaa !11
  %63 = load i32, ptr @n, align 4, !tbaa !11
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %85

66:                                               ; preds = %61
  %67 = load i32, ptr %5, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = add nsw i32 %70, 1
  call void @_ZN3BIT3updEii(ptr noundef nonnull align 4 dereferenceable(800024) @L, i32 noundef %71, i32 noundef 1)
  %72 = load i32, ptr %5, align 4, !tbaa !11
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !11
  %76 = add nsw i32 %75, 2
  %77 = load i32, ptr @n, align 4, !tbaa !11
  %78 = call noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024) @L, i32 noundef %76, i32 noundef %77)
  %79 = load i32, ptr %5, align 4, !tbaa !11
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [200005 x i32], ptr @ls, i64 0, i64 %80
  store i32 %78, ptr %81, align 4, !tbaa !11
  br label %82

82:                                               ; preds = %66
  %83 = load i32, ptr %5, align 4, !tbaa !11
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %5, align 4, !tbaa !11
  br label %61, !llvm.loop !16

85:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %86 = load i32, ptr @n, align 4, !tbaa !11
  %87 = sub nsw i32 %86, 1
  store i32 %87, ptr %6, align 4, !tbaa !11
  br label %88

88:                                               ; preds = %108, %85
  %89 = load i32, ptr %6, align 4, !tbaa !11
  %90 = icmp sge i32 %89, 0
  br i1 %90, label %92, label %91

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

92:                                               ; preds = %88
  %93 = load i32, ptr %6, align 4, !tbaa !11
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = add nsw i32 %96, 1
  call void @_ZN3BIT3updEii(ptr noundef nonnull align 4 dereferenceable(800024) @R, i32 noundef %97, i32 noundef 1)
  %98 = load i32, ptr %6, align 4, !tbaa !11
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !11
  %102 = add nsw i32 %101, 2
  %103 = load i32, ptr @n, align 4, !tbaa !11
  %104 = call noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024) @R, i32 noundef %102, i32 noundef %103)
  %105 = load i32, ptr %6, align 4, !tbaa !11
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [200005 x i32], ptr @rs, i64 0, i64 %106
  store i32 %104, ptr %107, align 4, !tbaa !11
  br label %108

108:                                              ; preds = %92
  %109 = load i32, ptr %6, align 4, !tbaa !11
  %110 = add nsw i32 %109, -1
  store i32 %110, ptr %6, align 4, !tbaa !11
  br label %88, !llvm.loop !17

111:                                              ; preds = %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %112

112:                                              ; preds = %140, %111
  %113 = load i32, ptr %7, align 4, !tbaa !11
  %114 = load i32, ptr @n, align 4, !tbaa !11
  %115 = icmp slt i32 %113, %114
  br i1 %115, label %117, label %116

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

117:                                              ; preds = %112
  %118 = load i32, ptr %7, align 4, !tbaa !11
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [200005 x i32], ptr @ls, i64 0, i64 %119
  %121 = load i32, ptr %7, align 4, !tbaa !11
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [200005 x i32], ptr @rs, i64 0, i64 %122
  %124 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %120, ptr noundef nonnull align 4 dereferenceable(4) %123)
  %125 = load i32, ptr %124, align 4, !tbaa !11
  %126 = load i32, ptr %7, align 4, !tbaa !11
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [200005 x i32], ptr @ls, i64 0, i64 %127
  %129 = load i32, ptr %7, align 4, !tbaa !11
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [200005 x i32], ptr @rs, i64 0, i64 %130
  %132 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %128, ptr noundef nonnull align 4 dereferenceable(4) %131)
  %133 = load i32, ptr %132, align 4, !tbaa !11
  %134 = mul nsw i32 2, %133
  %135 = icmp sgt i32 %125, %134
  br i1 %135, label %136, label %139

136:                                              ; preds = %117
  %137 = load i32, ptr @ans, align 4, !tbaa !11
  %138 = add nsw i32 %137, 1
  store i32 %138, ptr @ans, align 4, !tbaa !11
  br label %139

139:                                              ; preds = %136, %117
  br label %140

140:                                              ; preds = %139
  %141 = load i32, ptr %7, align 4, !tbaa !11
  %142 = add nsw i32 %141, 1
  store i32 %142, ptr %7, align 4, !tbaa !11
  br label %112, !llvm.loop !18

143:                                              ; preds = %116
  call void @_Z2prIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4) @ans)
  %144 = load i32, ptr %1, align 4
  ret i32 %144
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #2 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2reIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4)) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2inIPiEvT_S1_(ptr noundef, ptr noundef) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { ptr, i8 } @_ZN10__gnu_pbds6detail11rb_tree_setIiNS_9null_typeESt4lessIiENS0_11tree_traitsIiS2_S4_NS_33tree_order_statistics_node_updateENS_11rb_tree_tagESaIcEEES8_E6insertERKi(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK10__gnu_pbds33tree_order_statistics_node_updateINS_6detail30bin_search_tree_const_node_it_INS1_13rb_tree_node_IimSaIcEEENS1_25bin_search_tree_const_it_IPS5_iPiPKiRiRS9_Lb1ES4_EESD_S4_EESE_St4lessIiES4_E12order_of_keyESC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3BIT3updEii(ptr noundef nonnull align 4 dereferenceable(800024), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024), i32 noundef, i32 noundef) #3 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)) #6

; 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)) #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2prIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4)) #3

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


; 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.__gnu_pbds::tree" = type { %"class.__gnu_pbds::basic_branch" }
%"class.__gnu_pbds::basic_branch" = type { %"class.__gnu_pbds::detail::rb_tree_set" }
%"class.__gnu_pbds::detail::rb_tree_set" = type { %"class.__gnu_pbds::detail::bin_search_tree_set" }
%"class.__gnu_pbds::detail::bin_search_tree_set" = type { %"class.__gnu_pbds::tree_order_statistics_node_update", [8 x i8], ptr, i64 }
%"class.__gnu_pbds::tree_order_statistics_node_update" = type { %"struct.__gnu_pbds::detail::branch_policy" }
%"struct.__gnu_pbds::detail::branch_policy" = type { ptr }
%struct.BIT = type { [200006 x i32] }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@n = external dso_local global i32, align 4
@h = external dso_local global [200005 x i32], align 16
@ls = external dso_local global [200005 x i32], align 16
@rs = external dso_local global [200005 x i32], align 16
@ans = external dso_local global i32, align 4
@cc = external dso_local global %"class.__gnu_pbds::tree", align 8
@L = external dso_local global %struct.BIT, align 4
@R = external dso_local global %struct.BIT, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.3)
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %2

2:                                                ; preds = %0
  %3 = load ptr, ptr @stdin, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, ptr noundef %3)
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  %6 = tail call ptr @freopen(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, ptr noundef %5)
  br label %7

7:                                                ; preds = %2, %0
  %8 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %10
  %12 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %11, ptr noundef null)
  %13 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  tail call void @_Z2reIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4) @n)
  %14 = load i32, ptr @n, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @h, i64 %15
  tail call void @_Z2inIPiEvT_S1_(ptr noundef nonnull @h, ptr noundef nonnull %16)
  %17 = load i32, ptr @n, align 4, !tbaa !11
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.preheader31:                                     ; preds = %.lr.ph
  %19 = icmp sgt i32 %22, 0
  br i1 %19, label %.lr.ph34, label %._crit_edge

.lr.ph:                                           ; preds = %7, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %7 ]
  %20 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %indvars.iv
  %21 = tail call { ptr, i8 } @_ZN10__gnu_pbds6detail11rb_tree_setIiNS_9null_typeESt4lessIiENS0_11tree_traitsIiS2_S4_NS_33tree_order_statistics_node_updateENS_11rb_tree_tagESaIcEEES8_E6insertERKi(ptr noundef nonnull align 8 dereferenceable(32) @cc, ptr noundef nonnull align 4 dereferenceable(4) %20)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr @n, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %.preheader31, !llvm.loop !13

.preheader30:                                     ; preds = %.lr.ph34
  %25 = icmp sgt i32 %29, 0
  br i1 %25, label %.lr.ph36, label %._crit_edge

.lr.ph34:                                         ; preds = %.preheader31, %.lr.ph34
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.lr.ph34 ], [ 0, %.preheader31 ]
  %26 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %indvars.iv43
  %27 = tail call noundef i64 @_ZNK10__gnu_pbds33tree_order_statistics_node_updateINS_6detail30bin_search_tree_const_node_it_INS1_13rb_tree_node_IimSaIcEEENS1_25bin_search_tree_const_it_IPS5_iPiPKiRiRS9_Lb1ES4_EESD_S4_EESE_St4lessIiES4_E12order_of_keyESC_(ptr noundef nonnull align 8 dereferenceable(8) @cc, ptr noundef nonnull align 4 dereferenceable(4) %26)
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %26, align 4, !tbaa !11
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %29 = load i32, ptr @n, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next44, %30
  br i1 %31, label %.lr.ph34, label %.preheader30, !llvm.loop !15

.preheader29:                                     ; preds = %.lr.ph36
  %32 = icmp sgt i32 %42, 0
  br i1 %32, label %.lr.ph38.preheader, label %._crit_edge

.lr.ph38.preheader:                               ; preds = %.preheader29
  %33 = zext nneg i32 %42 to i64
  br label %.lr.ph38

.lr.ph36:                                         ; preds = %.preheader30, %.lr.ph36
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.lr.ph36 ], [ 0, %.preheader30 ]
  %34 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %indvars.iv46
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = add nsw i32 %35, 1
  tail call void @_ZN3BIT3updEii(ptr noundef nonnull align 4 dereferenceable(800024) @L, i32 noundef %36, i32 noundef 1)
  %37 = load i32, ptr %34, align 4, !tbaa !11
  %38 = add nsw i32 %37, 2
  %39 = load i32, ptr @n, align 4, !tbaa !11
  %40 = tail call noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024) @L, i32 noundef %38, i32 noundef %39)
  %41 = getelementptr inbounds [200005 x i32], ptr @ls, i64 0, i64 %indvars.iv46
  store i32 %40, ptr %41, align 4, !tbaa !11
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %42 = load i32, ptr @n, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next47, %43
  br i1 %44, label %.lr.ph36, label %.preheader29, !llvm.loop !16

.preheader:                                       ; preds = %.lr.ph38
  %.pre = load i32, ptr @n, align 4, !tbaa !11
  %45 = icmp sgt i32 %.pre, 0
  br i1 %45, label %.lr.ph40, label %._crit_edge

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.lr.ph38
  %indvars.iv49 = phi i64 [ %33, %.lr.ph38.preheader ], [ %indvars.iv.next50, %.lr.ph38 ]
  %indvars.iv.next50 = add nsw i64 %indvars.iv49, -1
  %46 = getelementptr inbounds [200005 x i32], ptr @h, i64 0, i64 %indvars.iv.next50
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = add nsw i32 %47, 1
  tail call void @_ZN3BIT3updEii(ptr noundef nonnull align 4 dereferenceable(800024) @R, i32 noundef %48, i32 noundef 1)
  %49 = load i32, ptr %46, align 4, !tbaa !11
  %50 = add nsw i32 %49, 2
  %51 = load i32, ptr @n, align 4, !tbaa !11
  %52 = tail call noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024) @R, i32 noundef %50, i32 noundef %51)
  %53 = getelementptr inbounds [200005 x i32], ptr @rs, i64 0, i64 %indvars.iv.next50
  store i32 %52, ptr %53, align 4, !tbaa !11
  %54 = icmp ugt i64 %indvars.iv49, 1
  br i1 %54, label %.lr.ph38, label %.preheader, !llvm.loop !17

._crit_edge:                                      ; preds = %66, %7, %.preheader31, %.preheader30, %.preheader29, %.preheader
  tail call void @_Z2prIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4) @ans)
  ret i32 0

.lr.ph40:                                         ; preds = %.preheader, %66
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %66 ], [ 0, %.preheader ]
  %55 = getelementptr inbounds [200005 x i32], ptr @ls, i64 0, i64 %indvars.iv52
  %56 = getelementptr inbounds [200005 x i32], ptr @rs, i64 0, i64 %indvars.iv52
  %57 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %55, ptr noundef nonnull align 4 dereferenceable(4) %56)
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %55, ptr noundef nonnull align 4 dereferenceable(4) %56)
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = shl nsw i32 %60, 1
  %62 = icmp sgt i32 %58, %61
  br i1 %62, label %63, label %66

63:                                               ; preds = %.lr.ph40
  %64 = load i32, ptr @ans, align 4, !tbaa !11
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @ans, align 4, !tbaa !11
  br label %66

66:                                               ; preds = %.lr.ph40, %63
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %67 = load i32, ptr @n, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = icmp slt i64 %indvars.iv.next53, %68
  br i1 %69, label %.lr.ph40, label %._crit_edge, !llvm.loop !18
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #3 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2reIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2inIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { ptr, i8 } @_ZN10__gnu_pbds6detail11rb_tree_setIiNS_9null_typeESt4lessIiENS0_11tree_traitsIiS2_S4_NS_33tree_order_statistics_node_updateENS_11rb_tree_tagESaIcEEES8_E6insertERKi(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK10__gnu_pbds33tree_order_statistics_node_updateINS_6detail30bin_search_tree_const_node_it_INS1_13rb_tree_node_IimSaIcEEENS1_25bin_search_tree_const_it_IPS5_iPiPKiRiRS9_Lb1ES4_EESD_S4_EESE_St4lessIiES4_E12order_of_keyESC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3BIT3qryEii(ptr noundef nonnull align 4 dereferenceable(800024), i32 noundef, i32 noundef) local_unnamed_addr #4 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 #6

; 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 #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2prIRiJEEvOT_DpOT0_(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "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 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 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 = { 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" }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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