; LLVM IR from ShahjalalShohag/code-library :: Data Structures/Segment Tree Merging.ll (Z5splitii)

; 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.STM = type { [3000270 x %"struct.STM::node"], i32, [3000270 x i32] }
%"struct.STM::node" = type { i32, i32, i32 }
%"class.std::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_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 <{ %"struct.std::_Rb_tree_const_iterator", i8, [7 x i8] }>
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@t = external dso_local global %struct.STM, align 4
@ty = external dso_local global [100009 x i8], align 16
@root = external dso_local global [100009 x i32], align 16
@rb = external dso_local global [100009 x i32], align 16
@cur = external dso_local global %"class.std::set", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splitii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %"struct.std::pair", align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp sge i32 %7, %11
  br i1 %12, label %17, label %13

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %13, %2
  br label %90

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100009 x i8], ptr @ty, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  br i1 %23, label %37, label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = add nsw i32 %35, 1
  call void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324) @t, i32 noundef %28, ptr noundef nonnull align 4 dereferenceable(4) %32, i32 noundef %36)
  br label %60

37:                                               ; preds = %18
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %52
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sub nsw i32 %57, %58
  call void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324) @t, i32 noundef %50, ptr noundef nonnull align 4 dereferenceable(4) %53, i32 noundef %59)
  br label %60

60:                                               ; preds = %37, %24
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %67
  store i32 %64, ptr %68, align 4, !tbaa !5
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !5
  %75 = call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertEOi(ptr noundef nonnull align 8 dereferenceable(48) @cur, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %76 = getelementptr inbounds { ptr, i8 }, ptr %6, i32 0, i32 0
  %77 = extractvalue { ptr, i8 } %75, 0
  store ptr %77, ptr %76, align 8
  %78 = getelementptr inbounds { ptr, i8 }, ptr %6, i32 0, i32 1
  %79 = extractvalue { ptr, i8 } %75, 1
  store i8 %79, ptr %78, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [100009 x i8], ptr @ty, i64 0, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !9, !range !11, !noundef !12
  %84 = trunc i8 %83 to i1
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100009 x i8], ptr @ty, i64 0, i64 %87
  %89 = zext i1 %84 to i8
  store i8 %89, ptr %88, align 1, !tbaa !9
  br label %90

90:                                               ; preds = %60, %17
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324), i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0 align 2

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

; 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

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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; 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.STM = type { [3000270 x %"struct.STM::node"], i32, [3000270 x i32] }
%"struct.STM::node" = type { i32, i32, i32 }
%"class.std::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>>::_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 }

@t = external dso_local global %struct.STM, align 4
@ty = external dso_local local_unnamed_addr global [100009 x i8], align 16
@root = external dso_local global [100009 x i32], align 16
@rb = external dso_local local_unnamed_addr global [100009 x i32], align 16
@cur = external dso_local global %"class.std::set", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splitii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp sle i32 %6, %1
  %7 = icmp slt i32 %1, %0
  %or.cond = or i1 %7, %.not
  br i1 %or.cond, label %27, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds [100009 x i8], ptr @ty, i64 0, i64 %4
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  %12 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %1, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100009 x i32], ptr @root, i64 0, i64 %15
  br i1 %11, label %19, label %17

17:                                               ; preds = %8
  %reass.sub = sub i32 %1, %0
  %18 = add i32 %reass.sub, 1
  tail call void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324) @t, i32 noundef %13, ptr noundef nonnull align 4 dereferenceable(4) %16, i32 noundef %18)
  br label %21

19:                                               ; preds = %8
  store i32 %13, ptr %16, align 4, !tbaa !5
  %20 = sub nsw i32 %6, %1
  tail call void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324) @t, i32 noundef %13, ptr noundef nonnull align 4 dereferenceable(4) %12, i32 noundef %20)
  br label %21

21:                                               ; preds = %19, %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = getelementptr inbounds [100009 x i32], ptr @rb, i64 0, i64 %15
  store i32 %22, ptr %23, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 %14, ptr %3, align 4, !tbaa !5
  %24 = call { ptr, i8 } @_ZNSt3setIiSt4lessIiESaIiEE6insertEOi(ptr noundef nonnull align 8 dereferenceable(48) @cur, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %25 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %26 = getelementptr inbounds [100009 x i8], ptr @ty, i64 0, i64 %15
  store i8 %25, ptr %26, align 1, !tbaa !9
  br label %27

27:                                               ; preds = %2, %21
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3STM5splitEiRii(ptr noundef nonnull align 4 dereferenceable(48004324), i32 noundef, ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0 align 2

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

; 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

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 = { 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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


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