; 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: 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 i16 @dwc_ep_write_packet(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3) #1 {
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i16 %3, ptr %9, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %13, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %14 = load i8, ptr %7, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = and i32 %15, 127
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %7, align 1, !tbaa !9
  %18 = load i8, ptr %7, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = mul nsw i32 32, %19
  %21 = add nsw i32 2320, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._usbd_device, ptr %22, i32 0, i32 18
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct._usbd_driver, ptr %24, i32 0, i32 11
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = add i32 %21, %26
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = load volatile i32, ptr %29, align 4, !tbaa !20
  %31 = and i32 %30, 524288
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %4
  store i16 0, ptr %5, align 2
  store i32 1, ptr %12, align 4
  br label %65

34:                                               ; preds = %4
  %35 = load i16, ptr %9, align 2, !tbaa !10
  %36 = zext i16 %35 to i32
  %37 = or i32 524288, %36
  %38 = load i8, ptr %7, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = mul nsw i32 32, %39
  %41 = add nsw i32 2320, %40
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._usbd_device, ptr %42, i32 0, i32 18
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds %struct._usbd_driver, ptr %44, i32 0, i32 11
  %46 = load i32, ptr %45, align 8, !tbaa !18
  %47 = add i32 %41, %46
  %48 = zext i32 %47 to i64
  %49 = inttoptr i64 %48 to ptr
  store volatile i32 %37, ptr %49, align 4, !tbaa !20
  %50 = load i8, ptr %7, align 1, !tbaa !9
  %51 = zext i8 %50 to i32
  %52 = mul nsw i32 32, %51
  %53 = add nsw i32 2304, %52
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._usbd_device, ptr %54, i32 0, i32 18
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  %57 = getelementptr inbounds %struct._usbd_driver, ptr %56, i32 0, i32 11
  %58 = load i32, ptr %57, align 8, !tbaa !18
  %59 = add i32 %53, %58
  %60 = zext i32 %59 to i64
  %61 = inttoptr i64 %60 to ptr
  %62 = load volatile i32, ptr %61, align 4, !tbaa !20
  %63 = or i32 %62, -2080374784
  store volatile i32 %63, ptr %61, align 4, !tbaa !20
  %64 = load i16, ptr %9, align 2, !tbaa !10
  store i16 %64, ptr %5, align 2
  store i32 1, ptr %12, align 4
  br label %65

65:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %66 = load i16, ptr %5, align 2
  ret i16 %66
}

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, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !6, i64 424}
!13 = !{!"_usbd_device", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !11, i64 40, !7, i64 42, !7, i64 43, !11, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !15, i64 80, !7, i64 128, !7, i64 192, !7, i64 384, !6, i64 416, !6, i64 424, !11, i64 432, !11, i64 434, !7, i64 436, !7, i64 440, !11, i64 456}
!14 = !{!"int", !7, i64 0}
!15 = !{!"usb_control_state", !14, i64 0, !16, i64 4, !6, i64 16, !11, i64 24, !6, i64 32, !17, i64 40}
!16 = !{!"usb_setup_data", !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!19, !14, i64 88}
!19 = !{!"_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, !14, i64 88, !17, i64 92, !11, i64 94}
!20 = !{!14, !14, 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: nofree norecurse nounwind uwtable
define dso_local noundef zeroext i16 @dwc_ep_write_packet(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, ptr nocapture noundef readnone %2, i16 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = and i8 %1, 127
  %6 = zext nneg i8 %5 to i32
  %7 = shl nuw nsw i32 %6, 5
  %8 = add nuw nsw i32 %7, 2320
  %9 = getelementptr inbounds i8, ptr %0, i64 424
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 88
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %13 = add i32 %8, %12
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = load volatile i32, ptr %15, align 4, !tbaa !17
  %17 = and i32 %16, 524288
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %28

18:                                               ; preds = %4
  %19 = zext i16 %3 to i32
  %20 = or disjoint i32 %19, 524288
  store volatile i32 %20, ptr %15, align 4, !tbaa !17
  %21 = add nuw nsw i32 %7, 2304
  %22 = load i32, ptr %11, align 8, !tbaa !15
  %23 = add i32 %21, %22
  %24 = zext i32 %23 to i64
  %25 = inttoptr i64 %24 to ptr
  %26 = load volatile i32, ptr %25, align 4, !tbaa !17
  %27 = or i32 %26, -2080374784
  store volatile i32 %27, ptr %25, align 4, !tbaa !17
  br label %28

28:                                               ; preds = %4, %18
  %.0 = phi i16 [ %3, %18 ], [ 0, %4 ]
  ret i16 %.0
}

attributes #0 = { nofree norecurse 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, !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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass