; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Host_Library/Class/MSC_ (TestUnitReady)

; 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._USBH_HandleTypeDef = type { i32, i32, i32, %struct.USBH_CtrlTypeDef, %struct.USBH_DeviceTypeDef, [1 x ptr], ptr, i32, [16 x i32], i32, i32, i8, ptr, ptr }
%struct.USBH_CtrlTypeDef = type { i8, i8, i8, ptr, i16, i16, %union._USB_Setup, i32, i8 }
%union._USB_Setup = type { [2 x i32] }
%struct.USBH_DeviceTypeDef = type { [256 x i8], [512 x i8], i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct._DeviceDescriptor, %struct._ConfigurationDescriptor }
%struct._DeviceDescriptor = type { i8, i8, i16, i8, i8, i8, i8, i16, i16, i16, i8, i8, i8, i8 }
%struct._ConfigurationDescriptor = type { i8, i8, i16, i8, i8, i8, i8, i8, [2 x %struct._InterfaceDescriptor] }
%struct._InterfaceDescriptor = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, [2 x %struct._EndpointDescriptor] }
%struct._EndpointDescriptor = type { i8, i8, i8, i8, i16, i8 }
%struct.USBH_ClassTypeDef = type { ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._MSC_Process = type { i8, [3 x i8], i8, i8, i8, i8, i16, i16, i32, i32, i32, i32, %struct.BOT_HandleTypeDef, [2 x %struct.MSC_LUNTypeDef], i16, i16, i32 }
%struct.BOT_HandleTypeDef = type { [16 x i32], i32, i32, i32, %union.BOT_CBWTypeDef, i8, %union.BOT_CSWTypeDef, [3 x i8], ptr }
%union.BOT_CBWTypeDef = type { %struct.__CBW }
%struct.__CBW = type { i32, i32, i32, i8, i8, i8, [16 x i8] }
%union.BOT_CSWTypeDef = type { %struct.__CSW }
%struct.__CSW = type { i32, i32, i32, i8 }
%struct.MSC_LUNTypeDef = type { i32, i32, i32, %struct.SCSI_CapacityTypeDef, %struct.SCSI_SenseTypeDef, %struct.SCSI_StdInquiryDataTypeDef, i8 }
%struct.SCSI_CapacityTypeDef = type { i32, i16 }
%struct.SCSI_SenseTypeDef = type { i8, i8, i8 }
%struct.SCSI_StdInquiryDataTypeDef = type { i8, i8, i8, [9 x i8], [17 x i8], [5 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @USBH_MSC_SCSI_TestUnitReady(ptr noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %7, i32 0, i32 6
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds %struct.USBH_ClassTypeDef, ptr %9, i32 0, i32 7
  %11 = load ptr, ptr %10, align 8, !tbaa !19
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._MSC_Process, ptr %12, i32 0, i32 12
  %14 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 8, !tbaa !21
  switch i32 %15, label %49 [
    i32 1, label %16
    i32 2, label %45
  ]

16:                                               ; preds = %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._MSC_Process, ptr %17, i32 0, i32 12
  %19 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds %struct.__CBW, ptr %19, i32 0, i32 2
  store i32 0, ptr %20, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._MSC_Process, ptr %21, i32 0, i32 12
  %23 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %22, i32 0, i32 4
  %24 = getelementptr inbounds %struct.__CBW, ptr %23, i32 0, i32 3
  store i8 0, ptr %24, align 4, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._MSC_Process, ptr %25, i32 0, i32 12
  %27 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %26, i32 0, i32 4
  %28 = getelementptr inbounds %struct.__CBW, ptr %27, i32 0, i32 5
  store i8 10, ptr %28, align 2, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._MSC_Process, ptr %29, i32 0, i32 12
  %31 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %30, i32 0, i32 4
  %32 = getelementptr inbounds %struct.__CBW, ptr %31, i32 0, i32 6
  %33 = getelementptr inbounds [16 x i8], ptr %32, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %33, i8 0, i64 16, i1 false)
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._MSC_Process, ptr %34, i32 0, i32 12
  %36 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds %struct.__CBW, ptr %36, i32 0, i32 6
  %38 = getelementptr inbounds [16 x i8], ptr %37, i64 0, i64 0
  store i8 0, ptr %38, align 1, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._MSC_Process, ptr %39, i32 0, i32 12
  %41 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %40, i32 0, i32 1
  store i32 1, ptr %41, align 8, !tbaa !24
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._MSC_Process, ptr %42, i32 0, i32 12
  %44 = getelementptr inbounds %struct.BOT_HandleTypeDef, ptr %43, i32 0, i32 3
  store i32 2, ptr %44, align 8, !tbaa !21
  store i32 1, ptr %5, align 4, !tbaa !10
  br label %50

45:                                               ; preds = %2
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i8, ptr %4, align 1, !tbaa !9
  %48 = call i32 @USBH_MSC_BOT_Process(ptr noundef %46, i8 noundef zeroext %47)
  store i32 %48, ptr %5, align 4, !tbaa !10
  br label %50

49:                                               ; preds = %2
  br label %50

50:                                               ; preds = %49, %45, %16
  %51 = load i32, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %51
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @USBH_MSC_BOT_Process(ptr noundef, i8 noundef zeroext) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 928}
!13 = !{!"_USBH_HandleTypeDef", !11, i64 0, !11, i64 4, !11, i64 8, !14, i64 16, !16, i64 56, !7, i64 920, !6, i64 928, !11, i64 936, !7, i64 940, !11, i64 1004, !11, i64 1008, !7, i64 1012, !6, i64 1016, !6, i64 1024}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 8, !15, i64 16, !15, i64 18, !7, i64 20, !11, i64 28, !7, i64 32}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 256, !7, i64 768, !7, i64 769, !7, i64 770, !7, i64 771, !7, i64 772, !7, i64 773, !7, i64 774, !7, i64 775, !7, i64 776, !17, i64 778, !18, i64 796}
!17 = !{!"_DeviceDescriptor", !7, i64 0, !7, i64 1, !15, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !15, i64 8, !15, i64 10, !15, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17}
!18 = !{!"_ConfigurationDescriptor", !7, i64 0, !7, i64 1, !15, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 10}
!19 = !{!20, !6, i64 56}
!20 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!21 = !{!22, !11, i64 104}
!22 = !{!"_MSC_Process", !7, i64 0, !7, i64 1, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !15, i64 8, !15, i64 10, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !23, i64 32, !7, i64 176, !15, i64 296, !15, i64 298, !11, i64 300}
!23 = !{!"", !7, i64 0, !11, i64 64, !11, i64 68, !11, i64 72, !7, i64 76, !7, i64 108, !7, i64 112, !7, i64 128, !6, i64 136}
!24 = !{!22, !11, i64 96}


; 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: nounwind uwtable
define dso_local i32 @USBH_MSC_SCSI_TestUnitReady(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 928
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %6, i64 104
  %8 = load i32, ptr %7, align 8, !tbaa !18
  switch i32 %8, label %17 [
    i32 1, label %9
    i32 2, label %15
  ]

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %6, i64 116
  store i32 0, ptr %10, align 4, !tbaa !21
  %11 = getelementptr inbounds i8, ptr %6, i64 120
  store i8 0, ptr %11, align 4, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %6, i64 122
  store i8 10, ptr %12, align 2, !tbaa !21
  %13 = getelementptr inbounds i8, ptr %6, i64 123
  %14 = getelementptr inbounds i8, ptr %6, i64 96
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  store i32 1, ptr %14, align 8, !tbaa !22
  store i32 2, ptr %7, align 8, !tbaa !18
  br label %17

15:                                               ; preds = %2
  %16 = tail call i32 @USBH_MSC_BOT_Process(ptr noundef nonnull %0, i8 noundef zeroext %1) #3
  br label %17

17:                                               ; preds = %2, %15, %9
  %.0 = phi i32 [ 2, %2 ], [ %16, %15 ], [ 1, %9 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare i32 @USBH_MSC_BOT_Process(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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, !11, i64 928}
!6 = !{!"_USBH_HandleTypeDef", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !13, i64 56, !8, i64 920, !11, i64 928, !7, i64 936, !8, i64 940, !7, i64 1004, !7, i64 1008, !8, i64 1012, !11, i64 1016, !11, i64 1024}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !11, i64 8, !12, i64 16, !12, i64 18, !8, i64 20, !7, i64 28, !8, i64 32}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !8, i64 0, !8, i64 256, !8, i64 768, !8, i64 769, !8, i64 770, !8, i64 771, !8, i64 772, !8, i64 773, !8, i64 774, !8, i64 775, !8, i64 776, !14, i64 778, !15, i64 796}
!14 = !{!"_DeviceDescriptor", !8, i64 0, !8, i64 1, !12, i64 2, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !12, i64 8, !12, i64 10, !12, i64 12, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17}
!15 = !{!"_ConfigurationDescriptor", !8, i64 0, !8, i64 1, !12, i64 2, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !8, i64 8, !8, i64 10}
!16 = !{!17, !11, i64 56}
!17 = !{!"", !11, i64 0, !8, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!18 = !{!19, !7, i64 104}
!19 = !{!"_MSC_Process", !8, i64 0, !8, i64 1, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7, !12, i64 8, !12, i64 10, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !20, i64 32, !8, i64 176, !12, i64 296, !12, i64 298, !7, i64 300}
!20 = !{!"", !8, i64 0, !7, i64 64, !7, i64 68, !7, i64 72, !8, i64 76, !8, i64 108, !8, i64 112, !8, i64 128, !11, i64 136}
!21 = !{!8, !8, i64 0}
!22 = !{!19, !7, i64 96}


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