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

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

@tot = external dso_local global i32, align 4
@out = external dso_local global [131072 x [2 x i32]], align 16
@root = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %10 = load ptr, ptr @stdin, align 8, !tbaa !5
  %11 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %10)
  %12 = load ptr, ptr @stdout, align 8, !tbaa !5
  %13 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  %14 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #9
  invoke void @_ZN11SegmentTreeC2Eii(ptr noundef nonnull align 8 dereferenceable(31) %14, i32 noundef 0, i32 noundef 131072)
          to label %15 unwind label %30

15:                                               ; preds = %0
  store ptr %14, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree9make_treeEv(ptr noundef nonnull align 8 dereferenceable(31) %14)
  br label %16

16:                                               ; preds = %89, %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %2, ptr noundef %3, ptr noundef %5, ptr noundef %6, ptr noundef %4)
  %18 = icmp eq i32 %17, 5
  br i1 %18, label %19, label %90

19:                                               ; preds = %16
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = shl i32 %20, 1
  store i32 %21, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = shl i32 %22, 1
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load i8, ptr %3, align 1, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 40
  br i1 %26, label %27, label %34

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !9
  br label %34

30:                                               ; preds = %0
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %7, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 32) #10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #8
  br label %227

34:                                               ; preds = %27, %19
  %35 = load i8, ptr %4, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %36, 41
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr %6, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %38, %34
  %42 = load i8, ptr %2, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  switch i32 %43, label %89 [
    i32 85, label %44
    i32 73, label %48
    i32 68, label %63
    i32 67, label %67
    i32 83, label %85
  ]

44:                                               ; preds = %41
  %45 = load ptr, ptr @root, align 8, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %45, i32 noundef %46, i32 noundef %47, i32 noundef 1)
  br label %89

48:                                               ; preds = %41
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %55

51:                                               ; preds = %48
  %52 = load ptr, ptr @root, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %52, i32 noundef 0, i32 noundef %54, i32 noundef 0)
  br label %55

55:                                               ; preds = %51, %48
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp slt i32 %56, 131072
  br i1 %57, label %58, label %62

58:                                               ; preds = %55
  %59 = load ptr, ptr @root, align 8, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %59, i32 noundef %61, i32 noundef 131072, i32 noundef 0)
  br label %62

62:                                               ; preds = %58, %55
  br label %89

63:                                               ; preds = %41
  %64 = load ptr, ptr @root, align 8, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %64, i32 noundef %65, i32 noundef %66, i32 noundef 0)
  br label %89

67:                                               ; preds = %41
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %74

70:                                               ; preds = %67
  %71 = load ptr, ptr @root, align 8, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %71, i32 noundef 0, i32 noundef %73, i32 noundef 0)
  br label %74

74:                                               ; preds = %70, %67
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = icmp slt i32 %75, 131072
  br i1 %76, label %77, label %81

77:                                               ; preds = %74
  %78 = load ptr, ptr @root, align 8, !tbaa !5
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %78, i32 noundef %80, i32 noundef 131072, i32 noundef 0)
  br label %81

81:                                               ; preds = %77, %74
  %82 = load ptr, ptr @root, align 8, !tbaa !5
  %83 = load i32, ptr %5, align 4, !tbaa !9
  %84 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31) %82, i32 noundef %83, i32 noundef %84)
  br label %89

85:                                               ; preds = %41
  %86 = load ptr, ptr @root, align 8, !tbaa !5
  %87 = load i32, ptr %5, align 4, !tbaa !9
  %88 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31) %86, i32 noundef %87, i32 noundef %88)
  br label %89

89:                                               ; preds = %85, %81, %63, %62, %44, %41
  br label %16, !llvm.loop !12

90:                                               ; preds = %16
  %91 = load ptr, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree3preEv(ptr noundef nonnull align 8 dereferenceable(31) %91)
  %92 = load i32, ptr @tot, align 4, !tbaa !9
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %96, label %94

94:                                               ; preds = %90
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %222

96:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %168, %96
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = load i32, ptr @tot, align 4, !tbaa !9
  %100 = sub nsw i32 %99, 1
  %101 = icmp slt i32 %98, %100
  br i1 %101, label %102, label %171

102:                                              ; preds = %97
  %103 = load i32, ptr %9, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %104
  %106 = getelementptr inbounds [2 x i32], ptr %105, i64 0, i64 1
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  %109 = load i32, ptr %9, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %111
  %113 = getelementptr inbounds [2 x i32], ptr %112, i64 0, i64 0
  %114 = load i32, ptr %113, align 8, !tbaa !9
  %115 = icmp eq i32 %108, %114
  br i1 %115, label %116, label %127

116:                                              ; preds = %102
  %117 = load i32, ptr %9, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %118
  %120 = getelementptr inbounds [2 x i32], ptr %119, i64 0, i64 0
  %121 = load i32, ptr %120, align 8, !tbaa !9
  %122 = load i32, ptr %9, align 4, !tbaa !9
  %123 = add nsw i32 %122, 1
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %124
  %126 = getelementptr inbounds [2 x i32], ptr %125, i64 0, i64 0
  store i32 %121, ptr %126, align 8, !tbaa !9
  br label %167

127:                                              ; preds = %102
  %128 = load i32, ptr %9, align 4, !tbaa !9
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %129
  %131 = getelementptr inbounds [2 x i32], ptr %130, i64 0, i64 0
  %132 = load i32, ptr %131, align 8, !tbaa !9
  %133 = and i32 %132, 1
  %134 = icmp ne i32 %133, 0
  br i1 %134, label %135, label %137

135:                                              ; preds = %127
  %136 = call i32 @putchar(i32 noundef 40)
  br label %139

137:                                              ; preds = %127
  %138 = call i32 @putchar(i32 noundef 91)
  br label %139

139:                                              ; preds = %137, %135
  %140 = load i32, ptr %9, align 4, !tbaa !9
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %141
  %143 = getelementptr inbounds [2 x i32], ptr %142, i64 0, i64 0
  %144 = load i32, ptr %143, align 8, !tbaa !9
  %145 = ashr i32 %144, 1
  %146 = load i32, ptr %9, align 4, !tbaa !9
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %147
  %149 = getelementptr inbounds [2 x i32], ptr %148, i64 0, i64 1
  %150 = load i32, ptr %149, align 4, !tbaa !9
  %151 = add nsw i32 %150, 1
  %152 = ashr i32 %151, 1
  %153 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %145, i32 noundef %152)
  %154 = load i32, ptr %9, align 4, !tbaa !9
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %155
  %157 = getelementptr inbounds [2 x i32], ptr %156, i64 0, i64 1
  %158 = load i32, ptr %157, align 4, !tbaa !9
  %159 = and i32 %158, 1
  %160 = icmp ne i32 %159, 0
  br i1 %160, label %161, label %163

161:                                              ; preds = %139
  %162 = call i32 @putchar(i32 noundef 41)
  br label %165

163:                                              ; preds = %139
  %164 = call i32 @putchar(i32 noundef 93)
  br label %165

165:                                              ; preds = %163, %161
  %166 = call i32 @putchar(i32 noundef 32)
  br label %167

167:                                              ; preds = %165, %116
  br label %168

168:                                              ; preds = %167
  %169 = load i32, ptr %9, align 4, !tbaa !9
  %170 = add nsw i32 %169, 1
  store i32 %170, ptr %9, align 4, !tbaa !9
  br label %97, !llvm.loop !14

171:                                              ; preds = %97
  %172 = load i32, ptr %9, align 4, !tbaa !9
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %173
  %175 = getelementptr inbounds [2 x i32], ptr %174, i64 0, i64 0
  %176 = load i32, ptr %175, align 8, !tbaa !9
  %177 = and i32 %176, 1
  %178 = icmp ne i32 %177, 0
  br i1 %178, label %179, label %181

179:                                              ; preds = %171
  %180 = call i32 @putchar(i32 noundef 40)
  br label %183

181:                                              ; preds = %171
  %182 = call i32 @putchar(i32 noundef 91)
  br label %183

