; LLVM IR from Try/Tempest :: Engine/thirdparty/openal-soft/core/converter.ll (ZNK15SampleConverter12availableOutEj)

; 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.SampleConverter = type { i8, i8, i32, i32, i32, i32, i32, %"class.std::variant", ptr, [8 x i8], %"struct.std::array", %"struct.std::array", %"struct.al::FlexArray" }
%"class.std::variant" = type { %"struct.std::__detail::__variant::_Variant_base.base", [7 x i8] }
%"struct.std::__detail::__variant::_Variant_base.base" = type { %"struct.std::__detail::__variant::_Move_assign_base.base" }
%"struct.std::__detail::__variant::_Move_assign_base.base" = type { %"struct.std::__detail::__variant::_Copy_assign_base.base" }
%"struct.std::__detail::__variant::_Copy_assign_base.base" = type { %"struct.std::__detail::__variant::_Move_ctor_base.base" }
%"struct.std::__detail::__variant::_Move_ctor_base.base" = type { %"struct.std::__detail::__variant::_Copy_ctor_base.base" }
%"struct.std::__detail::__variant::_Copy_ctor_base.base" = type { %"struct.std::__detail::__variant::_Variant_storage.base" }
%"struct.std::__detail::__variant::_Variant_storage.base" = type <{ %"union.std::__detail::__variant::_Variadic_union", i8 }>
%"union.std::__detail::__variant::_Variadic_union" = type { %"union.std::__detail::__variant::_Variadic_union.2" }
%"union.std::__detail::__variant::_Variadic_union.2" = type { %"union.std::__detail::__variant::_Variadic_union.4" }
%"union.std::__detail::__variant::_Variadic_union.4" = type { %"struct.std::__detail::__variant::_Uninitialized.5" }
%"struct.std::__detail::__variant::_Uninitialized.5" = type { %struct.BsincState }
%struct.BsincState = type { float, i32, i32, %"class.al::span.6" }
%"class.al::span.6" = type { ptr, i64 }
%"struct.std::array" = type { [1024 x float] }
%"struct.al::FlexArray" = type { %"struct.al::FlexArrayStorage" }
%"struct.al::FlexArrayStorage" = type { %"class.al::span.8" }
%"class.al::span.8" = type { ptr, i64 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK15SampleConverter12availableOutEj(ptr noundef nonnull align 16 dereferenceable(8288) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ult i32 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %60

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = getelementptr inbounds %struct.SampleConverter, ptr %12, i32 0, i32 4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp ult i32 %19, 48
  br i1 %20, label %21, label %27

21:                                               ; preds = %16
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sub i32 48, %22
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp uge i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %59

27:                                               ; preds = %21, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  store i64 %29, ptr %8, align 8, !tbaa !26
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = load i64, ptr %8, align 8, !tbaa !26
  %33 = add i64 %32, %31
  store i64 %33, ptr %8, align 8, !tbaa !26
  %34 = load i64, ptr %8, align 8, !tbaa !26
  %35 = sub i64 %34, 48
  store i64 %35, ptr %8, align 8, !tbaa !26
  %36 = load i64, ptr %8, align 8, !tbaa !26
  %37 = shl i64 %36, 16
  store i64 %37, ptr %8, align 8, !tbaa !26
  %38 = getelementptr inbounds %struct.SampleConverter, ptr %12, i32 0, i32 5
  %39 = load i32, ptr %38, align 16, !tbaa !27
  %40 = zext i32 %39 to i64
  %41 = load i64, ptr %8, align 8, !tbaa !26
  %42 = sub i64 %41, %40
  store i64 %42, ptr %8, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %43 = load i64, ptr %8, align 8, !tbaa !26
  %44 = getelementptr inbounds %struct.SampleConverter, ptr %12, i32 0, i32 6
  %45 = load i32, ptr %44, align 4, !tbaa !28
  %46 = zext i32 %45 to i64
  %47 = add i64 %43, %46
  %48 = sub i64 %47, 1
  %49 = getelementptr inbounds %struct.SampleConverter, ptr %12, i32 0, i32 6
  %50 = load i32, ptr %49, align 4, !tbaa !28
  %51 = zext i32 %50 to i64
  %52 = udiv i64 %48, %51
  store i64 %52, ptr %9, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %53 = call noundef i64 @_Zli4_u64y(i64 noundef 1) #3
  store i64 %53, ptr %10, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %54 = call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #3
  %55 = sext i32 %54 to i64
  store i64 %55, ptr %11, align 8, !tbaa !26
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt5clampImERKT_S2_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %57 = load i64, ptr %56, align 8, !tbaa !26
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %59

59:                                               ; preds = %27, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %60

60:                                               ; preds = %59, %15
  %61 = load i32, ptr %3, align 4
  ret i32 %61
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt5clampImERKT_S2_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Zli4_u64y(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !10, i64 12}
!12 = !{!"_ZTS15SampleConverter", !13, i64 0, !13, i64 1, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !14, i64 24, !6, i64 64, !21, i64 80, !21, i64 4176, !22, i64 8272}
!13 = !{!"_ZTS10DevFmtType", !7, i64 0}
!14 = !{!"_ZTSSt7variantIJSt9monostate10CubicState10BsincStateEE", !15, i64 0}
!15 = !{!"_ZTSNSt8__detail9__variant13_Variant_baseIJSt9monostate10CubicState10BsincStateEEE", !16, i64 0}
!16 = !{!"_ZTSNSt8__detail9__variant17_Move_assign_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !17, i64 0}
!17 = !{!"_ZTSNSt8__detail9__variant17_Copy_assign_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !18, i64 0}
!18 = !{!"_ZTSNSt8__detail9__variant15_Move_ctor_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !19, i64 0}
!19 = !{!"_ZTSNSt8__detail9__variant15_Copy_ctor_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !20, i64 0}
!20 = !{!"_ZTSNSt8__detail9__variant16_Variant_storageILb1EJSt9monostate10CubicState10BsincStateEEE", !7, i64 0, !7, i64 32}
!21 = !{!"_ZTSSt5arrayIfLm1024EE", !7, i64 0}
!22 = !{!"_ZTSN2al9FlexArrayIN15SampleConverter11ChanSamplesELm16EEE", !23, i64 0}
!23 = !{!"_ZTSN2al16FlexArrayStorageIN15SampleConverter11ChanSamplesELm16ELb1EEE", !24, i64 0}
!24 = !{!"_ZTSN2al4spanIN15SampleConverter11ChanSamplesELm18446744073709551615EEE", !6, i64 0, !25, i64 8}
!25 = !{!"long", !7, i64 0}
!26 = !{!25, !25, i64 0}
!27 = !{!12, !10, i64 16}
!28 = !{!12, !10, i64 20}


; 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK15SampleConverter12availableOutEj(ptr nocapture noundef nonnull readonly align 16 dereferenceable(8288) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = icmp eq i32 %1, 0
  br i1 %6, label %33, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp ugt i32 %9, 47
  %11 = sub nuw nsw i32 48, %9
  %.not = icmp ult i32 %11, %1
  %or.cond = select i1 %10, i1 true, i1 %.not
  br i1 %or.cond, label %12, label %33

12:                                               ; preds = %7
  %13 = zext i32 %9 to i64
  %14 = zext i32 %1 to i64
  %15 = add nuw nsw i64 %13, %14
  %16 = shl nuw nsw i64 %15, 16
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i32, ptr %17, align 16, !tbaa !24
  %19 = zext i32 %18 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 20
  %21 = load i32, ptr %20, align 4, !tbaa !25
  %22 = zext i32 %21 to i64
  %23 = add nsw i64 %16, -3145729
  %24 = sub nsw i64 %23, %19
  %25 = add nsw i64 %24, %22
  %26 = udiv i64 %25, %22
  store i64 %26, ptr %3, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %27 = tail call noundef i64 @_Zli4_u64y(i64 noundef 1) #3
  store i64 %27, ptr %4, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %28 = tail call noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() #3
  %29 = sext i32 %28 to i64
  store i64 %29, ptr %5, align 8, !tbaa !26
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt5clampImERKT_S2_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %31 = load i64, ptr %30, align 8, !tbaa !26
  %32 = trunc i64 %31 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %33

33:                                               ; preds = %12, %7, %2
  %.1 = phi i32 [ 0, %2 ], [ %32, %12 ], [ 0, %7 ]
  ret i32 %.1
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Zli4_u64y(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt14numeric_limitsIiE3maxEv() local_unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 12}
!6 = !{!"_ZTS15SampleConverter", !7, i64 0, !7, i64 1, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24, !18, i64 64, !19, i64 80, !19, i64 4176, !20, i64 8272}
!7 = !{!"_ZTS10DevFmtType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSSt7variantIJSt9monostate10CubicState10BsincStateEE", !12, i64 0}
!12 = !{!"_ZTSNSt8__detail9__variant13_Variant_baseIJSt9monostate10CubicState10BsincStateEEE", !13, i64 0}
!13 = !{!"_ZTSNSt8__detail9__variant17_Move_assign_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !14, i64 0}
!14 = !{!"_ZTSNSt8__detail9__variant17_Copy_assign_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !15, i64 0}
!15 = !{!"_ZTSNSt8__detail9__variant15_Move_ctor_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !16, i64 0}
!16 = !{!"_ZTSNSt8__detail9__variant15_Copy_ctor_baseILb1EJSt9monostate10CubicState10BsincStateEEE", !17, i64 0}
!17 = !{!"_ZTSNSt8__detail9__variant16_Variant_storageILb1EJSt9monostate10CubicState10BsincStateEEE", !8, i64 0, !8, i64 32}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{!"_ZTSSt5arrayIfLm1024EE", !8, i64 0}
!20 = !{!"_ZTSN2al9FlexArrayIN15SampleConverter11ChanSamplesELm16EEE", !21, i64 0}
!21 = !{!"_ZTSN2al16FlexArrayStorageIN15SampleConverter11ChanSamplesELm16ELb1EEE", !22, i64 0}
!22 = !{!"_ZTSN2al4spanIN15SampleConverter11ChanSamplesELm18446744073709551615EEE", !18, i64 0, !23, i64 8}
!23 = !{!"long", !8, i64 0}
!24 = !{!6, !10, i64 16}
!25 = !{!6, !10, i64 20}
!26 = !{!23, !23, i64 0}


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