; LLVM IR from kacperks/Fractal_Engine :: Engine/Thirdparty/cmake/Engine/Thirdparty/cmake/openal-soft/common/ringbuffer_f0300f69 (ZNK10RingBuffer13getReadVectorEv)

; 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.std::pair" = type { %struct.ll_ringbuffer_data, %struct.ll_ringbuffer_data }
%struct.ll_ringbuffer_data = type { ptr, i64 }
%struct.RingBuffer = type { %"struct.std::atomic", %"struct.std::atomic", i64, i64, i64, [8 x i8], %"struct.al::FlexArray" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i64 }
%"struct.al::FlexArray" = type { %"struct.al::FlexArrayStorage" }
%"struct.al::FlexArrayStorage" = type { i64, [8 x i8], %union.anon.2 }
%union.anon.2 = type { i8, [15 x i8] }

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK10RingBuffer13getReadVectorEv(ptr dead_on_unwind noalias writable sret(%"struct.std::pair") align 8 %0, ptr noundef nonnull align 16 dereferenceable(80) %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  invoke void @_ZNSt4pairI18ll_ringbuffer_dataS0_EC2IS0_S0_TnNSt9enable_ifIXsr6__and_ISt37__is_implicitly_default_constructibleIT_ES4_IT0_EEE5valueEbE4typeELb1EEEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
          to label %9 unwind label %81

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 0
  %11 = call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef 2) #4
  store i64 %11, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 1
  %13 = call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %12, i32 noundef 2) #4
  store i64 %13, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = and i64 %16, %15
  store i64 %17, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = and i64 %20, %19
  store i64 %21, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = sub i64 %22, %23
  %25 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = and i64 %24, %26
  store i64 %27, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = add i64 %28, %29
  store i64 %30, ptr %7, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = add i64 %33, 1
  %35 = icmp ugt i64 %31, %34
  br i1 %35, label %36, label %63

36:                                               ; preds = %9
  %37 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %38 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %37) #4
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 4
  %41 = load i64, ptr %40, align 16, !tbaa !17
  %42 = mul i64 %39, %41
  %43 = getelementptr inbounds i8, ptr %38, i64 %42
  %44 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %45 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %44, i32 0, i32 0
  store ptr %43, ptr %45, align 8, !tbaa !18
  %46 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !11
  %48 = add i64 %47, 1
  %49 = load i64, ptr %5, align 8, !tbaa !9
  %50 = sub i64 %48, %49
  %51 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %52 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %51, i32 0, i32 1
  store i64 %50, ptr %52, align 8, !tbaa !21
  %53 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %54 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %53) #4
  %55 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %56 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %55, i32 0, i32 0
  store ptr %54, ptr %56, align 8, !tbaa !22
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !11
  %60 = and i64 %57, %59
  %61 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %62 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %61, i32 0, i32 1
  store i64 %60, ptr %62, align 8, !tbaa !23
  br label %80

63:                                               ; preds = %9
  %64 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %65 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %64) #4
  %66 = load i64, ptr %5, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 4
  %68 = load i64, ptr %67, align 16, !tbaa !17
  %69 = mul i64 %66, %68
  %70 = getelementptr inbounds i8, ptr %65, i64 %69
  %71 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %72 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %71, i32 0, i32 0
  store ptr %70, ptr %72, align 8, !tbaa !18
  %73 = load i64, ptr %6, align 8, !tbaa !9
  %74 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %75 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %74, i32 0, i32 1
  store i64 %73, ptr %75, align 8, !tbaa !21
  %76 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %77 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %76, i32 0, i32 0
  store ptr null, ptr %77, align 8, !tbaa !22
  %78 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %79 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %78, i32 0, i32 1
  store i64 0, ptr %79, align 8, !tbaa !23
  br label %80

80:                                               ; preds = %63, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  ret void

