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

; 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.daisy::MultiSlaveSpiHandle" = type { %"struct.daisy::MultiSlaveSpiHandle::Config", %"class.daisy::SpiHandle", [4 x %struct.dsy_gpio], %"struct.daisy::MultiSlaveSpiHandle::DmaTransfer" }
%"struct.daisy::MultiSlaveSpiHandle::Config" = type { %struct.anon, i32, i32, i64, i32, i32, i32, i64 }
%struct.anon = type { %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, [4 x %struct.dsy_gpio_pin] }
%struct.dsy_gpio_pin = type { i32, i8 }
%"class.daisy::SpiHandle" = type { ptr }
%struct.dsy_gpio = type { %struct.dsy_gpio_pin, i32, i32 }
%"struct.daisy::MultiSlaveSpiHandle::DmaTransfer" = type { i8, 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: mustprogress uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) #1 align 2

; 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
declare dso_local noundef zeroext i1 @_ZNK5daisy19MultiSlaveSpiHandle11DmaTransfer7IsValidEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy19MultiSlaveSpiHandle26BlockingTransmitAndReceiveEmPhS1_mj(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) #1 align 2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !11
  %15 = load ptr, ptr %8, align 8
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %15, i32 0, i32 0
  %18 = getelementptr inbounds %"struct.daisy::MultiSlaveSpiHandle::Config", ptr %17, i32 0, i32 7
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp uge i64 %16, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  store i32 1, ptr %7, align 4
  br label %37

22:                                               ; preds = %6
  br label %23

23:                                               ; preds = %26, %22
  %24 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %15, i32 0, i32 3
  %25 = call noundef zeroext i1 @_ZNK5daisy19MultiSlaveSpiHandle11DmaTransfer7IsValidEv(ptr noundef nonnull align 8 dereferenceable(32) %24)
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  br label %23, !llvm.loop !26

27:                                               ; preds = %23
  %28 = load i64, ptr %9, align 8, !tbaa !9
  call void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %15, i64 noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %29 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %15, i32 0, i32 1
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = load i32, ptr %13, align 4, !tbaa !11
  %34 = call noundef i32 @_ZN5daisy9SpiHandle26BlockingTransmitAndReceiveEPhS1_mj(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %30, ptr noundef %31, i64 noundef %32, i32 noundef %33)
  store i32 %34, ptr %14, align 4, !tbaa !28
  %35 = load i64, ptr %9, align 8, !tbaa !9
  call void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %15, i64 noundef %35)
  %36 = load i32, ptr %14, align 4, !tbaa !28
  store i32 %36, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %37

37:                                               ; preds = %27, %21
  %38 = load i32, ptr %7, align 4
  ret i32 %38
}

declare noundef i32 @_ZN5daisy9SpiHandle26BlockingTransmitAndReceiveEPhS1_mj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, i64 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 88}
!14 = !{!"_ZTSN5daisy19MultiSlaveSpiHandleE", !15, i64 0, !24, i64 96, !7, i64 104, !25, i64 168}
!15 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigE", !16, i64 0, !19, i64 56, !20, i64 60, !10, i64 64, !21, i64 72, !22, i64 76, !23, i64 80, !10, i64 88}
!16 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigUt_E", !17, i64 0, !17, i64 8, !17, i64 16, !7, i64 24}
!17 = !{!"_ZTS12dsy_gpio_pin", !18, i64 0, !7, i64 4}
!18 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!19 = !{!"_ZTSN5daisy9SpiHandle6Config10PeripheralE", !7, i64 0}
!20 = !{!"_ZTSN5daisy9SpiHandle6Config9DirectionE", !7, i64 0}
!21 = !{!"_ZTSN5daisy9SpiHandle6Config13ClockPolarityE", !7, i64 0}
!22 = !{!"_ZTSN5daisy9SpiHandle6Config10ClockPhaseE", !7, i64 0}
!23 = !{!"_ZTSN5daisy9SpiHandle6Config13BaudPrescalerE", !7, i64 0}
!24 = !{!"_ZTSN5daisy9SpiHandleE", !6, i64 0}
!25 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle11DmaTransferE", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!29, !29, i64 0}
!29 = !{!"_ZTSN5daisy9SpiHandle6ResultE", !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 uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy19MultiSlaveSpiHandle26BlockingTransmitAndReceiveEmPhS1_mj(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #0 align 2 {
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not = icmp ugt i64 %8, %1
  br i1 %.not, label %.preheader, label %15

.preheader:                                       ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 168
  br label %10

10:                                               ; preds = %.preheader, %10
  %11 = tail call noundef zeroext i1 @_ZNK5daisy19MultiSlaveSpiHandle11DmaTransfer7IsValidEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  br i1 %11, label %10, label %12, !llvm.loop !22

12:                                               ; preds = %10
  tail call void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1)
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = tail call noundef i32 @_ZN5daisy9SpiHandle26BlockingTransmitAndReceiveEPhS1_mj(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5)
  tail call void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1)
  br label %15

15:                                               ; preds = %6, %12
  %.0 = phi i32 [ %14, %12 ], [ 1, %6 ]
  ret i32 %.0
}

declare noundef i32 @_ZN5daisy9SpiHandle26BlockingTransmitAndReceiveEPhS1_mj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #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 = { "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, !15, i64 88}
!6 = !{!"_ZTSN5daisy19MultiSlaveSpiHandleE", !7, i64 0, !19, i64 96, !11, i64 104, !21, i64 168}
!7 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigE", !8, i64 0, !13, i64 56, !14, i64 60, !15, i64 64, !16, i64 72, !17, i64 76, !18, i64 80, !15, i64 88}
!8 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigUt_E", !9, i64 0, !9, i64 8, !9, i64 16, !11, i64 24}
!9 = !{!"_ZTS12dsy_gpio_pin", !10, i64 0, !11, i64 4}
!10 = !{!"_ZTS13dsy_gpio_port", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN5daisy9SpiHandle6Config10PeripheralE", !11, i64 0}
!14 = !{!"_ZTSN5daisy9SpiHandle6Config9DirectionE", !11, i64 0}
!15 = !{!"long", !11, i64 0}
!16 = !{!"_ZTSN5daisy9SpiHandle6Config13ClockPolarityE", !11, i64 0}
!17 = !{!"_ZTSN5daisy9SpiHandle6Config10ClockPhaseE", !11, i64 0}
!18 = !{!"_ZTSN5daisy9SpiHandle6Config13BaudPrescalerE", !11, i64 0}
!19 = !{!"_ZTSN5daisy9SpiHandleE", !20, i64 0}
!20 = !{!"any pointer", !11, i64 0}
!21 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle11DmaTransferE", !11, i64 0, !20, i64 8, !20, i64 16, !20, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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