; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Company Contests/CodeStorm/Problem F (F)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

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

@n = external dso_local global i32, align 4
@a = external dso_local global [524288 x i32], align 16
@cnt = external dso_local global i32, align 4
@compressor = external dso_local global %"class.std::set", align 8
@m = external dso_local global %"class.std::map", align 8
@tree1 = external dso_local global [524288 x i32], align 16
@used = external dso_local global [524288 x i32], align 16
@inf = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8
@MOD = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6query1i(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: 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 void @_Z7update1ii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6query2i(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7update2ii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5buildiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; 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)) #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 %"struct.std::pair", align 8
  %4 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %5 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %6 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %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
  store i32 0, ptr %1, align 4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

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

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

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %21)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %24
  %26 = call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48) @compressor, ptr noundef nonnull align 4 dereferenceable(4) %25)
  %27 = getelementptr inbounds { ptr, i8 }, ptr %3, i32 0, i32 0
  %28 = extractvalue { ptr, i8 } %26, 0
  store ptr %28, ptr %27, align 8
  %29 = getelementptr inbounds { ptr, i8 }, ptr %3, i32 0, i32 1
  %30 = extractvalue { ptr, i8 } %26, 1
  store i8 %30, ptr %29, align 8
  br label %31

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

34:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %35 = call ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @compressor) #7
  %36 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %4, i32 0, i32 0
  store ptr %35, ptr %36, align 8
  br label %37

37:                                               ; preds = %47, %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %38 = call ptr @_ZNKSt3setIiSt4lessIiESaIiEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @compressor) #7
  %39 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %5, i32 0, i32 0
  store ptr %38, ptr %39, align 8
  %40 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  br label %50

42:                                               ; preds = %37
  %43 = load i32, ptr @cnt, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @cnt, align 4, !tbaa !5
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #7
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %45)
  store i32 %44, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %42
  %48 = call ptr @_ZNSt23_Rb_tree_const_iteratorIiEppEi(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef 0) #7
  %49 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %6, i32 0, i32 0
  store ptr %48, ptr %49, align 8
  br label %37, !llvm.loop !11

50:                                               ; preds = %41
  call void @_Z5buildiii(i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %65, %50
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr @n, align 4, !tbaa !5
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %68

56:                                               ; preds = %51
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %58
  %60 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %59)
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %56
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !5
  br label %51, !llvm.loop !12

68:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %69 = load i32, ptr @inf, align 4, !tbaa !5
  store i32 %69, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %70 = load i32, ptr @n, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  store i32 %71, ptr %9, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %135, %68
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = icmp sge i32 %73, 0
  br i1 %74, label %76, label %75

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

76:                                               ; preds = %72
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = call noundef i32 @_Z6query1i(i32 noundef %80)
  %82 = icmp sgt i32 %81, 0
  br i1 %82, label %83, label %125

83:                                               ; preds = %76
  %84 = load i32, ptr %9, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = call noundef i32 @_Z6query2i(i32 noundef %87)
  %89 = icmp eq i32 %88, 0
  br i1 %89, label %90, label %123

90:                                               ; preds = %83
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = load i32, ptr @cnt, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  %98 = call noundef i32 @_Z5queryiiiii(i32 noundef %95, i32 noundef %97, i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  store i32 %98, ptr %10, align 4, !tbaa !5
  %99 = load i32, ptr %10, align 4, !tbaa !5
  %100 = load i32, ptr %9, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = icmp sgt i32 %99, %103
  br i1 %104, label %105, label %110

105:                                              ; preds = %90
  %106 = load i64, ptr @ans, align 8, !tbaa !13
  %107 = mul nsw i64 %106, 2
  %108 = load i64, ptr @MOD, align 8, !tbaa !13
  %109 = srem i64 %107, %108
  store i64 %109, ptr @ans, align 8, !tbaa !13
  br label %110

110:                                              ; preds = %105, %90
  %111 = load i32, ptr %9, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !5
  %115 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef %114, i32 noundef %115, i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  %116 = load i32, ptr %9, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %117
  %119 = load i32, ptr %118, align 4, !tbaa !5
  call void @_Z7update2ii(i32 noundef %119, i32 noundef 1)
  %120 = load i32, ptr %9, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [524288 x i32], ptr @used, i64 0, i64 %121
  store i32 1, ptr %122, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %124

123:                                              ; preds = %83
  store i64 0, ptr @ans, align 8, !tbaa !13
  br label %124

124:                                              ; preds = %123, %110
  br label %125

125:                                              ; preds = %124, %76
  %126 = load i32, ptr %9, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  call void @_Z7update1ii(i32 noundef %129, i32 noundef 1)
  %130 = load i32, ptr %9, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %131
  %133 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %132)
  %134 = load i32, ptr %133, align 4, !tbaa !5
  store i32 %134, ptr %8, align 4, !tbaa !5
  br label %135

135:                                              ; preds = %125
  %136 = load i32, ptr %9, align 4, !tbaa !5
  %137 = add nsw i32 %136, -1
  store i32 %137, ptr %9, align 4, !tbaa !5
  br label %72, !llvm.loop !15

138:                                              ; preds = %75
  call void @llvm.memset.p0.i64(ptr align 16 @tree1, i8 0, i64 2097152, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %139

139:                                              ; preds = %170, %138
  %140 = load i32, ptr %11, align 4, !tbaa !5
  %141 = load i32, ptr @n, align 4, !tbaa !5
  %142 = icmp slt i32 %140, %141
  br i1 %142, label %144, label %143

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

144:                                              ; preds = %139
  %145 = load i32, ptr %11, align 4, !tbaa !5
  %146 = load i32, ptr %11, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  %150 = sub nsw i32 %149, 1
  %151 = call noundef i32 @_Z6query1i(i32 noundef %150)
  %152 = sub nsw i32 %145, %151
  %153 = icmp eq i32 %152, 0
  br i1 %153, label %154, label %165

154:                                              ; preds = %144
  %155 = load i32, ptr %11, align 4, !tbaa !5
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [524288 x i32], ptr @used, i64 0, i64 %156
  %158 = load i32, ptr %157, align 4, !tbaa !5
  %159 = icmp ne i32 %158, 0
  br i1 %159, label %165, label %160

160:                                              ; preds = %154
  %161 = load i64, ptr @ans, align 8, !tbaa !13
  %162 = mul nsw i64 %161, 2
  %163 = load i64, ptr @MOD, align 8, !tbaa !13
  %164 = srem i64 %162, %163
  store i64 %164, ptr @ans, align 8, !tbaa !13
  br label %165

165:                                              ; preds = %160, %154, %144
  %166 = load i32, ptr %11, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %167
  %169 = load i32, ptr %168, align 4, !tbaa !5
  call void @_Z7update1ii(i32 noundef %169, i32 noundef 1)
  br label %170

170:                                              ; preds = %165
  %171 = load i32, ptr %11, align 4, !tbaa !5
  %172 = add nsw i32 %171, 1
  store i32 %172, ptr %11, align 4, !tbaa !5
  br label %139, !llvm.loop !16

173:                                              ; preds = %143
  %174 = load i64, ptr @ans, align 8, !tbaa !13
  %175 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %174)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  ret i32 0
}

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

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

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

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

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::map" = type { %"class.std::_Rb_tree.0" }
%"class.std::_Rb_tree.0" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@a = external dso_local global [524288 x i32], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4
@compressor = external dso_local global %"class.std::set", align 8
@m = external dso_local global %"class.std::map", align 8
@tree1 = external dso_local local_unnamed_addr global [524288 x i32], align 16
@used = external dso_local local_unnamed_addr global [524288 x i32], align 16
@inf = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8
@MOD = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6query1i(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 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 void @_Z7update1ii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6query2i(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7update2ii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5buildiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #4 {
  %1 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %2 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %3 = alloca i32, align 4
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #7
  %7 = tail call ptr @_ZNKSt3setIiSt4lessIiESaIiEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @compressor) #7
  store ptr %7, ptr %1, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  %8 = tail call ptr @_ZNKSt3setIiSt4lessIiESaIiEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @compressor) #7
  store ptr %8, ptr %2, align 8
  %9 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  br i1 %9, label %.lr.ph32, label %._crit_edge33

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %10 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %10)
  %12 = tail call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48) @compressor, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge33:                                    ; preds = %.lr.ph32, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #7
  call void @_Z5buildiii(i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph36, label %._crit_edge37.thread

._crit_edge37.thread:                             ; preds = %._crit_edge33
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  %storemerge3860 = load i32, ptr @inf, align 4, !tbaa !5
  store i32 %storemerge3860, ptr %3, align 4, !tbaa !5
  br label %._crit_edge43.thread

.lr.ph32:                                         ; preds = %._crit_edge, %.lr.ph32
  %18 = load i32, ptr @cnt, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt23_Rb_tree_const_iteratorIiEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %1) #7
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %20)
  store i32 %19, ptr %21, align 4, !tbaa !5
  %22 = call ptr @_ZNSt23_Rb_tree_const_iteratorIiEppEi(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 0) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  %23 = call ptr @_ZNKSt3setIiSt4lessIiESaIiEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @compressor) #7
  store ptr %23, ptr %2, align 8
  %24 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorIiES2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  br i1 %24, label %.lr.ph32, label %._crit_edge33, !llvm.loop !11

._crit_edge37:                                    ; preds = %.lr.ph36
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  %storemerge38 = load i32, ptr @inf, align 4, !tbaa !5
  store i32 %storemerge38, ptr %3, align 4, !tbaa !5
  %25 = icmp sgt i32 %30, 0
  br i1 %25, label %.lr.ph42.preheader, label %._crit_edge43.thread

