; LLVM IR from pixelsdb/mini-pixels :: pixels-common/lib/physical/natives/ByteBuffer.ll (ZN10ByteBufferC2ERS_jj)

; 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.ByteBuffer = type <{ i32, i32, ptr, i32, [4 x i8], %"class.std::__cxx11::basic_string", i32, i8, i8, [2 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [104 x i8], align 1
@__PRETTY_FUNCTION__._ZN10ByteBufferC2ERS_jj = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10ByteBuffer13resetPositionEv(ptr noundef nonnull align 8 dereferenceable(62)) #0 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10ByteBufferC2ERS_jj(ptr noundef nonnull align 8 dereferenceable(62) %0, ptr noundef nonnull align 8 dereferenceable(62) %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 5
  call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %12) #3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp uge i32 %13, 0
  br i1 %14, label %15, label %26

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = add i32 %16, %17
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = invoke noundef i32 @_ZN10ByteBuffer4sizeEv(ptr noundef nonnull align 8 dereferenceable(62) %19)
          to label %21 unwind label %30

21:                                               ; preds = %15
  %22 = icmp ule i32 %18, %20
  br i1 %22, label %23, label %26

23:                                               ; preds = %21
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp ugt i32 %24, 0
  br label %26

26:                                               ; preds = %23, %21, %4
  %27 = phi i1 [ false, %21 ], [ false, %4 ], [ %25, %23 ]
  br i1 %27, label %28, label %29

28:                                               ; preds = %26
  br label %35

29:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 60, ptr noundef @__PRETTY_FUNCTION__._ZN10ByteBufferC2ERS_jj) #4
  unreachable

30:                                               ; preds = %45, %38, %35, %15
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %9, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %10, align 4
  call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %12) #3
  br label %51

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %28
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = invoke noundef ptr @_ZN10ByteBuffer10getPointerEv(ptr noundef nonnull align 8 dereferenceable(62) %36)
          to label %38 unwind label %30

38:                                               ; preds = %35
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %37, i64 %40
  %42 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 2
  store ptr %41, ptr %42, align 8, !tbaa !11
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 3
  store i32 %43, ptr %44, align 8, !tbaa !17
  invoke void @_ZN10ByteBuffer13resetPositionEv(ptr noundef nonnull align 8 dereferenceable(62) %11)
          to label %45 unwind label %30

45:                                               ; preds = %38
  %46 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 5
  %47 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %46, ptr noundef @.str)
          to label %48 unwind label %30

48:                                               ; preds = %45
  %49 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 7
  store i8 1, ptr %49, align 4, !tbaa !18
  %50 = getelementptr inbounds %class.ByteBuffer, ptr %11, i32 0, i32 8
  store i8 1, ptr %50, align 1, !tbaa !19
  ret void

51:                                               ; preds = %30
  %52 = load ptr, ptr %9, align 8
  %53 = load i32, ptr %10, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10ByteBuffer4sizeEv(ptr noundef nonnull align 8 dereferenceable(62)) #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

attributes #0 = { 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 #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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS10ByteBuffer", !10, i64 0, !10, i64 4, !6, i64 8, !10, i64 16, !13, i64 24, !10, i64 56, !16, i64 60, !16, i64 61}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !16, i64 60}
!19 = !{!12, !16, i64 61}


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

@.str = external hidden unnamed_addr constant [1 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [104 x i8], align 1
@__PRETTY_FUNCTION__._ZN10ByteBufferC2ERS_jj = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10ByteBuffer13resetPositionEv(ptr noundef nonnull align 8 dereferenceable(62)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10ByteBufferC2ERS_jj(ptr noundef nonnull align 8 dereferenceable(62) %0, ptr noundef nonnull align 8 dereferenceable(62) %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #3
  %6 = add i32 %3, %2
  %7 = tail call noundef i32 @_ZN10ByteBuffer4sizeEv(ptr noundef nonnull align 8 dereferenceable(62) %1)
  %8 = icmp ule i32 %6, %7
  %9 = icmp ne i32 %3, 0
  %or.cond = and i1 %9, %8
  br i1 %or.cond, label %12, label %.critedge

.critedge:                                        ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 60, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN10ByteBufferC2ERS_jj) #4
  unreachable

10:                                               ; preds = %12
  %11 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #3
  resume { ptr, i32 } %11

12:                                               ; preds = %4
  %13 = tail call noundef ptr @_ZN10ByteBuffer10getPointerEv(ptr noundef nonnull align 8 dereferenceable(62) %1)
  %14 = zext i32 %2 to i64
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %3, ptr %17, align 8, !tbaa !15
  tail call void @_ZN10ByteBuffer13resetPositionEv(ptr noundef nonnull align 8 dereferenceable(62) %0)
  %18 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull @.str)
          to label %19 unwind label %10

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %0, i64 60
  store i8 1, ptr %20, align 4, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 61
  store i8 1, ptr %21, align 1, !tbaa !17
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10ByteBuffer4sizeEv(ptr noundef nonnull align 8 dereferenceable(62)) local_unnamed_addr #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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, !10, i64 8}
!6 = !{!"_ZTS10ByteBuffer", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !11, i64 24, !7, i64 56, !14, i64 60, !14, i64 61}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !7, i64 16}
!16 = !{!6, !14, i64 60}
!17 = !{!6, !14, i64 61}


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