; LLVM IR from kdrag0n/fxdsp :: external/oboe/src/common (StabilizedCallback)

; 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.oboe::StabilizedCallback" = type { %"class.oboe::AudioStreamCallback", ptr, i64, i64, double }
%"class.oboe::AudioStreamCallback" = type { %"class.oboe::AudioStreamDataCallback", %"class.oboe::AudioStreamErrorCallback" }
%"class.oboe::AudioStreamDataCallback" = type { ptr }
%"class.oboe::AudioStreamErrorCallback" = type { ptr }

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4oboe18StabilizedCallback12onAudioReadyEPNS_11AudioStreamEPvi(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %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 i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %19 = call noundef i64 @_ZN4oboe10AudioClock14getNanosecondsEi(i32 noundef 1)
  store i64 %19, ptr %9, align 8, !tbaa !11
  %20 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %4
  %24 = load i64, ptr %9, align 8, !tbaa !11
  %25 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 3
  store i64 %24, ptr %25, align 8, !tbaa !19
  br label %26

26:                                               ; preds = %23, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %27 = load i64, ptr %9, align 8, !tbaa !11
  %28 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %30 = sub nsw i64 %27, %29
  store i64 %30, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %31 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = mul nsw i64 %32, 1000000000
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call noundef i32 @_ZNK4oboe15AudioStreamBase13getSampleRateEv(ptr noundef nonnull align 8 dereferenceable(152) %34)
  %36 = sext i32 %35 to i64
  %37 = sdiv i64 %33, %36
  store i64 %37, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %38 = load i64, ptr %10, align 8, !tbaa !11
  %39 = load i64, ptr %11, align 8, !tbaa !11
  %40 = sub nsw i64 %38, %39
  store i64 %40, ptr %12, align 8, !tbaa !11
  %41 = load i64, ptr %12, align 8, !tbaa !11
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %26
  %44 = load i64, ptr %9, align 8, !tbaa !11
  %45 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 3
  store i64 %44, ptr %45, align 8, !tbaa !19
  %46 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 2
  store i64 0, ptr %46, align 8, !tbaa !13
  br label %47

47:                                               ; preds = %43, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %49, 1000000000
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call noundef i32 @_ZNK4oboe15AudioStreamBase13getSampleRateEv(ptr noundef nonnull align 8 dereferenceable(152) %51)
  %53 = sext i32 %52 to i64
  %54 = sdiv i64 %50, %53
  store i64 %54, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %55 = load i64, ptr %13, align 8, !tbaa !11
  %56 = sitofp i64 %55 to float
  %57 = load i64, ptr %12, align 8, !tbaa !11
  %58 = sitofp i64 %57 to float
  %59 = fneg float %58
  %60 = call float @llvm.fmuladd.f32(float %56, float 0x3FE99999A0000000, float %59)
  %61 = fptosi float %60 to i64
  store i64 %61, ptr %14, align 8, !tbaa !11
  call void (ptr, ...) @_ZN5Trace12beginSectionEPKcz(ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %62 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load ptr, ptr %63, align 8, !tbaa !21
  %68 = getelementptr inbounds ptr, ptr %67, i64 2
  %69 = load ptr, ptr %68, align 8
  %70 = call noundef i32 %69(ptr noundef nonnull align 8 dereferenceable(8) %63, ptr noundef %64, ptr noundef %65, i32 noundef %66)
  store i32 %70, ptr %15, align 4, !tbaa !23
  call void @_ZN5Trace10endSectionEv()
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %71 = call noundef i64 @_ZN4oboe10AudioClock14getNanosecondsEi(i32 noundef 1)
  %72 = load i64, ptr %9, align 8, !tbaa !11
  %73 = sub nsw i64 %71, %72
  store i64 %73, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %74 = load i64, ptr %14, align 8, !tbaa !11
  %75 = load i64, ptr %16, align 8, !tbaa !11
  %76 = sub nsw i64 %74, %75
  store i64 %76, ptr %17, align 8, !tbaa !11
  %77 = load i64, ptr %17, align 8, !tbaa !11
  call void (ptr, ...) @_ZN5Trace12beginSectionEPKcz(ptr noundef @.str.1, i64 noundef %77)
  %78 = load i64, ptr %17, align 8, !tbaa !11
  call void @_ZN4oboe18StabilizedCallback12generateLoadEl(ptr noundef nonnull align 8 dereferenceable(48) %18, i64 noundef %78)
  call void @_ZN5Trace10endSectionEv()
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %"class.oboe::StabilizedCallback", ptr %18, i32 0, i32 2
  %82 = load i64, ptr %81, align 8, !tbaa !13
  %83 = add nsw i64 %82, %80
  store i64 %83, ptr %81, align 8, !tbaa !13
  %84 = load i32, ptr %15, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret i32 %84
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

declare void @_ZN5Trace12beginSectionEPKcz(ptr noundef, ...) #4

declare void @_ZN5Trace10endSectionEv() #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4oboe18StabilizedCallback12generateLoadEl(ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { "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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"_ZTSN4oboe18StabilizedCallbackE", !15, i64 0, !6, i64 16, !12, i64 24, !12, i64 32, !18, i64 40}
!15 = !{!"_ZTSN4oboe19AudioStreamCallbackE", !16, i64 0, !17, i64 8}
!16 = !{!"_ZTSN4oboe23AudioStreamDataCallbackE"}
!17 = !{!"_ZTSN4oboe24AudioStreamErrorCallbackE"}
!18 = !{!"double", !7, i64 0}
!19 = !{!14, !12, i64 32}
!20 = !{!14, !6, i64 16}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"_ZTSN4oboe18DataCallbackResultE", !7, i64 0}


; 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 [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4oboe18StabilizedCallback12onAudioReadyEPNS_11AudioStreamEPvi(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = tail call noundef i64 @_ZN4oboe10AudioClock14getNanosecondsEi(i32 noundef 1)
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %8, label %10, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.pre = load i64, ptr %9, align 8, !tbaa !15
  br label %11

10:                                               ; preds = %4
  store i64 %5, ptr %9, align 8, !tbaa !15
  br label %11

11:                                               ; preds = %._crit_edge, %10
  %12 = phi i64 [ %.pre, %._crit_edge ], [ %5, %10 ]
  %13 = mul nsw i64 %7, 1000000000
  %14 = tail call noundef i32 @_ZNK4oboe15AudioStreamBase13getSampleRateEv(ptr noundef nonnull align 8 dereferenceable(152) %1)
  %15 = sext i32 %14 to i64
  %16 = sdiv i64 %13, %15
  %17 = add i64 %12, %16
  %18 = sub i64 %5, %17
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %11
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %5, ptr %21, align 8, !tbaa !15
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %20, %11
  %23 = sext i32 %3 to i64
  %24 = mul nsw i64 %23, 1000000000
  %25 = tail call noundef i32 @_ZNK4oboe15AudioStreamBase13getSampleRateEv(ptr noundef nonnull align 8 dereferenceable(152) %1)
  %26 = sext i32 %25 to i64
  %27 = sdiv i64 %24, %26
  %28 = sitofp i64 %27 to float
  %29 = sitofp i64 %18 to float
  %30 = fneg float %29
  %31 = tail call float @llvm.fmuladd.f32(float %28, float 0x3FE99999A0000000, float %30)
  %32 = fptosi float %31 to i64
  tail call void (ptr, ...) @_ZN5Trace12beginSectionEPKcz(ptr noundef nonnull @.str)
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %37 = load ptr, ptr %36, align 8
  %38 = tail call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(8) %34, ptr noundef nonnull %1, ptr noundef %2, i32 noundef %3)
  tail call void @_ZN5Trace10endSectionEv()
  %39 = tail call noundef i64 @_ZN4oboe10AudioClock14getNanosecondsEi(i32 noundef 1)
  %.neg = sub i64 %5, %39
  %40 = add i64 %.neg, %32
  tail call void (ptr, ...) @_ZN5Trace12beginSectionEPKcz(ptr noundef nonnull @.str.1, i64 noundef %40)
  tail call void @_ZN4oboe18StabilizedCallback12generateLoadEl(ptr noundef nonnull align 8 dereferenceable(48) %0, i64 noundef %40)
  tail call void @_ZN5Trace10endSectionEv()
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = add nsw i64 %41, %23
  store i64 %42, ptr %6, align 8, !tbaa !5
  ret i32 %38
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4oboe15AudioStreamBase13getSampleRateEv(ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

declare void @_ZN5Trace12beginSectionEPKcz(ptr noundef, ...) local_unnamed_addr #3

declare void @_ZN5Trace10endSectionEv() local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4oboe18StabilizedCallback12generateLoadEl(ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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" }

!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, !13, i64 24}
!6 = !{!"_ZTSN4oboe18StabilizedCallbackE", !7, i64 0, !10, i64 16, !13, i64 24, !13, i64 32, !14, i64 40}
!7 = !{!"_ZTSN4oboe19AudioStreamCallbackE", !8, i64 0, !9, i64 8}
!8 = !{!"_ZTSN4oboe23AudioStreamDataCallbackE"}
!9 = !{!"_ZTSN4oboe24AudioStreamErrorCallbackE"}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"double", !11, i64 0}
!15 = !{!6, !13, i64 32}
!16 = !{!6, !10, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !12, i64 0}


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