.lr.ph42.preheader:                               ; preds = %._crit_edge37
  %26 = zext nneg i32 %30 to i64
  br label %.lr.ph42

.lr.ph36:                                         ; preds = %._crit_edge33, %.lr.ph36
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %.lr.ph36 ], [ 0, %._crit_edge33 ]
  %27 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %indvars.iv50
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %27)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %27, align 4, !tbaa !5
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next51, %31
  br i1 %32, label %.lr.ph36, label %._crit_edge37, !llvm.loop !12

._crit_edge43.thread:                             ; preds = %._crit_edge37, %._crit_edge37.thread
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2097152) @tree1, i8 0, i64 2097152, i1 false)
  br label %._crit_edge47

._crit_edge43:                                    ; preds = %60
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp sgt i32 %.pre, 0
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2097152) @tree1, i8 0, i64 2097152, i1 false)
  br i1 %33, label %.lr.ph46, label %._crit_edge47

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %60
  %indvars.iv53 = phi i64 [ %26, %.lr.ph42.preheader ], [ %indvars.iv.next54, %60 ]
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  %34 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %indvars.iv.next54
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = call noundef i32 @_Z6query1i(i32 noundef %35)
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %38, label %60

38:                                               ; preds = %.lr.ph42
  %39 = load i32, ptr %34, align 4, !tbaa !5
  %40 = call noundef i32 @_Z6query2i(i32 noundef %39)
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %59

42:                                               ; preds = %38
  %43 = load i32, ptr %34, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr @cnt, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = call noundef i32 @_Z5queryiiiii(i32 noundef %44, i32 noundef %46, i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  %48 = load i32, ptr %34, align 4, !tbaa !5
  %49 = icmp sgt i32 %47, %48
  br i1 %49, label %50, label %55

50:                                               ; preds = %42
  %51 = load i64, ptr @ans, align 8, !tbaa !13
  %52 = shl nsw i64 %51, 1
  %53 = load i64, ptr @MOD, align 8, !tbaa !13
  %54 = srem i64 %52, %53
  store i64 %54, ptr @ans, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %50, %42
  %56 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef %48, i32 noundef %56, i32 noundef 1, i32 noundef 0, i32 noundef 524288)
  %57 = load i32, ptr %34, align 4, !tbaa !5
  call void @_Z7update2ii(i32 noundef %57, i32 noundef 1)
  %58 = getelementptr inbounds [524288 x i32], ptr @used, i64 0, i64 %indvars.iv.next54
  store i32 1, ptr %58, align 4, !tbaa !5
  br label %60

59:                                               ; preds = %38
  store i64 0, ptr @ans, align 8, !tbaa !13
  br label %60

60:                                               ; preds = %55, %59, %.lr.ph42
  %61 = load i32, ptr %34, align 4, !tbaa !5
  call void @_Z7update1ii(i32 noundef %61, i32 noundef 1)
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %34)
  %storemerge = load i32, ptr %62, align 4, !tbaa !5
  store i32 %storemerge, ptr %3, align 4, !tbaa !5
  %63 = icmp ugt i64 %indvars.iv53, 1
  br i1 %63, label %.lr.ph42, label %._crit_edge43, !llvm.loop !15

._crit_edge47:                                    ; preds = %80, %._crit_edge43.thread, %._crit_edge43
  %64 = load i64, ptr @ans, align 8, !tbaa !13
  %65 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  ret i32 0

.lr.ph46:                                         ; preds = %._crit_edge43, %80
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %80 ], [ 0, %._crit_edge43 ]
  %66 = getelementptr inbounds [524288 x i32], ptr @a, i64 0, i64 %indvars.iv56
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = add nsw i32 %67, -1
  %69 = call noundef i32 @_Z6query1i(i32 noundef %68)
  %70 = zext i32 %69 to i64
  %71 = icmp eq i64 %indvars.iv56, %70
  br i1 %71, label %72, label %80

72:                                               ; preds = %.lr.ph46
  %73 = getelementptr inbounds [524288 x i32], ptr @used, i64 0, i64 %indvars.iv56
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %.not = icmp eq i32 %74, 0
  br i1 %.not, label %75, label %80

75:                                               ; preds = %72
  %76 = load i64, ptr @ans, align 8, !tbaa !13
  %77 = shl nsw i64 %76, 1
  %78 = load i64, ptr @MOD, align 8, !tbaa !13
  %79 = srem i64 %77, %78
  store i64 %79, ptr @ans, align 8, !tbaa !13
  br label %80

80:                                               ; preds = %75, %72, %.lr.ph46
  %81 = load i32, ptr %66, align 4, !tbaa !5
  call void @_Z7update1ii(i32 noundef %81, i32 noundef 1)
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %82 = load i32, ptr @n, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = icmp slt i64 %indvars.iv.next57, %83
  br i1 %84, label %.lr.ph46, label %._crit_edge47, !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 { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertERKi(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 align 2

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

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

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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