; LLVM IR from Aquatic-Games/mixr :: src/Stream/Wav.ll (ZN4mixr6Stream3Wav9GetBufferEPhm)

; 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.std::fpos" = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"class.mixr::Stream::Wav" = type <{ %"class.mixr::Stream::AudioStream", %"class.std::basic_ifstream", %"struct.mixr::AudioFormat", i8, [3 x i8], %"struct.mixr::Stream::ADPCMInfo", i64, i64, i32, [4 x i8] }>
%"class.mixr::Stream::AudioStream" = type { ptr }
%"class.std::basic_ifstream" = type { %"class.std::basic_istream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_istream.base" = type { ptr, i64 }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%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 }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%"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 }
%"struct.mixr::AudioFormat" = type { i32, i32, i8 }
%"struct.mixr::Stream::ADPCMInfo" = type { i32, 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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN4mixr6Stream3Wav9GetBufferEPhm(ptr noundef nonnull align 8 dereferenceable(580) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca %"class.std::fpos", align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 1
  %13 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 7
  %14 = load i64, ptr %13, align 8, !tbaa !11
  call void @_ZNSt4fposI11__mbstate_tEC2El(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %14)
  %15 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %16 = load i64, ptr %15, align 8
  %17 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %18 = load i64, ptr %17, align 8
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgESt4fposI11__mbstate_tE(ptr noundef nonnull align 8 dereferenceable(16) %12, i64 %16, i64 %18)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %20 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 7
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = add i64 %21, %22
  store i64 %23, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %24 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 6
  %25 = load i64, ptr %24, align 8, !tbaa !28
  %26 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 8
  %27 = load i32, ptr %26, align 8, !tbaa !29
  %28 = zext i32 %27 to i64
  %29 = add i64 %25, %28
  store i64 %29, ptr %9, align 8, !tbaa !9
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = icmp uge i64 %30, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %3
  %34 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %34, ptr %8, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %33, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 7
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = sub i64 %36, %38
  store i64 %39, ptr %10, align 8, !tbaa !9
  %40 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 1
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %40, ptr noundef %41, i64 noundef %42)
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = getelementptr inbounds %"class.mixr::Stream::Wav", ptr %11, i32 0, i32 7
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = add i64 %46, %44
  store i64 %47, ptr %45, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  ret i64 %48
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgESt4fposI11__mbstate_tE(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4fposI11__mbstate_tEC2El(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) unnamed_addr #3 align 2

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

!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 568}
!12 = !{!"_ZTSN4mixr6Stream3WavE", !13, i64 0, !14, i64 8, !24, i64 528, !20, i64 540, !26, i64 544, !10, i64 560, !10, i64 568, !23, i64 576}
!13 = !{!"_ZTSN4mixr6Stream11AudioStreamE"}
!14 = !{!"_ZTSSt14basic_ifstreamIcSt11char_traitsIcEE", !15, i64 0, !16, i64 16}
!15 = !{!"_ZTSSi", !10, i64 8}
!16 = !{!"_ZTSSt13basic_filebufIcSt11char_traitsIcEE", !17, i64 0, !7, i64 64, !19, i64 104, !21, i64 120, !22, i64 124, !22, i64 132, !22, i64 140, !6, i64 152, !10, i64 160, !20, i64 168, !20, i64 169, !20, i64 170, !7, i64 171, !6, i64 176, !6, i64 184, !20, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !6, i64 224, !6, i64 232}
!17 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !18, i64 56}
!18 = !{!"_ZTSSt6locale", !6, i64 0}
!19 = !{!"_ZTSSt12__basic_fileIcE", !6, i64 0, !20, i64 8}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTSSt13_Ios_Openmode", !7, i64 0}
!22 = !{!"_ZTS11__mbstate_t", !23, i64 0, !7, i64 4}
!23 = !{!"int", !7, i64 0}
!24 = !{!"_ZTSN4mixr11AudioFormatE", !25, i64 0, !23, i64 4, !7, i64 8}
!25 = !{!"_ZTSN4mixr8DataTypeE", !7, i64 0}
!26 = !{!"_ZTSN4mixr6Stream9ADPCMInfoE", !27, i64 0, !10, i64 8}
!27 = !{!"_ZTSN4mixr6Stream9ADPCMTypeE", !7, i64 0}
!28 = !{!12, !10, i64 560}
!29 = !{!12, !23, i64 576}


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

%"class.std::fpos" = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN4mixr6Stream3Wav9GetBufferEPhm(ptr noundef nonnull align 8 dereferenceable(580) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca %"class.std::fpos", align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 568
  %7 = load i64, ptr %6, align 8, !tbaa !5
  call void @_ZNSt4fposI11__mbstate_tEC2El(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %7)
  %8 = load i64, ptr %4, align 8
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  %10 = load i64, ptr %9, align 8
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgESt4fposI11__mbstate_tE(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 %8, i64 %10)
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = add i64 %12, %2
  %14 = getelementptr inbounds i8, ptr %0, i64 560
  %15 = load i64, ptr %14, align 8, !tbaa !26
  %16 = getelementptr inbounds i8, ptr %0, i64 576
  %17 = load i32, ptr %16, align 8, !tbaa !27
  %18 = zext i32 %17 to i64
  %19 = add i64 %15, %18
  %spec.select = call i64 @llvm.umin.i64(i64 %13, i64 %19)
  %20 = sub i64 %spec.select, %12
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi4readEPcl(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef %1, i64 noundef %20)
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = add i64 %20, %22
  store i64 %23, ptr %6, align 8, !tbaa !5
  ret i64 %20
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSi5seekgESt4fposI11__mbstate_tE(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4fposI11__mbstate_tEC2El(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) unnamed_addr #2 align 2

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

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

!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 568}
!6 = !{!"_ZTSN4mixr6Stream3WavE", !7, i64 0, !8, i64 8, !22, i64 528, !18, i64 540, !24, i64 544, !10, i64 560, !10, i64 568, !21, i64 576}
!7 = !{!"_ZTSN4mixr6Stream11AudioStreamE"}
!8 = !{!"_ZTSSt14basic_ifstreamIcSt11char_traitsIcEE", !9, i64 0, !13, i64 16}
!9 = !{!"_ZTSSi", !10, i64 8}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSSt13basic_filebufIcSt11char_traitsIcEE", !14, i64 0, !11, i64 64, !17, i64 104, !19, i64 120, !20, i64 124, !20, i64 132, !20, i64 140, !15, i64 152, !10, i64 160, !18, i64 168, !18, i64 169, !18, i64 170, !11, i64 171, !15, i64 176, !15, i64 184, !18, i64 192, !15, i64 200, !15, i64 208, !10, i64 216, !15, i64 224, !15, i64 232}
!14 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !16, i64 56}
!15 = !{!"any pointer", !11, i64 0}
!16 = !{!"_ZTSSt6locale", !15, i64 0}
!17 = !{!"_ZTSSt12__basic_fileIcE", !15, i64 0, !18, i64 8}
!18 = !{!"bool", !11, i64 0}
!19 = !{!"_ZTSSt13_Ios_Openmode", !11, i64 0}
!20 = !{!"_ZTS11__mbstate_t", !21, i64 0, !11, i64 4}
!21 = !{!"int", !11, i64 0}
!22 = !{!"_ZTSN4mixr11AudioFormatE", !23, i64 0, !21, i64 4, !11, i64 8}
!23 = !{!"_ZTSN4mixr8DataTypeE", !11, i64 0}
!24 = !{!"_ZTSN4mixr6Stream9ADPCMInfoE", !25, i64 0, !10, i64 8}
!25 = !{!"_ZTSN4mixr6Stream9ADPCMTypeE", !11, i64 0}
!26 = !{!6, !10, i64 560}
!27 = !{!6, !21, i64 576}


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