; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/tiny_audio/b3ReadWavFile.ll (ZN13b3ReadWavFile15createWavTickerEd)

; 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.b3WavTicker = type <{ %"class.std::vector", i8, [7 x i8], double, double, double, double, double, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.b3ReadWavFile = type <{ ptr, i8, i8, [6 x i8], i64, i64, double, i64, i32, i8, [3 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13b3ReadWavFile15createWavTickerEd(ptr dead_on_unwind noalias writable sret(%struct.b3WavTicker) align 8 %0, ptr noundef nonnull align 8 dereferenceable(53) %1, double noundef %2) #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  store i1 false, ptr %7, align 1
  call void @_ZN11b3WavTickerC2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) #2
  %11 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 0
  %12 = getelementptr inbounds %class.b3ReadWavFile, ptr %10, i32 0, i32 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = zext i32 %13 to i64
  invoke void @_ZNSt6vectorIdSaIdEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %14)
          to label %15 unwind label %31

15:                                               ; preds = %3
  %16 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 3
  store double 0.000000e+00, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 4
  store double 0.000000e+00, ptr %17, align 8, !tbaa !22
  %18 = getelementptr inbounds %class.b3ReadWavFile, ptr %10, i32 0, i32 4
  %19 = load i64, ptr %18, align 8, !tbaa !23
  %20 = uitofp i64 %19 to double
  %21 = fsub double %20, 1.000000e+00
  %22 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 5
  store double %21, ptr %22, align 8, !tbaa !24
  %23 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 1
  store i8 0, ptr %23, align 8, !tbaa !25
  %24 = getelementptr inbounds %class.b3ReadWavFile, ptr %10, i32 0, i32 6
  %25 = load double, ptr %24, align 8, !tbaa !26
  %26 = load double, ptr %6, align 8, !tbaa !9
  %27 = fdiv double %25, %26
  %28 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 6
  store double %27, ptr %28, align 8, !tbaa !27
  %29 = getelementptr inbounds %struct.b3WavTicker, ptr %0, i32 0, i32 7
  store double 1.000000e+00, ptr %29, align 8, !tbaa !28
  store i1 true, ptr %7, align 1
  %30 = load i1, ptr %7, align 1
  br i1 %30, label %36, label %35

31:                                               ; preds = %3
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %8, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %9, align 4
  call void @_ZN11b3WavTickerD2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) #2
  br label %37

35:                                               ; preds = %15
  call void @_ZN11b3WavTickerD2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) #2
  br label %36

36:                                               ; preds = %35, %15
  ret void

37:                                               ; preds = %31
  %38 = load ptr, ptr %8, align 8
  %39 = load i32, ptr %9, align 4
  %40 = insertvalue { ptr, i32 } poison, ptr %38, 0
  %41 = insertvalue { ptr, i32 } %40, i32 %39, 1
  resume { ptr, i32 } %41
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11b3WavTickerC2Ev(ptr noundef nonnull align 8 dereferenceable(76)) unnamed_addr #1 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11b3WavTickerD2Ev(ptr noundef nonnull align 8 dereferenceable(76)) unnamed_addr #1 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 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !15, i64 48}
!12 = !{!"_ZTS13b3ReadWavFile", !13, i64 8, !13, i64 9, !14, i64 16, !14, i64 24, !10, i64 32, !14, i64 40, !15, i64 48, !13, i64 52}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !10, i64 32}
!17 = !{!"_ZTS11b3WavTicker", !18, i64 0, !13, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !15, i64 72}
!18 = !{!"_ZTSSt6vectorIdSaIdEE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!17, !10, i64 40}
!23 = !{!12, !14, i64 16}
!24 = !{!17, !10, i64 48}
!25 = !{!17, !13, i64 24}
!26 = !{!12, !10, i64 32}
!27 = !{!17, !10, i64 56}
!28 = !{!17, !10, i64 64}


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

%struct.b3WavTicker = type <{ %"class.std::vector", i8, [7 x i8], double, double, double, double, double, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13b3ReadWavFile15createWavTickerEd(ptr dead_on_unwind noalias nonnull writable sret(%struct.b3WavTicker) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(53) %1, double noundef %2) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN11b3WavTickerC2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) #3
  %4 = getelementptr inbounds i8, ptr %1, i64 48
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = zext i32 %5 to i64
  invoke void @_ZNSt6vectorIdSaIdEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %6)
          to label %7 unwind label %20

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = uitofp i64 %10 to double
  %12 = fadd double %11, -1.000000e+00
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  store double %12, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 0, ptr %14, align 8, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %1, i64 32
  %16 = load double, ptr %15, align 8, !tbaa !22
  %17 = fdiv double %16, %2
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  store double %17, ptr %18, align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  store double 1.000000e+00, ptr %19, align 8, !tbaa !24
  ret void

20:                                               ; preds = %3
  %21 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN11b3WavTickerD2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) #3
  resume { ptr, i32 } %21
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11b3WavTickerC2Ev(ptr noundef nonnull align 8 dereferenceable(76)) unnamed_addr #1 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11b3WavTickerD2Ev(ptr noundef nonnull align 8 dereferenceable(76)) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !12, i64 48}
!6 = !{!"_ZTS13b3ReadWavFile", !7, i64 8, !7, i64 9, !10, i64 16, !10, i64 24, !11, i64 32, !10, i64 40, !12, i64 48, !7, i64 52}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !11, i64 48}
!15 = !{!"_ZTS11b3WavTicker", !16, i64 0, !7, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !12, i64 72}
!16 = !{!"_ZTSSt6vectorIdSaIdEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !20, i64 0, !20, i64 8, !20, i64 16}
!20 = !{!"any pointer", !8, i64 0}
!21 = !{!15, !7, i64 24}
!22 = !{!6, !11, i64 32}
!23 = !{!15, !11, i64 56}
!24 = !{!15, !11, i64 64}


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