; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/src/hid (audio)

; 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.daisy::SaiHandle::Config" = type { i32, %struct.anon, i32, i32, i32, i32, i32, i32 }
%struct.anon = type { %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin }
%struct.dsy_gpio_pin = type { i32, i8 }
%"class.daisy::AudioHandle::Impl" = type { ptr, ptr, %"struct.daisy::AudioHandle::Config", %"class.daisy::SaiHandle", %"class.daisy::SaiHandle", [2 x ptr], [2 x ptr], float, float }
%"struct.daisy::AudioHandle::Config" = type <{ i64, i32, float, float, [4 x i8] }>
%"class.daisy::SaiHandle" = type { ptr }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

declare noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy11AudioHandle4Impl13SetSampleRateENS_9SaiHandle6Config10SampleRateE(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.daisy::SaiHandle::Config", align 4
  %7 = alloca i32, align 4
  %8 = alloca %"struct.daisy::SaiHandle::Config", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 2
  %12 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %11, i32 0, i32 1
  store i32 %10, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 3
  %14 = call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %13)
  br i1 %14, label %15, label %30

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 68, ptr %6) #5
  %16 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 3
  %17 = call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %17, i64 68, i1 false), !tbaa.struct !17
  %18 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 2
  %19 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %"struct.daisy::SaiHandle::Config", ptr %6, i32 0, i32 2
  store i32 %20, ptr %21, align 4, !tbaa !29
  %22 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 3
  %23 = call noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef nonnull align 4 dereferenceable(68) %6)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %15
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %27

26:                                               ; preds = %15
  store i32 0, ptr %7, align 4
  br label %27

27:                                               ; preds = %26, %25
  call void @llvm.lifetime.end.p0(i64 68, ptr %6) #5
  %28 = load i32, ptr %7, align 4
  switch i32 %28, label %51 [
    i32 0, label %29
    i32 1, label %49
  ]

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %29, %2
  %31 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 4
  %32 = call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %31)
  br i1 %32, label %33, label %48

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 68, ptr %8) #5
  %34 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 4
  %35 = call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %34)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %35, i64 68, i1 false), !tbaa.struct !17
  %36 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 2
  %37 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %"struct.daisy::SaiHandle::Config", ptr %8, i32 0, i32 2
  store i32 %38, ptr %39, align 4, !tbaa !29
  %40 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %9, i32 0, i32 4
  %41 = call noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8) %40, ptr noundef nonnull align 4 dereferenceable(68) %8)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %33
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %45

44:                                               ; preds = %33
  store i32 0, ptr %7, align 4
  br label %45

45:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 68, ptr %8) #5
  %46 = load i32, ptr %7, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
    i32 1, label %49
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %30
  store i32 0, ptr %3, align 4
  br label %49

49:                                               ; preds = %48, %45, %27
  %50 = load i32, ptr %3, align 4
  ret i32 %50

51:                                               ; preds = %45, %27
  unreachable
}

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

declare noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(68)) #2

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_ZTSN5daisy9SaiHandle6Config10SampleRateE", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTSN5daisy11AudioHandle4ImplE", !6, i64 0, !6, i64 8, !13, i64 16, !16, i64 40, !16, i64 48, !7, i64 56, !7, i64 72, !15, i64 88, !15, i64 92}
!13 = !{!"_ZTSN5daisy11AudioHandle6ConfigE", !14, i64 0, !10, i64 8, !15, i64 12, !15, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTSN5daisy9SaiHandleE", !6, i64 0}
!17 = !{i64 0, i64 4, !18, i64 4, i64 4, !20, i64 8, i64 1, !22, i64 12, i64 4, !20, i64 16, i64 1, !22, i64 20, i64 4, !20, i64 24, i64 1, !22, i64 28, i64 4, !20, i64 32, i64 1, !22, i64 36, i64 4, !20, i64 40, i64 1, !22, i64 44, i64 4, !9, i64 48, i64 4, !23, i64 52, i64 4, !25, i64 56, i64 4, !25, i64 60, i64 4, !27, i64 64, i64 4, !27}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTSN5daisy9SaiHandle6Config10PeripheralE", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"_ZTSN5daisy9SaiHandle6Config8BitDepthE", !7, i64 0}
!25 = !{!26, !26, i64 0}
!26 = !{!"_ZTSN5daisy9SaiHandle6Config4SyncE", !7, i64 0}
!27 = !{!28, !28, i64 0}
!28 = !{!"_ZTSN5daisy9SaiHandle6Config9DirectionE", !7, i64 0}
!29 = !{!30, !10, i64 44}
!30 = !{!"_ZTSN5daisy9SaiHandle6ConfigE", !19, i64 0, !31, i64 4, !10, i64 44, !24, i64 48, !26, i64 52, !26, i64 56, !28, i64 60, !28, i64 64}
!31 = !{!"_ZTSN5daisy9SaiHandle6ConfigUt_E", !32, i64 0, !32, i64 8, !32, i64 16, !32, i64 24, !32, i64 32}
!32 = !{!"_ZTS12dsy_gpio_pin", !21, i64 0, !7, i64 4}


; 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.daisy::SaiHandle::Config" = type { i32, %struct.anon, i32, i32, i32, i32, i32, i32 }
%struct.anon = type { %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin }
%struct.dsy_gpio_pin = type { i32, i8 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

declare noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN5daisy11AudioHandle4Impl13SetSampleRateENS_9SaiHandle6Config10SampleRateE(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %"struct.daisy::SaiHandle::Config", align 4
  %4 = alloca %"struct.daisy::SaiHandle::Config", align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %1, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = tail call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 68, ptr nonnull %3) #5
  %9 = tail call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(68) %3, ptr noundef nonnull align 4 dereferenceable(68) %9, i64 68, i1 false), !tbaa.struct !15
  %10 = load i32, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %3, i64 44
  store i32 %10, ptr %11, align 4, !tbaa !28
  %12 = call noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(68) %3)
  %.not.not = icmp eq i32 %12, 0
  call void @llvm.lifetime.end.p0(i64 68, ptr nonnull %3) #5
  br i1 %.not.not, label %13, label %22