81:                                               ; preds = %2
  %82 = landingpad { ptr, i32 }
          catch ptr null
  %83 = extractvalue { ptr, i32 } %82, 0
  call void @__clang_call_terminate(ptr %83) #5
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn nounwind uwtable "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 = { alwaysinline 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 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS10RingBuffer", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !15, i64 48}
!13 = !{!"_ZTSSt6atomicImE", !14, i64 0}
!14 = !{!"_ZTSSt13__atomic_baseImE", !10, i64 0}
!15 = !{!"_ZTSN2al9FlexArrayINS_4byteELm16EEE", !16, i64 0}
!16 = !{!"_ZTSN2al16FlexArrayStorageINS_4byteELm16ELb1EEE", !10, i64 0, !7, i64 16}
!17 = !{!12, !10, i64 32}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSSt4pairI18ll_ringbuffer_dataS0_E", !20, i64 0, !20, i64 16}
!20 = !{!"_ZTS18ll_ringbuffer_data", !6, i64 0, !10, i64 8}
!21 = !{!19, !10, i64 8}
!22 = !{!19, !6, i64 16}
!23 = !{!19, !10, i64 24}


; 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.std::pair" = type { %struct.ll_ringbuffer_data, %struct.ll_ringbuffer_data }
%struct.ll_ringbuffer_data = type { ptr, i64 }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK10RingBuffer13getReadVectorEv(ptr dead_on_unwind noalias nonnull writable sret(%"struct.std::pair") align 8 %0, ptr noundef nonnull align 16 dereferenceable(80) %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZNSt4pairI18ll_ringbuffer_dataS0_EC2IS0_S0_TnNSt9enable_ifIXsr6__and_ISt37__is_implicitly_default_constructibleIT_ES4_IT0_EEE5valueEbE4typeELb1EEEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %3 = tail call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 2) #2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = tail call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef 2) #2
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = and i64 %7, %3
  %9 = and i64 %7, %5
  %10 = sub i64 %8, %9
  %11 = and i64 %10, %7
  %12 = add i64 %11, %9
  %13 = add i64 %7, 1
  %14 = icmp ugt i64 %12, %13
  %15 = getelementptr inbounds i8, ptr %1, i64 48
  %16 = tail call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %15) #2
  %17 = getelementptr inbounds i8, ptr %1, i64 32
  %18 = load i64, ptr %17, align 16, !tbaa !14
  %19 = mul i64 %18, %9
  %20 = getelementptr inbounds i8, ptr %16, i64 %19
  store ptr %20, ptr %0, align 8, !tbaa !15
  br i1 %14, label %21, label %28

21:                                               ; preds = %2
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %reass.sub = sub i64 %22, %9
  %23 = add i64 %reass.sub, 1
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %23, ptr %24, align 8, !tbaa !19
  %25 = tail call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %15) #2
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = and i64 %26, %12
  br label %30

28:                                               ; preds = %2
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %11, ptr %29, align 8, !tbaa !19
  br label %30

30:                                               ; preds = %28, %21
  %.sink12 = phi ptr [ %25, %21 ], [ null, %28 ]
  %.sink = phi i64 [ %27, %21 ], [ 0, %28 ]
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %.sink12, ptr %31, align 8
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %.sink, ptr %32, align 8
  ret void
}

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

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

attributes #0 = { alwaysinline 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 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 = { 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, !9, i64 24}
!6 = !{!"_ZTS10RingBuffer", !7, i64 0, !7, i64 8, !9, i64 16, !9, i64 24, !9, i64 32, !12, i64 48}
!7 = !{!"_ZTSSt6atomicImE", !8, i64 0}
!8 = !{!"_ZTSSt13__atomic_baseImE", !9, i64 0}
!9 = !{!"long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN2al9FlexArrayINS_4byteELm16EEE", !13, i64 0}
!13 = !{!"_ZTSN2al16FlexArrayStorageINS_4byteELm16ELb1EEE", !9, i64 0, !10, i64 16}
!14 = !{!6, !9, i64 32}
!15 = !{!16, !18, i64 0}
!16 = !{!"_ZTSSt4pairI18ll_ringbuffer_dataS0_E", !17, i64 0, !17, i64 16}
!17 = !{!"_ZTS18ll_ringbuffer_data", !18, i64 0, !9, i64 8}
!18 = !{!"any pointer", !10, i64 0}
!19 = !{!16, !9, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass