; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100827I)

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

%struct.Edge = type { i32, i32 }
%struct.Segment = type { i32, i32, i32 }

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@lnk = external dso_local global [1000001 x i32], align 16
@in = external dso_local global [1000001 x i32], align 16
@out = external dso_local global [1000001 x i32], align 16
@e = external dso_local global [2000002 x %struct.Edge], align 16
@seg = external dso_local global [2000002 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_Z5queryiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %struct.Edge, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [2 x i8], align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.Segment, align 4
  %11 = alloca { i64, i32 }, align 8
  store i32 0, ptr %1, align 4
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %13

13:                                               ; preds = %128, %0
  %14 = load i32, ptr @t, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @t, align 4, !tbaa !5
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %129

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr @tot, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 %20, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @lnk, i64 1), i8 -1, i64 %21, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %44, %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %29 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 0
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000001 x i32], ptr @lnk, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %29, align 4, !tbaa !9
  %34 = getelementptr inbounds %struct.Edge, ptr %4, i32 0, i32 1
  %35 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %35, ptr %34, align 4, !tbaa !11
  %36 = load i32, ptr @tot, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %37
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  %39 = load i32, ptr @tot, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @tot, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000001 x i32], ptr @lnk, i64 0, i64 %42
  store i32 %39, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  br label %44

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

47:                                               ; preds = %26
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %80, %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %53, label %52

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

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %54 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = call noundef i32 @_Z7seg_idxii(i32 noundef %59, i32 noundef %63)
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.Segment, ptr %66, i32 0, i32 1
  store i32 %55, ptr %67, align 4, !tbaa !15
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = call noundef i32 @_Z7seg_idxii(i32 noundef %71, i32 noundef %75)
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.Segment, ptr %78, i32 0, i32 0
  store i32 %55, ptr %79, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %80

80:                                               ; preds = %53
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %48, !llvm.loop !18

83:                                               ; preds = %52
  %84 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5buildii(i32 noundef 1, i32 noundef %84)
  %85 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @q)
  br label %86

86:                                               ; preds = %127, %83
  %87 = load i32, ptr @q, align 4, !tbaa !5
  %88 = add nsw i32 %87, -1
  store i32 %88, ptr @q, align 4, !tbaa !5
  %89 = icmp ne i32 %87, 0
  br i1 %89, label %90, label %128

90:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %91 = getelementptr inbounds [2 x i8], ptr %7, i64 0, i64 0
  %92 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %91)
  %93 = getelementptr inbounds [2 x i8], ptr %7, i64 0, i64 0
  %94 = load i8, ptr %93, align 1, !tbaa !19
  %95 = sext i8 %94 to i32
  %96 = icmp eq i32 %95, 82
  br i1 %96, label %97, label %109

97:                                               ; preds = %90
  %98 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %8, ptr noundef %9)
  %99 = load i32, ptr @n, align 4, !tbaa !5
  %100 = load i32, ptr %8, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = load i32, ptr %8, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [1000001 x i32], ptr @out, i64 0, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef 1, i32 noundef %99, i32 noundef %103, i32 noundef %107, i32 noundef %108)
  br label %127

109:                                              ; preds = %90
  %110 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #7
  %111 = load i32, ptr @n, align 4, !tbaa !5
  %112 = load i32, ptr %8, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = load i32, ptr %8, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [1000001 x i32], ptr @out, i64 0, i64 %117
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = call { i64, i32 } @_Z5queryiiii(i32 noundef 1, i32 noundef %111, i32 noundef %115, i32 noundef %119)
  store { i64, i32 } %120, ptr %11, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %11, i64 12, i1 false)
  %121 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 0
  %122 = load i32, ptr %121, align 4, !tbaa !17
  %123 = getelementptr inbounds %struct.Segment, ptr %10, i32 0, i32 1
  %124 = load i32, ptr %123, align 4, !tbaa !15
  %125 = sub nsw i32 %122, %124
  %126 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %125)
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #7
  br label %127

127:                                              ; preds = %109, %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #7
  br label %86, !llvm.loop !20

128:                                              ; preds = %86
  br label %13, !llvm.loop !21

129:                                              ; preds = %13
  ret i32 0
}

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

; 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 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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 4}
!16 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 0}
!18 = distinct !{!18, !14}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !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"

