; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Host_Library/Core/Src (FindInterfaceIndex)

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

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @USBH_FindInterfaceIndex(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #1 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  store i8 0, ptr %10, align 1, !tbaa !9
  store ptr null, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USBH_HandleTypeDef, ptr %12, i32 0, i32 4
  %14 = getelementptr inbounds %struct.USBH_DeviceTypeDef, ptr %13, i32 0, i32 12
  store ptr %14, ptr %9, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %42, %3
  %16 = load i8, ptr %10, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp ult i32 %17, 2
  br i1 %18, label %19, label %45

19:                                               ; preds = %15
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._ConfigurationDescriptor, ptr %20, i32 0, i32 8
  %22 = load i8, ptr %10, align 1, !tbaa !9
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds [2 x %struct._InterfaceDescriptor], ptr %21, i64 0, i64 %23
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._InterfaceDescriptor, ptr %25, i32 0, i32 2
  %27 = load i8, ptr %26, align 2, !tbaa !10
  %28 = zext i8 %27 to i32
  %29 = load i8, ptr %6, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %28, %30
  br i1 %31, label %32, label %42

32:                                               ; preds = %19
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._InterfaceDescriptor, ptr %33, i32 0, i32 3
  %35 = load i8, ptr %34, align 1, !tbaa !12
  %36 = zext i8 %35 to i32
  %37 = load i8, ptr %7, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = icmp eq i32 %36, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  %41 = load i8, ptr %10, align 1, !tbaa !9
  store i8 %41, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %46

42:                                               ; preds = %32, %19
  %43 = load i8, ptr %10, align 1, !tbaa !9
  %44 = add i8 %43, 1
  store i8 %44, ptr %10, align 1, !tbaa !9
  br label %15, !llvm.loop !13

45:                                               ; preds = %15
  store i8 -1, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %46

46:                                               ; preds = %45, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %47 = load i8, ptr %4, align 1
  ret i8 %47
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 2}
!11 = !{!"_InterfaceDescriptor", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 10}
!12 = !{!11, !7, i64 3}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i8 @USBH_FindInterfaceIndex(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 864
  %5 = load i8, ptr %4, align 2, !tbaa !5
  %6 = icmp eq i8 %5, %1
  br i1 %6, label %7, label %11

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 865
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = icmp eq i8 %9, %2
  br i1 %10, label %20, label %11

11:                                               ; preds = %7, %3
  %12 = getelementptr inbounds i8, ptr %0, i64 890
  %13 = load i8, ptr %12, align 2, !tbaa !5
  %14 = icmp eq i8 %13, %1
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 891
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = icmp eq i8 %17, %2
  br i1 %18, label %20, label %19

19:                                               ; preds = %15, %11
  br label %20

20:                                               ; preds = %19, %15, %7
  %.010 = phi i8 [ 0, %7 ], [ 1, %15 ], [ -1, %19 ]
  ret i8 %.010
}

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

!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, !7, i64 2}
!6 = !{!"_InterfaceDescriptor", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 10}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 3}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass