; LLVM IR from eyangch/competitive-programming :: Codeforces/1398/e.ll (Z3addx)

; 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<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<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 }
%"class.std::reverse_iterator" = type { %"struct.std::_Rb_tree_const_iterator" }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }
%"struct.std::pair" = type <{ %"struct.std::_Rb_tree_const_iterator", i8, [7 x i8] }>

@sumh = external dso_local global i64, align 8
@suml = external dso_local global i64, align 8
@low = external dso_local global %"class.std::set", align 8
@hi = external dso_local global %"class.std::set", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3balv() #0

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt3setIxSt4lessIxESaIxEE6rbeginEv(ptr dead_on_unwind noalias writable sret(%"class.std::reverse_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca %"class.std::reverse_iterator", align 8
  %4 = alloca %"struct.std::pair", align 8
  %5 = alloca %"struct.std::pair", align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %6 = call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) @low) #3
  %7 = icmp ne i64 %6, 0
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  br i1 %7, label %8, label %13

8:                                                ; preds = %1
  %9 = load i64, ptr %2, align 8, !tbaa !5
  call void @_ZNKSt3setIxSt4lessIxESaIxEE6rbeginEv(ptr dead_on_unwind writable sret(%"class.std::reverse_iterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(48) @low) #3
  %10 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorIxEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i64 %9, %11
  br label %13

13:                                               ; preds = %8, %1
  %14 = phi i1 [ false, %1 ], [ %12, %8 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br i1 %14, label %15, label %24

15:                                               ; preds = %13
  %16 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) @hi, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %17 = getelementptr inbounds { ptr, i8 }, ptr %4, i32 0, i32 0
  %18 = extractvalue { ptr, i8 } %16, 0
  store ptr %18, ptr %17, align 8
  %19 = getelementptr inbounds { ptr, i8 }, ptr %4, i32 0, i32 1
  %20 = extractvalue { ptr, i8 } %16, 1
  store i8 %20, ptr %19, align 8
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr @sumh, align 8, !tbaa !5
  %23 = add nsw i64 %22, %21
  store i64 %23, ptr @sumh, align 8, !tbaa !5
  br label %33

24:                                               ; preds = %13
  %25 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) @low, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %26 = getelementptr inbounds { ptr, i8 }, ptr %5, i32 0, i32 0
  %27 = extractvalue { ptr, i8 } %25, 0
  store ptr %27, ptr %26, align 8
  %28 = getelementptr inbounds { ptr, i8 }, ptr %5, i32 0, i32 1
  %29 = extractvalue { ptr, i8 } %25, 1
  store i8 %29, ptr %28, align 8
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = load i64, ptr @suml, align 8, !tbaa !5
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr @suml, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %24, %15
  call void @_Z3balv()
  ret void
}

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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<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 }
%"class.std::reverse_iterator" = type { %"struct.std::_Rb_tree_const_iterator" }
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@sumh = external dso_local local_unnamed_addr global i64, align 8
@suml = external dso_local local_unnamed_addr global i64, align 8
@low = external dso_local global %"class.std::set", align 8
@hi = external dso_local global %"class.std::set", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3balv() local_unnamed_addr #0

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNKSt3setIxSt4lessIxESaIxEE6rbeginEv(ptr dead_on_unwind noalias writable sret(%"class.std::reverse_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca %"class.std::reverse_iterator", align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %4 = tail call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) @low) #3
  %.not = icmp eq i64 %4, 0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  br i1 %.not, label %.critedge, label %5

5:                                                ; preds = %1
  call void @_ZNKSt3setIxSt4lessIxESaIxEE6rbeginEv(ptr dead_on_unwind nonnull writable sret(%"class.std::reverse_iterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(48) @low) #3
  %6 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt16reverse_iteratorISt23_Rb_tree_const_iteratorIxEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i64 %7, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br i1 %8, label %10, label %9

.critedge:                                        ; preds = %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %9

9:                                                ; preds = %.critedge, %5
  br label %10

10:                                               ; preds = %5, %9
  %low.sink = phi ptr [ @low, %9 ], [ @hi, %5 ]
  %suml.sink5 = phi ptr [ @suml, %9 ], [ @sumh, %5 ]
  %11 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) %low.sink, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.sink4 = load i64, ptr %2, align 8, !tbaa !5
  %12 = load i64, ptr %suml.sink5, align 8, !tbaa !5
  %13 = add nsw i64 %12, %.sink4
  store i64 %13, ptr %suml.sink5, align 8, !tbaa !5
  call void @_Z3balv()
  ret void
}

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 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass