; LLVM IR from glaretechnologies/substrata :: rtaudio/RtAudio.ll (ZN5RtApi16getStreamLatencyEv)

; 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.RtApi = type { ptr, %"class.std::__cxx11::basic_ostringstream", %"class.std::__cxx11::basic_string", %"class.std::function", i8, %"class.std::vector.3", i32, %"struct.RtApi::RtApiStream" }
%"class.std::__cxx11::basic_ostringstream" = type { %"class.std::basic_ostream.base", %"class.std::__cxx11::basic_stringbuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::__cxx11::basic_stringbuf" = type { %"class.std::basic_streambuf", i32, %"class.std::__cxx11::basic_string" }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<RtAudio::DeviceInfo, std::allocator<RtAudio::DeviceInfo>>::_Vector_impl" }
%"struct.std::_Vector_base<RtAudio::DeviceInfo, std::allocator<RtAudio::DeviceInfo>>::_Vector_impl" = type { %"struct.std::_Vector_base<RtAudio::DeviceInfo, std::allocator<RtAudio::DeviceInfo>>::_Vector_impl_data" }
%"struct.std::_Vector_base<RtAudio::DeviceInfo, std::allocator<RtAudio::DeviceInfo>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.RtApi::RtApiStream" = type { [2 x i32], ptr, i32, i32, [2 x ptr], ptr, [2 x i8], i8, [2 x i8], [2 x i8], i32, i32, i32, [2 x i32], [2 x i32], [2 x i32], [2 x i64], i64, [2 x i64], %union.pthread_mutex_t, %struct.CallbackInfo, [2 x %"struct.RtApi::ConvertInfo"], double }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.CallbackInfo = type <{ ptr, i64, ptr, ptr, ptr, i8, i8, [2 x i8], i32, i8, [7 x i8] }>
%"struct.RtApi::ConvertInfo" = type { i32, i32, i32, i64, i64, %"class.std::vector.8", %"class.std::vector.8" }
%"class.std::vector.8" = type { %"struct.std::_Vector_base.9" }
%"struct.std::_Vector_base.9" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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 nounwind uwtable
define dso_local noundef i64 @_ZN5RtApi16getStreamLatencyEv(ptr noundef nonnull align 8 dereferenceable(888) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %6 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %14, label %9

9:                                                ; preds = %1
  %10 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %11 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %14, label %19

14:                                               ; preds = %9, %1
  %15 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %16 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %15, i32 0, i32 16
  %17 = getelementptr inbounds [2 x i64], ptr %16, i64 0, i64 0
  %18 = load i64, ptr %17, align 8, !tbaa !9
  store i64 %18, ptr %3, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %14, %9
  %20 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %21 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %29, label %24

24:                                               ; preds = %19
  %25 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %26 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp eq i32 %27, 2
  br i1 %28, label %29, label %36

29:                                               ; preds = %24, %19
  %30 = getelementptr inbounds %class.RtApi, ptr %4, i32 0, i32 7
  %31 = getelementptr inbounds %"struct.RtApi::RtApiStream", ptr %30, i32 0, i32 16
  %32 = getelementptr inbounds [2 x i64], ptr %31, i64 0, i64 1
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = add i64 %34, %33
  store i64 %35, ptr %3, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %29, %24
  %37 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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, !30, i64 504}
!12 = !{!"_ZTS5RtApi", !13, i64 8, !19, i64 384, !21, i64 416, !23, i64 448, !24, i64 456, !28, i64 480, !29, i64 488}
!13 = !{!"_ZTSNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8}
!14 = !{!"_ZTSSo"}
!15 = !{!"_ZTSNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE", !16, i64 0, !18, i64 64, !19, i64 72}
!16 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56}
!17 = !{!"_ZTSSt6locale", !6, i64 0}
!18 = !{!"_ZTSSt13_Ios_Openmode", !7, i64 0}
!19 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !20, i64 0, !10, i64 8, !7, i64 16}
!20 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!21 = !{!"_ZTSSt8functionIFv16RtAudioErrorTypeRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE", !22, i64 0, !6, i64 24}
!22 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!23 = !{!"bool", !7, i64 0}
!24 = !{!"_ZTSSt6vectorIN7RtAudio10DeviceInfoESaIS1_EE", !25, i64 0}
!25 = !{!"_ZTSSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE12_Vector_implE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!28 = !{!"int", !7, i64 0}
!29 = !{!"_ZTSN5RtApi11RtApiStreamE", !7, i64 0, !6, i64 8, !30, i64 16, !31, i64 20, !7, i64 24, !6, i64 40, !7, i64 48, !23, i64 50, !7, i64 51, !7, i64 53, !28, i64 56, !28, i64 60, !28, i64 64, !7, i64 68, !7, i64 76, !7, i64 84, !7, i64 96, !10, i64 112, !7, i64 120, !7, i64 136, !32, i64 176, !7, i64 232, !33, i64 392}
!30 = !{!"_ZTSN5RtApi10StreamModeE", !7, i64 0}
!31 = !{!"_ZTSN5RtApi11StreamStateE", !7, i64 0}
!32 = !{!"_ZTS12CallbackInfo", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !23, i64 40, !23, i64 41, !28, i64 44, !23, i64 48}
!33 = !{!"double", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i64 @_ZN5RtApi16getStreamLatencyEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(888) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 504
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %7 [
    i32 0, label %4
    i32 2, label %4
  ]

4:                                                ; preds = %1, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 584
  %6 = load i64, ptr %5, align 8, !tbaa !32
  br label %7

7:                                                ; preds = %1, %4
  %.0 = phi i64 [ %6, %4 ], [ 0, %1 ]
  %.off = add i32 %3, -1
  %switch = icmp ult i32 %.off, 2
  %8 = getelementptr inbounds i8, ptr %0, i64 592
  %9 = load i64, ptr %8, align 8
  %10 = select i1 %switch, i64 %9, i64 0
  %.1 = add i64 %10, %.0
  ret i64 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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, !28, i64 504}
!6 = !{!"_ZTS5RtApi", !7, i64 8, !16, i64 384, !19, i64 416, !21, i64 448, !22, i64 456, !26, i64 480, !27, i64 488}
!7 = !{!"_ZTSNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE", !8, i64 0, !9, i64 8}
!8 = !{!"_ZTSSo"}
!9 = !{!"_ZTSNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE", !10, i64 0, !15, i64 64, !16, i64 72}
!10 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !14, i64 56}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"_ZTSSt6locale", !11, i64 0}
!15 = !{!"_ZTSSt13_Ios_Openmode", !12, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !12, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!18 = !{!"long", !12, i64 0}
!19 = !{!"_ZTSSt8functionIFv16RtAudioErrorTypeRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE", !20, i64 0, !11, i64 24}
!20 = !{!"_ZTSSt14_Function_base", !12, i64 0, !11, i64 16}
!21 = !{!"bool", !12, i64 0}
!22 = !{!"_ZTSSt6vectorIN7RtAudio10DeviceInfoESaIS1_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIN7RtAudio10DeviceInfoESaIS1_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!26 = !{!"int", !12, i64 0}
!27 = !{!"_ZTSN5RtApi11RtApiStreamE", !12, i64 0, !11, i64 8, !28, i64 16, !29, i64 20, !12, i64 24, !11, i64 40, !12, i64 48, !21, i64 50, !12, i64 51, !12, i64 53, !26, i64 56, !26, i64 60, !26, i64 64, !12, i64 68, !12, i64 76, !12, i64 84, !12, i64 96, !18, i64 112, !12, i64 120, !12, i64 136, !30, i64 176, !12, i64 232, !31, i64 392}
!28 = !{!"_ZTSN5RtApi10StreamModeE", !12, i64 0}
!29 = !{!"_ZTSN5RtApi11StreamStateE", !12, i64 0}
!30 = !{!"_ZTS12CallbackInfo", !11, i64 0, !18, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !21, i64 40, !21, i64 41, !26, i64 44, !21, i64 48}
!31 = !{!"double", !12, i64 0}
!32 = !{!18, !18, i64 0}


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