%struct.Edge = type { i32, i32 }
%struct.Segment = type { i32, i32, i32 }

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@in = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@out = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@e = external dso_local local_unnamed_addr global [2000002 x %struct.Edge], align 16
@seg = external dso_local local_unnamed_addr global [2000002 x %struct.Segment], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(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 #0

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_Z5queryiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [2 x i8], align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %.not26 = icmp eq i32 %7, 0
  br i1 %.not26, label %._crit_edge29, label %.lr.ph28

.loopexit:                                        ; preds = %68, %._crit_edge22
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !9

.lr.ph28:                                         ; preds = %0, %.loopexit
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 0, ptr @tot, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = shl nsw i64 %13, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @lnk, i64 4), i8 -1, i64 %14, i1 false)
  %.not1316 = icmp slt i32 %12, 2
  br i1 %.not1316, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph28
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef 1)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %.not1418 = icmp slt i32 %15, 1
  br i1 %.not1418, label %._crit_edge22, label %.lr.ph21

.lr.ph:                                           ; preds = %.lr.ph28, %.lr.ph
  %.017 = phi i32 [ %25, %.lr.ph ], [ 2, %.lr.ph28 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000001 x i32], ptr @lnk, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000002 x %struct.Edge], ptr @e, i64 0, i64 %22
  store i32 %20, ptr %23, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 4
  store i32 %.017, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %24 = add nsw i32 %21, 1
  store i32 %24, ptr @tot, align 4, !tbaa !5
  store i32 %21, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %25 = add nuw nsw i32 %.017, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %.not13.not = icmp slt i32 %.017, %26
  br i1 %.not13.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge22:                                    ; preds = %.lr.ph21, %._crit_edge
  %.lcssa = phi i32 [ %15, %._crit_edge ], [ %41, %.lr.ph21 ]
  call void @_Z5buildii(i32 noundef 1, i32 noundef %.lcssa)
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @q)
  %28 = load i32, ptr @q, align 4, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr @q, align 4, !tbaa !5
  %.not1523 = icmp eq i32 %28, 0
  br i1 %.not1523, label %.loopexit, label %.lr.ph25

.lr.ph21:                                         ; preds = %._crit_edge, %.lr.ph21
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph21 ], [ 1, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call noundef i32 @_Z7seg_idxii(i32 noundef %33, i32 noundef %33)
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %35, i32 1
  store i32 %31, ptr %36, align 4, !tbaa !12
  %37 = load i32, ptr %32, align 4, !tbaa !5
  %38 = call noundef i32 @_Z7seg_idxii(i32 noundef %37, i32 noundef %37)
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2000002 x %struct.Segment], ptr @seg, i64 0, i64 %39
  store i32 %31, ptr %40, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %.not14.not = icmp slt i64 %indvars.iv, %42
  br i1 %.not14.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !15

.lr.ph25:                                         ; preds = %._crit_edge22, %68
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %44 = load i8, ptr %3, align 1, !tbaa !16
  %45 = icmp eq i8 %44, 82
  br i1 %45, label %46, label %56

46:                                               ; preds = %.lr.ph25
  %47 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = getelementptr inbounds [1000001 x i32], ptr @out, i64 0, i64 %50
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6updateiiiii(i32 noundef 1, i32 noundef %48, i32 noundef %52, i32 noundef %54, i32 noundef %55)
  br label %68

56:                                               ; preds = %.lr.ph25
  %57 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000001 x i32], ptr @in, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = getelementptr inbounds [1000001 x i32], ptr @out, i64 0, i64 %60
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = call { i64, i32 } @_Z5queryiiii(i32 noundef 1, i32 noundef %58, i32 noundef %62, i32 noundef %64)
  %.fca.0.extract = extractvalue { i64, i32 } %65, 0
  %.sroa.01.0.extract.trunc = trunc i64 %.fca.0.extract to i32
  %.sroa.01.4.extract.shift = lshr i64 %.fca.0.extract, 32
  %.sroa.01.4.extract.trunc = trunc nuw i64 %.sroa.01.4.extract.shift to i32
  %66 = sub nsw i32 %.sroa.01.0.extract.trunc, %.sroa.01.4.extract.trunc
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %66)
  br label %68

68:                                               ; preds = %56, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %3) #6
  %69 = load i32, ptr @q, align 4, !tbaa !5
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr @q, align 4, !tbaa !5
  %.not15 = icmp eq i32 %69, 0
  br i1 %.not15, label %.loopexit, label %.lr.ph25, !llvm.loop !17

._crit_edge29:                                    ; preds = %.loopexit, %0
  ret i32 0
}

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

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

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

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

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !6, i64 4}
!13 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!13, !6, i64 0}
!15 = distinct !{!15, !10}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !10}


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