; LLVM IR from tangjz/acm-icpc :: lydsy/3207.ll (Z5queryiiiii)

; 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::multiset" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<std::pair<unsigned long long, unsigned long long>, std::pair<unsigned long long, unsigned long long>, std::_Identity<std::pair<unsigned long long, unsigned long long>>, std::less<std::pair<unsigned long long, unsigned long long>>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<std::pair<unsigned long long, unsigned long long>, std::pair<unsigned long long, unsigned long long>, std::_Identity<std::pair<unsigned long long, unsigned long long>>, std::less<std::pair<unsigned long long, unsigned long long>>>::_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 }
%"struct.std::pair" = type { i64, i64 }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@Seg = external dso_local global [262144 x %"class.std::multiset"], align 16
@tmp = external dso_local global %"struct.std::pair", align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i1, align 1
  %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
  %12 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %13 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %35

19:                                               ; preds = %5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %35

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %24 = load i32, ptr %11, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [262144 x %"class.std::multiset"], ptr @Seg, i64 0, i64 %25
  %27 = call ptr @_ZNSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE4findERKS1_(ptr noundef nonnull align 8 dereferenceable(48) %26, ptr noundef nonnull align 8 dereferenceable(16) @tmp)
  %28 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %12, i32 0, i32 0
  store ptr %27, ptr %28, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [262144 x %"class.std::multiset"], ptr @Seg, i64 0, i64 %30
  %32 = call ptr @_ZNKSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %31) #3
  %33 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %13, i32 0, i32 0
  store ptr %32, ptr %33, align 8
  %34 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorISt4pairIyyEES4_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %13) #3
  store i1 %34, ptr %6, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %87

35:                                               ; preds = %19, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %14, align 4, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = icmp sle i32 %40, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %35
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %14, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = shl i32 %48, 1
  %50 = call noundef zeroext i1 @_Z5queryiiiii(i32 noundef %44, i32 noundef %45, i32 noundef %46, i32 noundef %47, i32 noundef %49)
  store i1 %50, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %86

51:                                               ; preds = %35
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %14, align 4, !tbaa !5
  %54 = icmp sgt i32 %52, %53
  br i1 %54, label %55, label %65

55:                                               ; preds = %51
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %14, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = shl i32 %61, 1
  %63 = xor i32 %62, 1
  %64 = call noundef zeroext i1 @_Z5queryiiiii(i32 noundef %56, i32 noundef %57, i32 noundef %59, i32 noundef %60, i32 noundef %63)
  store i1 %64, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %86

65:                                               ; preds = %51
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = load i32, ptr %14, align 4, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %14, align 4, !tbaa !5
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = shl i32 %70, 1
  %72 = call noundef zeroext i1 @_Z5queryiiiii(i32 noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69, i32 noundef %71)
  br i1 %72, label %84, label %73

73:                                               ; preds = %65
  %74 = load i32, ptr %14, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = load i32, ptr %14, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  %79 = load i32, ptr %10, align 4, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %81 = shl i32 %80, 1
  %82 = xor i32 %81, 1
  %83 = call noundef zeroext i1 @_Z5queryiiiii(i32 noundef %75, i32 noundef %76, i32 noundef %78, i32 noundef %79, i32 noundef %82)
  br label %84

84:                                               ; preds = %73, %65
  %85 = phi i1 [ true, %65 ], [ %83, %73 ]
  store i1 %85, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %86

86:                                               ; preds = %84, %55, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %87

87:                                               ; preds = %86, %23
  %88 = load i1, ptr %6, align 1
  ret i1 %88
}

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

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

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

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


; 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::multiset" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<std::pair<unsigned long long, unsigned long long>, std::pair<unsigned long long, unsigned long long>, std::_Identity<std::pair<unsigned long long, unsigned long long>>, std::less<std::pair<unsigned long long, unsigned long long>>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<std::pair<unsigned long long, unsigned long long>, std::pair<unsigned long long, unsigned long long>, std::_Identity<std::pair<unsigned long long, unsigned long long>>, std::less<std::pair<unsigned long long, unsigned long long>>>::_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 }
%"struct.std::pair" = type { i64, i64 }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@Seg = external dso_local global [262144 x %"class.std::multiset"], align 16
@tmp = external dso_local global %"struct.std::pair", align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %7 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %8 = icmp eq i32 %0, %2
  %9 = icmp eq i32 %1, %3
  %or.cond495561 = and i1 %8, %9
  br i1 %or.cond495561, label %tailrecurse.outer42._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %5, %tailrecurse.outer
  %10 = phi i1 [ true, %tailrecurse.outer ], [ %8, %5 ]
  %.tr41.ph65 = phi i32 [ %34, %tailrecurse.outer ], [ %4, %5 ]
  %.tr40.ph64 = phi i32 [ %.us-phi53, %tailrecurse.outer ], [ %3, %5 ]
  %.tr39.ph63 = phi i32 [ %33, %tailrecurse.outer ], [ %2, %5 ]
  %.tr.ph62 = phi i32 [ %33, %tailrecurse.outer ], [ %0, %5 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer42
  %11 = phi i1 [ %10, %.lr.ph.lr.ph ], [ %28, %tailrecurse.outer42 ]
  %.tr41.ph4558 = phi i32 [ %.tr41.ph65, %.lr.ph.lr.ph ], [ %27, %tailrecurse.outer42 ]
  %.tr40.ph4457 = phi i32 [ %.tr40.ph64, %.lr.ph.lr.ph ], [ %.us-phi53, %tailrecurse.outer42 ]
  %.tr39.ph4356 = phi i32 [ %.tr39.ph63, %.lr.ph.lr.ph ], [ %25, %tailrecurse.outer42 ]
  br i1 %11, label %.lr.ph.split, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr4151.us = phi i32 [ %14, %tailrecurse.us ], [ %.tr41.ph4558, %.lr.ph ]
  %.tr4050.us = phi i32 [ %13, %tailrecurse.us ], [ %.tr40.ph4457, %.lr.ph ]
  %12 = add i32 %.tr4050.us, %.tr39.ph4356
  %13 = ashr i32 %12, 1
  %.not.us = icmp slt i32 %13, %1
  %14 = shl i32 %.tr4151.us, 1
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer42._crit_edge:                   ; preds = %tailrecurse.outer, %tailrecurse.outer42, %tailrecurse, %5
  %.tr41.lcssa = phi i32 [ %4, %5 ], [ %22, %tailrecurse ], [ %27, %tailrecurse.outer42 ], [ %34, %tailrecurse.outer ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %15 = sext i32 %.tr41.lcssa to i64
  %16 = getelementptr inbounds [262144 x %"class.std::multiset"], ptr @Seg, i64 0, i64 %15
  %17 = tail call ptr @_ZNSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE4findERKS1_(ptr noundef nonnull align 8 dereferenceable(48) %16, ptr noundef nonnull align 8 dereferenceable(16) @tmp)
  store ptr %17, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %18 = tail call ptr @_ZNKSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %16) #3
  store ptr %18, ptr %7, align 8
  %19 = call noundef zeroext i1 @_ZStneRKSt23_Rb_tree_const_iteratorISt4pairIyyEES4_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4151 = phi i32 [ %22, %tailrecurse ], [ %.tr41.ph4558, %.lr.ph ]
  %.tr4050 = phi i32 [ %21, %tailrecurse ], [ %.tr40.ph4457, %.lr.ph ]
  %20 = add i32 %.tr4050, %.tr39.ph4356
  %21 = ashr i32 %20, 1
  %.not = icmp slt i32 %21, %1
  br i1 %.not, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %22 = shl i32 %.tr4151, 1
  %23 = icmp eq i32 %21, %1
  br i1 %23, label %tailrecurse.outer42._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split
  %.us-phi = phi i32 [ %21, %.lr.ph.split ], [ %13, %tailrecurse.us ]
  %.us-phi53 = phi i32 [ %.tr4050, %.lr.ph.split ], [ %.tr4050.us, %tailrecurse.us ]
  %.us-phi54 = phi i32 [ %.tr4151, %.lr.ph.split ], [ %.tr4151.us, %tailrecurse.us ]
  %24 = icmp slt i32 %.us-phi, %.tr.ph62
  br i1 %24, label %tailrecurse.outer42, label %30

tailrecurse.outer42:                              ; preds = %.split.us
  %25 = add nsw i32 %.us-phi, 1
  %26 = shl i32 %.us-phi54, 1
  %27 = or disjoint i32 %26, 1
  %28 = icmp eq i32 %.tr.ph62, %25
  %29 = icmp eq i32 %.us-phi53, %1
  %or.cond49 = and i1 %28, %29
  br i1 %or.cond49, label %tailrecurse.outer42._crit_edge, label %.lr.ph

30:                                               ; preds = %.split.us
  %31 = shl i32 %.us-phi54, 1
  %32 = tail call noundef zeroext i1 @_Z5queryiiiii(i32 noundef %.tr.ph62, i32 noundef %.us-phi, i32 noundef %.tr39.ph4356, i32 noundef %.us-phi, i32 noundef %31)
  br i1 %32, label %.loopexit, label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %30
  %33 = add nsw i32 %.us-phi, 1
  %34 = or disjoint i32 %31, 1
  %35 = icmp eq i32 %.us-phi53, %1
  br i1 %35, label %tailrecurse.outer42._crit_edge, label %.lr.ph.lr.ph

.loopexit:                                        ; preds = %30, %tailrecurse.outer42._crit_edge
  %.1 = phi i1 [ %19, %tailrecurse.outer42._crit_edge ], [ true, %30 ]
  ret i1 %.1
}

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

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

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

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


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