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

; 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
@H = external dso_local global [100001 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5Buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %"struct.std::_Rb_tree_const_iterator", align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %10, ptr %7, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %25, %3
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [262144 x %"class.std::multiset"], ptr @Seg, i64 0, i64 %18
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @H, i64 0, i64 %21
  %23 = call ptr @_ZNSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(48) %19, ptr noundef nonnull align 8 dereferenceable(16) %22)
  %24 = getelementptr inbounds %"struct.std::_Rb_tree_const_iterator", ptr %8, i32 0, i32 0
  store ptr %23, ptr %24, align 8
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %7, align 4, !tbaa !5
  br label %11, !llvm.loop !9

28:                                               ; preds = %15
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  br label %48

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = ashr i32 %36, 1
  store i32 %37, ptr %9, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = shl i32 %40, 1
  call void @_Z5Buildiii(i32 noundef %38, i32 noundef %39, i32 noundef %41)
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = shl i32 %45, 1
  %47 = xor i32 %46, 1
  call void @_Z5Buildiii(i32 noundef %43, i32 noundef %44, i32 noundef %47)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %48

48:                                               ; preds = %33, %32
  ret void
}

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

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

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

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 = { 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"}


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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5Buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %1, 1
  br label %tailrecurse

tailrecurse:                                      ; preds = %12, %3
  %.tr = phi i32 [ %0, %3 ], [ %16, %12 ]
  %.tr19 = phi i32 [ %2, %3 ], [ %17, %12 ]
  %.not20 = icmp sgt i32 %.tr, %1
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse
  %5 = sext i32 %.tr19 to i64
  %6 = getelementptr inbounds [262144 x %"class.std::multiset"], ptr @Seg, i64 0, i64 %5
  %7 = sext i32 %.tr to i64
  br label %9

._crit_edge:                                      ; preds = %9, %tailrecurse
  %8 = icmp eq i32 %.tr, %1
  br i1 %8, label %18, label %12

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ %7, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %10 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @H, i64 0, i64 %indvars.iv
  %11 = tail call ptr @_ZNSt8multisetISt4pairIyyESt4lessIS1_ESaIS1_EE6insertERKS1_(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr noundef nonnull align 8 dereferenceable(16) %10)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %4, %lftr.wideiv
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !5

12:                                               ; preds = %._crit_edge
  %13 = add nsw i32 %.tr, %1
  %14 = ashr i32 %13, 1
  %15 = shl i32 %.tr19, 1
  tail call void @_Z5Buildiii(i32 noundef %.tr, i32 noundef %14, i32 noundef %15)
  %16 = add nsw i32 %14, 1
  %17 = or disjoint i32 %15, 1
  br label %tailrecurse

18:                                               ; preds = %._crit_edge
  ret void
}

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

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass