; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/usb (usb_dwc_common)

; 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._usbd_device = type { ptr, ptr, ptr, i32, ptr, i16, i8, i8, i16, ptr, ptr, ptr, ptr, %struct.usb_control_state, [4 x %struct.user_control_callback], [8 x [3 x ptr]], [4 x ptr], ptr, ptr, i16, i16, [4 x i8], [4 x i32], i16 }
%struct.usb_control_state = type { i32, %struct.usb_setup_data, ptr, i16, ptr, i8 }
%struct.usb_setup_data = type { i8, i8, i16, i16, i16 }
%struct.user_control_callback = type { ptr, i8, i8 }
%struct._usbd_driver = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i16 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @dwc_ep_stall_get(ptr noundef %0, i8 noundef zeroext %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = zext i8 %6 to i32
  %8 = and i32 %7, 128
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %30

10:                                               ; preds = %2
  %11 = load i8, ptr %5, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 127
  %14 = mul nsw i32 32, %13
  %15 = add nsw i32 2304, %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._usbd_device, ptr %16, i32 0, i32 18
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %19 = getelementptr inbounds %struct._usbd_driver, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = add i32 %15, %20
  %22 = zext i32 %21 to i64
  %23 = inttoptr i64 %22 to ptr
  %24 = load volatile i32, ptr %23, align 4, !tbaa !19
  %25 = and i32 %24, 2097152
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 1, i32 0
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %3, align 1
  br label %49

30:                                               ; preds = %2
  %31 = load i8, ptr %5, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = mul nsw i32 32, %32
  %34 = add nsw i32 2816, %33
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._usbd_device, ptr %35, i32 0, i32 18
  %37 = load ptr, ptr %36, align 8, !tbaa !10
  %38 = getelementptr inbounds %struct._usbd_driver, ptr %37, i32 0, i32 11
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = add i32 %34, %39
  %41 = zext i32 %40 to i64
  %42 = inttoptr i64 %41 to ptr
  %43 = load volatile i32, ptr %42, align 4, !tbaa !19
  %44 = and i32 %43, 2097152
  %45 = icmp ne i32 %44, 0
  %46 = zext i1 %45 to i64
  %47 = select i1 %45, i32 1, i32 0
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr %3, align 1
  br label %49

49:                                               ; preds = %30, %10
  %50 = load i8, ptr %3, align 1
  ret i8 %50
}

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

!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, !6, i64 424}
!11 = !{!"_usbd_device", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !13, i64 40, !7, i64 42, !7, i64 43, !13, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !14, i64 80, !7, i64 128, !7, i64 192, !7, i64 384, !6, i64 416, !6, i64 424, !13, i64 432, !13, i64 434, !7, i64 436, !7, i64 440, !13, i64 456}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"usb_control_state", !12, i64 0, !15, i64 4, !6, i64 16, !13, i64 24, !6, i64 32, !16, i64 40}
!15 = !{!"usb_setup_data", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !13, i64 6}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!18, !12, i64 88}
!18 = !{!"_usbd_driver", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !16, i64 92, !13, i64 94}
!19 = !{!12, !12, 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 nofree norecurse nounwind willreturn uwtable
define dso_local zeroext range(i8 0, 2) i8 @dwc_ep_stall_get(ptr nocapture noundef readonly %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i8 %1 to i32
  %4 = shl nuw nsw i32 %3, 5
  %5 = add nuw nsw i32 %4, 2816
  %6 = and i32 %4, 4064
  %7 = add nuw nsw i32 %6, 2304
  %.not11 = icmp slt i8 %1, 0
  %.sink = select i1 %.not11, i32 %7, i32 %5
  %8 = getelementptr inbounds i8, ptr %0, i64 424
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 88
  %11 = load i32, ptr %10, align 8, !tbaa !15
  %12 = add i32 %.sink, %11
  %.0.in.in.in.in.in = zext i32 %12 to i64
  %.0.in.in.in.in = inttoptr i64 %.0.in.in.in.in.in to ptr
  %.0.in.in.in = load volatile i32, ptr %.0.in.in.in.in, align 4, !tbaa !17
  %.0.in.in = lshr i32 %.0.in.in.in, 21
  %.0.in = trunc i32 %.0.in.in to i8
  %.0 = and i8 %.0.in, 1
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nounwind willreturn 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 424}
!6 = !{!"_usbd_device", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !11, i64 40, !8, i64 42, !8, i64 43, !11, i64 44, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !12, i64 80, !8, i64 128, !8, i64 192, !8, i64 384, !7, i64 416, !7, i64 424, !11, i64 432, !11, i64 434, !8, i64 436, !8, i64 440, !11, i64 456}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"usb_control_state", !10, i64 0, !13, i64 4, !7, i64 16, !11, i64 24, !7, i64 32, !14, i64 40}
!13 = !{!"usb_setup_data", !8, i64 0, !8, i64 1, !11, i64 2, !11, i64 4, !11, i64 6}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!16, !10, i64 88}
!16 = !{!"_usbd_driver", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !14, i64 92, !11, i64 94}
!17 = !{!10, !10, i64 0}


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