13:                                               ; preds = %8, %2
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %14)
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 68, ptr nonnull %4) #5
  %17 = call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %14)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(68) %4, ptr noundef nonnull align 4 dereferenceable(68) %17, i64 68, i1 false), !tbaa.struct !15
  %18 = load i32, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %4, i64 44
  store i32 %18, ptr %19, align 4, !tbaa !28
  %20 = call noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(68) %4)
  %.not6.not = icmp eq i32 %20, 0
  call void @llvm.lifetime.end.p0(i64 68, ptr nonnull %4) #5
  br i1 %.not6.not, label %21, label %22

21:                                               ; preds = %16, %13
  br label %22

22:                                               ; preds = %16, %8, %21
  %.3 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 0, %21 ]
  ret i32 %.3
}

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

declare noundef i32 @_ZN5daisy9SaiHandle4InitERKNS0_6ConfigE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(68)) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 24}
!6 = !{!"_ZTSN5daisy11AudioHandle4ImplE", !7, i64 0, !7, i64 8, !10, i64 16, !14, i64 40, !14, i64 48, !8, i64 56, !8, i64 72, !13, i64 88, !13, i64 92}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN5daisy11AudioHandle6ConfigE", !11, i64 0, !12, i64 8, !13, i64 12, !13, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_ZTSN5daisy9SaiHandle6Config10SampleRateE", !8, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!"_ZTSN5daisy9SaiHandleE", !7, i64 0}
!15 = !{i64 0, i64 4, !16, i64 4, i64 4, !18, i64 8, i64 1, !20, i64 12, i64 4, !18, i64 16, i64 1, !20, i64 20, i64 4, !18, i64 24, i64 1, !20, i64 28, i64 4, !18, i64 32, i64 1, !20, i64 36, i64 4, !18, i64 40, i64 1, !20, i64 44, i64 4, !21, i64 48, i64 4, !22, i64 52, i64 4, !24, i64 56, i64 4, !24, i64 60, i64 4, !26, i64 64, i64 4, !26}
!16 = !{!17, !17, i64 0}
!17 = !{!"_ZTSN5daisy9SaiHandle6Config10PeripheralE", !8, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTS13dsy_gpio_port", !8, i64 0}
!20 = !{!8, !8, i64 0}
!21 = !{!12, !12, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"_ZTSN5daisy9SaiHandle6Config8BitDepthE", !8, i64 0}
!24 = !{!25, !25, i64 0}
!25 = !{!"_ZTSN5daisy9SaiHandle6Config4SyncE", !8, i64 0}
!26 = !{!27, !27, i64 0}
!27 = !{!"_ZTSN5daisy9SaiHandle6Config9DirectionE", !8, i64 0}
!28 = !{!29, !12, i64 44}
!29 = !{!"_ZTSN5daisy9SaiHandle6ConfigE", !17, i64 0, !30, i64 4, !12, i64 44, !23, i64 48, !25, i64 52, !25, i64 56, !27, i64 60, !27, i64 64}
!30 = !{!"_ZTSN5daisy9SaiHandle6ConfigUt_E", !31, i64 0, !31, i64 8, !31, i64 16, !31, i64 24, !31, i64 32}
!31 = !{!"_ZTS12dsy_gpio_pin", !19, i64 0, !8, i64 4}


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