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

; 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.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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK10RingBuffer9readSpaceEv(ptr noundef nonnull align 16 dereferenceable(80)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK10RingBuffer4peekEPvm(ptr noundef nonnull align 16 dereferenceable(80) %0, ptr noundef %1, i64 noundef %2) #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %17 = call noundef i64 @_ZNK10RingBuffer9readSpaceEv(ptr noundef nonnull align 16 dereferenceable(80) %16) #6
  store i64 %17, ptr %8, align 8, !tbaa !9
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %79

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %22 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8)
          to label %23 unwind label %81

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

38:                                               ; preds = %23
  %39 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = add i64 %40, 1
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = sub i64 %41, %42
  store i64 %43, ptr %12, align 8, !tbaa !9
  %44 = load i64, ptr %14, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 3
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = and i64 %44, %46
  store i64 %47, ptr %13, align 8, !tbaa !9
  br label %50

48:                                               ; preds = %23
  %49 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %49, ptr %12, align 8, !tbaa !9
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %48, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %51 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 6
  %52 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE5beginEv(ptr noundef nonnull align 16 dereferenceable(32) %51) #6
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 4
  %55 = load i64, ptr %54, align 16, !tbaa !17
  %56 = mul i64 %53, %55
  %57 = getelementptr inbounds i8, ptr %52, i64 %56
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 4
  %60 = load i64, ptr %59, align 16, !tbaa !17
  %61 = mul i64 %58, %60
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = invoke noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef %57, i64 noundef %61, ptr noundef %62)
          to label %64 unwind label %81

64:                                               ; preds = %50
  store ptr %63, ptr %15, align 8, !tbaa !5
  %65 = load i64, ptr %13, align 8, !tbaa !9
  %66 = icmp ugt i64 %65, 0
  br i1 %66, label %67, label %77

67:                                               ; preds = %64
  %68 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 6
  %69 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE5beginEv(ptr noundef nonnull align 16 dereferenceable(32) %68) #6
  %70 = load i64, ptr %13, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.RingBuffer, ptr %16, i32 0, i32 4
  %72 = load i64, ptr %71, align 16, !tbaa !17
  %73 = mul i64 %70, %72
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = invoke noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef %69, i64 noundef %73, ptr noundef %74)
          to label %76 unwind label %81

76:                                               ; preds = %67
  br label %77

77:                                               ; preds = %76, %64
  %78 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %78, ptr %4, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %79

79:                                               ; preds = %77, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %80 = load i64, ptr %4, align 8
  ret i64 %80

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef, i64 noundef, ptr noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE5beginEv(ptr noundef nonnull align 16 dereferenceable(32)) #2 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 = { 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 = { inlinehint 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 = { 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 #5 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { 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}


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

; Function Attrs: mustprogress 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: mustprogress 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) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK10RingBuffer9readSpaceEv(ptr noundef nonnull align 16 dereferenceable(80)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

; 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 #4 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK10RingBuffer4peekEPvm(ptr noundef nonnull align 16 dereferenceable(80) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i64 %2, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  %6 = tail call noundef i64 @_ZNK10RingBuffer9readSpaceEv(ptr noundef nonnull align 16 dereferenceable(80) %0) #6
  store i64 %6, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %35, label %8

8:                                                ; preds = %3
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %11, i32 noundef 0) #6
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = and i64 %14, %12
  %16 = add i64 %15, %10
  %17 = add i64 %14, 1
  %18 = icmp ugt i64 %16, %17
  %19 = sub i64 %17, %15
  %20 = and i64 %16, %14
  %.015 = select i1 %18, i64 %19, i64 %10
  %.014 = select i1 %18, i64 %20, i64 0
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  %22 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE5beginEv(ptr noundef nonnull align 16 dereferenceable(32) %21) #6
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load i64, ptr %23, align 16, !tbaa !15
  %25 = mul i64 %24, %15
  %26 = getelementptr inbounds i8, ptr %22, i64 %25
  %27 = mul i64 %.015, %24
  %28 = invoke noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef %26, i64 noundef %27, ptr noundef %1)
          to label %29 unwind label %36

29:                                               ; preds = %8
  %.not = icmp eq i64 %.014, 0
  br i1 %.not, label %35, label %30

30:                                               ; preds = %29
  %31 = call noundef ptr @_ZNK2al9FlexArrayINS_4byteELm16EE5beginEv(ptr noundef nonnull align 16 dereferenceable(32) %21) #6
  %32 = load i64, ptr %23, align 16, !tbaa !15
  %33 = mul i64 %32, %.014
  %34 = invoke noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef %31, i64 noundef %33, ptr noundef %28)
          to label %35 unwind label %36

35:                                               ; preds = %29, %30, %3
  %.0 = phi i64 [ 0, %3 ], [ %10, %30 ], [ %10, %29 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  ret i64 %.0

36:                                               ; preds = %30, %8
  %37 = landingpad { ptr, i32 }
          catch ptr null
  %38 = extractvalue { ptr, i32 } %37, 0
  call void @__clang_call_terminate(ptr %38) #7
  unreachable
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6copy_nIPKN2al4byteEmPS1_ET1_T_T0_S5_(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #5

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

attributes #0 = { mustprogress 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 = { 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 = { inlinehint 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 = { 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 #5 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS10RingBuffer", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 48}
!11 = !{!"_ZTSSt6atomicImE", !12, i64 0}
!12 = !{!"_ZTSSt13__atomic_baseImE", !6, i64 0}
!13 = !{!"_ZTSN2al9FlexArrayINS_4byteELm16EEE", !14, i64 0}
!14 = !{!"_ZTSN2al16FlexArrayStorageINS_4byteELm16ELb1EEE", !6, i64 0, !7, i64 16}
!15 = !{!10, !6, i64 32}


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