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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK10RingBuffer14getWriteVectorEv(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 %88

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
  %14 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 2
  %15 = load i64, ptr %14, align 16, !tbaa !11
  %16 = add i64 %13, %15
  %17 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %19 = sub i64 %16, %18
  store i64 %19, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = and i64 %22, %21
  store i64 %23, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !17
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = and i64 %26, %25
  store i64 %27, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = sub i64 %28, %29
  %31 = sub i64 %30, 1
  %32 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = and i64 %31, %33
  store i64 %34, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = add i64 %35, %36
  store i64 %37, ptr %7, align 8, !tbaa !9
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = add i64 %40, 1
  %42 = icmp ugt i64 %38, %41
  br i1 %42, label %43, label %70

43:                                               ; preds = %9
  %44 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %45 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %44) #4
  %46 = load i64, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 4
  %48 = load i64, ptr %47, align 16, !tbaa !18
  %49 = mul i64 %46, %48
  %50 = getelementptr inbounds i8, ptr %45, i64 %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 0
  store ptr %50, ptr %52, align 8, !tbaa !19
  %53 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !17
  %55 = add i64 %54, 1
  %56 = load i64, ptr %4, align 8, !tbaa !9
  %57 = sub i64 %55, %56
  %58 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %59 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %58, i32 0, i32 1
  store i64 %57, ptr %59, align 8, !tbaa !22
  %60 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %61 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %60) #4
  %62 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %63 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %62, i32 0, i32 0
  store ptr %61, ptr %63, align 8, !tbaa !23
  %64 = load i64, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 3
  %66 = load i64, ptr %65, align 8, !tbaa !17
  %67 = and i64 %64, %66
  %68 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %69 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %68, i32 0, i32 1
  store i64 %67, ptr %69, align 8, !tbaa !24
  br label %87

70:                                               ; preds = %9
  %71 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 6
  %72 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %71) #4
  %73 = load i64, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.RingBuffer, ptr %8, i32 0, i32 4
  %75 = load i64, ptr %74, align 16, !tbaa !18
  %76 = mul i64 %73, %75
  %77 = getelementptr inbounds i8, ptr %72, i64 %76
  %78 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %79 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %78, i32 0, i32 0
  store ptr %77, ptr %79, align 8, !tbaa !19
  %80 = load i64, ptr %6, align 8, !tbaa !9
  %81 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 0
  %82 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %81, i32 0, i32 1
  store i64 %80, ptr %82, align 8, !tbaa !22
  %83 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %84 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %83, i32 0, i32 0
  store ptr null, ptr %84, align 8, !tbaa !23
  %85 = getelementptr inbounds %"struct.std::pair", ptr %0, i32 0, i32 1
  %86 = getelementptr inbounds %struct.ll_ringbuffer_data, ptr %85, i32 0, i32 1
  store i64 0, ptr %86, align 8, !tbaa !24
  br label %87

87:                                               ; preds = %70, %43
  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

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

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 16}
!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 24}
!18 = !{!12, !10, i64 32}
!19 = !{!20, !6, i64 0}
!20 = !{!"_ZTSSt4pairI18ll_ringbuffer_dataS0_E", !21, i64 0, !21, i64 16}
!21 = !{!"_ZTS18ll_ringbuffer_data", !6, i64 0, !10, i64 8}
!22 = !{!20, !10, i64 8}
!23 = !{!20, !6, i64 16}
!24 = !{!20, !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
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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK10RingBuffer14getWriteVectorEv(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 16
  %7 = load i64, ptr %6, align 16, !tbaa !5
  %8 = add i64 %7, %5
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !14
  %11 = sub i64 %8, %10
  %12 = and i64 %10, %3
  %13 = and i64 %11, %10
  %14 = xor i64 %12, -1
  %15 = add i64 %13, %14
  %16 = and i64 %15, %10
  %17 = add i64 %16, %12
  %18 = add i64 %10, 1
  %19 = icmp ugt i64 %17, %18
  %20 = getelementptr inbounds i8, ptr %1, i64 48
  %21 = tail call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %20) #2
  %22 = getelementptr inbounds i8, ptr %1, i64 32
  %23 = load i64, ptr %22, align 16, !tbaa !15
  %24 = mul i64 %23, %12
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  store ptr %25, ptr %0, align 8, !tbaa !16
  br i1 %19, label %26, label %33

26:                                               ; preds = %2
  %27 = load i64, ptr %9, align 8, !tbaa !14
  %reass.sub = sub i64 %27, %12
  %28 = add i64 %reass.sub, 1
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %28, ptr %29, align 8, !tbaa !20
  %30 = tail call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE4dataEv(ptr noundef nonnull align 16 dereferenceable(32) %20) #2
  %31 = load i64, ptr %9, align 8, !tbaa !14
  %32 = and i64 %31, %17
  br label %35

33:                                               ; preds = %2
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %16, ptr %34, align 8, !tbaa !20
  br label %35

35:                                               ; preds = %33, %26
  %.sink13 = phi ptr [ %30, %26 ], [ null, %33 ]
  %.sink = phi i64 [ %32, %26 ], [ 0, %33 ]
  %36 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %.sink13, ptr %36, align 8
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %.sink, ptr %37, align 8
  ret void
}

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 16}
!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 24}
!15 = !{!6, !9, i64 32}
!16 = !{!17, !19, i64 0}
!17 = !{!"_ZTSSt4pairI18ll_ringbuffer_dataS0_E", !18, i64 0, !18, i64 16}
!18 = !{!"_ZTS18ll_ringbuffer_data", !19, i64 0, !9, i64 8}
!19 = !{!"any pointer", !10, i64 0}
!20 = !{!17, !9, i64 8}


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