183:                                              ; preds = %181, %179
  %184 = load i32, ptr %9, align 4, !tbaa !9
  %185 = sext i32 %184 to i64
  %186 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %185
  %187 = getelementptr inbounds [2 x i32], ptr %186, i64 0, i64 0
  %188 = load i32, ptr %187, align 8, !tbaa !9
  %189 = ashr i32 %188, 1
  %190 = load i32, ptr %9, align 4, !tbaa !9
  %191 = sext i32 %190 to i64
  %192 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %191
  %193 = getelementptr inbounds [2 x i32], ptr %192, i64 0, i64 1
  %194 = load i32, ptr %193, align 4, !tbaa !9
  %195 = add nsw i32 %194, 1
  %196 = ashr i32 %195, 1
  %197 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %189, i32 noundef %196)
  %198 = load i32, ptr %9, align 4, !tbaa !9
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %199
  %201 = getelementptr inbounds [2 x i32], ptr %200, i64 0, i64 1
  %202 = load i32, ptr %201, align 4, !tbaa !9
  %203 = and i32 %202, 1
  %204 = icmp ne i32 %203, 0
  br i1 %204, label %205, label %207

205:                                              ; preds = %183
  %206 = call i32 @putchar(i32 noundef 41)
  br label %209

207:                                              ; preds = %183
  %208 = call i32 @putchar(i32 noundef 93)
  br label %209

209:                                              ; preds = %207, %205
  %210 = load i32, ptr %9, align 4, !tbaa !9
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %211
  %213 = getelementptr inbounds [2 x i32], ptr %212, i64 0, i64 1
  %214 = load i32, ptr %213, align 4, !tbaa !9
  %215 = add nsw i32 %214, 1
  %216 = ashr i32 %215, 1
  %217 = icmp ne i32 %216, 65535
  br i1 %217, label %218, label %220

218:                                              ; preds = %209
  %219 = call i32 @putchar(i32 noundef 32)
  br label %220

220:                                              ; preds = %218, %209
  %221 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %222

222:                                              ; preds = %220, %94
  %223 = load ptr, ptr @stdin, align 8, !tbaa !5
  %224 = call i32 @fclose(ptr noundef %223)
  %225 = load ptr, ptr @stdout, align 8, !tbaa !5
  %226 = call i32 @fclose(ptr noundef %225)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #8
  ret i32 0

227:                                              ; preds = %30
  %228 = load ptr, ptr %7, align 8
  %229 = load i32, ptr %8, align 4
  %230 = insertvalue { ptr, i32 } poison, ptr %228, 0
  %231 = insertvalue { ptr, i32 } %230, i32 %229, 1
  resume { ptr, i32 } %231
}

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11SegmentTreeC2Eii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree9make_treeEv(ptr noundef nonnull align 8 dereferenceable(31)) #6 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef, i32 noundef) #6 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef) #6 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree3preEv(ptr noundef nonnull align 8 dereferenceable(31)) #6 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #7

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

declare i32 @fclose(ptr noundef) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nobuiltin allocsize(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 = { nobuiltin 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 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 = { 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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }
attributes #10 = { builtin 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@out = external dso_local local_unnamed_addr global [131072 x [2 x i32]], align 16
@root = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = load ptr, ptr @stdin, align 8, !tbaa !5
  %7 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %6)
  %8 = load ptr, ptr @stdout, align 8, !tbaa !5
  %9 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  %10 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #9
  tail call void @_ZN11SegmentTreeC2Eii(ptr noundef nonnull align 8 dereferenceable(31) %10, i32 noundef 0, i32 noundef 131072)
  store ptr %10, ptr @root, align 8, !tbaa !5
  tail call void @_ZN11SegmentTree9make_treeEv(ptr noundef nonnull align 8 dereferenceable(31) %10)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %3)
  %12 = icmp eq i32 %11, 5
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %60
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = shl i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = shl i32 %15, 1
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = load i8, ptr %2, align 1, !tbaa !11
  %18 = icmp eq i8 %17, 40
  br i1 %18, label %19, label %21

19:                                               ; preds = %.lr.ph
  %20 = or disjoint i32 %14, 1
  store i32 %20, ptr %4, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %19, %.lr.ph
  %22 = phi i32 [ %20, %19 ], [ %14, %.lr.ph ]
  %23 = load i8, ptr %3, align 1, !tbaa !11
  %24 = icmp eq i8 %23, 41
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = add nsw i32 %16, -1
  store i32 %26, ptr %5, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %25, %21
  %28 = phi i32 [ %26, %25 ], [ %16, %21 ]
  %29 = load i8, ptr %1, align 1, !tbaa !11
  switch i8 %29, label %60 [
    i8 85, label %30
    i8 73, label %32
    i8 68, label %42
    i8 67, label %44
    i8 83, label %58
  ]

30:                                               ; preds = %27
  %31 = load ptr, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %31, i32 noundef %22, i32 noundef %28, i32 noundef 1)
  br label %60

32:                                               ; preds = %27
  %.not25 = icmp eq i32 %22, 0
  br i1 %.not25, label %36, label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr @root, align 8, !tbaa !5
  %35 = add nsw i32 %22, -1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %34, i32 noundef 0, i32 noundef %35, i32 noundef 0)
  %.pre31 = load i32, ptr %5, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %33, %32
  %37 = phi i32 [ %.pre31, %33 ], [ %28, %32 ]
  %38 = icmp slt i32 %37, 131072
  br i1 %38, label %39, label %60

39:                                               ; preds = %36
  %40 = load ptr, ptr @root, align 8, !tbaa !5
  %41 = add nsw i32 %37, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %40, i32 noundef %41, i32 noundef 131072, i32 noundef 0)
  br label %60

42:                                               ; preds = %27
  %43 = load ptr, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %43, i32 noundef %22, i32 noundef %28, i32 noundef 0)
  br label %60

44:                                               ; preds = %27
  %.not24 = icmp eq i32 %22, 0
  br i1 %.not24, label %48, label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr @root, align 8, !tbaa !5
  %47 = add nsw i32 %22, -1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %46, i32 noundef 0, i32 noundef %47, i32 noundef 0)
  %.pre = load i32, ptr %5, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %45, %44
  %49 = phi i32 [ %.pre, %45 ], [ %28, %44 ]
  %50 = icmp slt i32 %49, 131072
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load ptr, ptr @root, align 8, !tbaa !5
  %53 = add nsw i32 %49, 1
  call void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31) %52, i32 noundef %53, i32 noundef 131072, i32 noundef 0)
  %.pre30 = load i32, ptr %5, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %51, %48
  %55 = phi i32 [ %.pre30, %51 ], [ %49, %48 ]
  %56 = load ptr, ptr @root, align 8, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31) %56, i32 noundef %57, i32 noundef %55)
  br label %60

58:                                               ; preds = %27
  %59 = load ptr, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31) %59, i32 noundef %22, i32 noundef %28)
  br label %60

60:                                               ; preds = %36, %39, %58, %54, %42, %30, %27
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %3)
  %62 = icmp eq i32 %61, 5
  br i1 %62, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %60, %0
  %63 = load ptr, ptr @root, align 8, !tbaa !5
  call void @_ZN11SegmentTree3preEv(ptr noundef nonnull align 8 dereferenceable(31) %63)
  %64 = load i32, ptr @tot, align 4, !tbaa !9
  %.not = icmp eq i32 %64, 0
  br i1 %.not, label %66, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %65 = icmp sgt i32 %64, 1
  br i1 %65, label %.lr.ph27, label %._crit_edge28

66:                                               ; preds = %._crit_edge
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %117

.lr.ph27:                                         ; preds = %.preheader, %91
  %68 = phi i32 [ %92, %91 ], [ %64, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %91 ], [ 0, %.preheader ]
  %69 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %indvars.iv
  %70 = getelementptr inbounds i8, ptr %69, i64 4
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %73 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %indvars.iv.next
  %74 = load i32, ptr %73, align 8, !tbaa !9
  %75 = icmp eq i32 %72, %74
  %76 = load i32, ptr %69, align 8, !tbaa !9
  br i1 %75, label %77, label %78

77:                                               ; preds = %.lr.ph27
  store i32 %76, ptr %73, align 8, !tbaa !9
  br label %91

78:                                               ; preds = %.lr.ph27
  %79 = and i32 %76, 1
  %.not22 = icmp eq i32 %79, 0
  %. = select i1 %.not22, i32 91, i32 40
  %80 = call i32 @putchar(i32 noundef %.)
  %81 = load i32, ptr %69, align 8, !tbaa !9
  %82 = ashr i32 %81, 1
  %83 = load i32, ptr %70, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  %85 = ashr i32 %84, 1
  %86 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %82, i32 noundef %85)
  %87 = load i32, ptr %70, align 4, !tbaa !9
  %88 = and i32 %87, 1
  %.not23 = icmp eq i32 %88, 0
  %.sink33 = select i1 %.not23, i32 93, i32 41
  %89 = call i32 @putchar(i32 noundef %.sink33)
  %90 = call i32 @putchar(i32 noundef 32)
  %.pre32 = load i32, ptr @tot, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %77, %78
  %92 = phi i32 [ %68, %77 ], [ %.pre32, %78 ]
  %93 = add nsw i32 %92, -1
  %94 = sext i32 %93 to i64
  %95 = icmp slt i64 %indvars.iv.next, %94
  br i1 %95, label %.lr.ph27, label %._crit_edge28.loopexit, !llvm.loop !14

._crit_edge28.loopexit:                           ; preds = %91
  %96 = and i64 %indvars.iv.next, 4294967295
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %96, %._crit_edge28.loopexit ]
  %97 = getelementptr inbounds [131072 x [2 x i32]], ptr @out, i64 0, i64 %.0.lcssa
  %98 = load i32, ptr %97, align 8, !tbaa !9
  %99 = and i32 %98, 1
  %.not19 = icmp eq i32 %99, 0
  %.36 = select i1 %.not19, i32 91, i32 40
  %100 = call i32 @putchar(i32 noundef %.36)
  %101 = load i32, ptr %97, align 8, !tbaa !9
  %102 = ashr i32 %101, 1
  %103 = getelementptr inbounds i8, ptr %97, i64 4
  %104 = load i32, ptr %103, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  %106 = ashr i32 %105, 1
  %107 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %102, i32 noundef %106)
  %108 = load i32, ptr %103, align 4, !tbaa !9
  %109 = and i32 %108, 1
  %.not20 = icmp eq i32 %109, 0
  %.sink35 = select i1 %.not20, i32 93, i32 41
  %110 = call i32 @putchar(i32 noundef %.sink35)
  %111 = load i32, ptr %103, align 4, !tbaa !9
  %112 = add nsw i32 %111, 1
  %.mask = and i32 %112, -2
  %.not21 = icmp eq i32 %.mask, 131070
  br i1 %.not21, label %115, label %113

113:                                              ; preds = %._crit_edge28
  %114 = call i32 @putchar(i32 noundef 32)
  br label %115

115:                                              ; preds = %113, %._crit_edge28
  %116 = call i32 @putchar(i32 noundef 10)
  br label %117

117:                                              ; preds = %115, %66
  %118 = load ptr, ptr @stdin, align 8, !tbaa !5
  %119 = call i32 @fclose(ptr noundef %118)
  %120 = load ptr, ptr @stdout, align 8, !tbaa !5
  %121 = call i32 @fclose(ptr noundef %120)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #8
  ret i32 0
}

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11SegmentTreeC2Eii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree9make_treeEv(ptr noundef nonnull align 8 dereferenceable(31)) local_unnamed_addr #5 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree4fillEiii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree3revEii(ptr noundef nonnull align 8 dereferenceable(31), i32 noundef, i32 noundef) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SegmentTree3preEv(ptr noundef nonnull align 8 dereferenceable(31)) local_unnamed_addr #5 align 2

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #7

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #6

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nobuiltin allocsize(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 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 = { 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 #7 = { inlinehint mustprogress nofree 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 #8 = { nounwind }
attributes #9 = { builtin allocsize(0) }

!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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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