; 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 void @dwc_ep_nak_set(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  %7 = load i8, ptr %5, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = and i32 %8, 128
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %51

12:                                               ; preds = %3
  %13 = load i8, ptr %6, align 1, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._usbd_device, ptr %14, i32 0, i32 21
  %16 = load i8, ptr %5, align 1, !tbaa !9
  %17 = zext i8 %16 to i64
  %18 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 %17
  store i8 %13, ptr %18, align 1, !tbaa !9
  %19 = load i8, ptr %6, align 1, !tbaa !9
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %36

21:                                               ; preds = %12
  %22 = load i8, ptr %5, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = mul nsw i32 32, %23
  %25 = add nsw i32 2816, %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._usbd_device, ptr %26, i32 0, i32 18
  %28 = load ptr, ptr %27, align 8, !tbaa !10
  %29 = getelementptr inbounds %struct._usbd_driver, ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = add i32 %25, %30
  %32 = zext i32 %31 to i64
  %33 = inttoptr i64 %32 to ptr
  %34 = load volatile i32, ptr %33, align 4, !tbaa !19
  %35 = or i32 %34, 134217728
  store volatile i32 %35, ptr %33, align 4, !tbaa !19
  br label %51

36:                                               ; preds = %12
  %37 = load i8, ptr %5, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = mul nsw i32 32, %38
  %40 = add nsw i32 2816, %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._usbd_device, ptr %41, i32 0, i32 18
  %43 = load ptr, ptr %42, align 8, !tbaa !10
  %44 = getelementptr inbounds %struct._usbd_driver, ptr %43, i32 0, i32 11
  %45 = load i32, ptr %44, align 8, !tbaa !17
  %46 = add i32 %40, %45
  %47 = zext i32 %46 to i64
  %48 = inttoptr i64 %47 to ptr
  %49 = load volatile i32, ptr %48, align 4, !tbaa !19
  %50 = or i32 %49, 67108864
  store volatile i32 %50, ptr %48, align 4, !tbaa !19
  br label %51

51:                                               ; preds = %36, %21, %11
  ret void
}

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: nofree norecurse nounwind uwtable
define dso_local void @dwc_ep_nak_set(ptr nocapture noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %.not = icmp sgt i8 %1, -1
  br i1 %.not, label %.sink.split, label %19

.sink.split:                                      ; preds = %3
  %4 = zext nneg i8 %1 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 436
  %6 = zext nneg i8 %1 to i64
  %7 = getelementptr inbounds [4 x i8], ptr %5, i64 0, i64 %6
  store i8 %2, ptr %7, align 1, !tbaa !5
  %.not8 = icmp eq i8 %2, 0
  %8 = shl nuw nsw i32 %4, 5
  %9 = add nuw nsw i32 %8, 2816
  %10 = getelementptr inbounds i8, ptr %0, i64 424
  %11 = load ptr, ptr %10, align 8, !tbaa !8
  %12 = getelementptr inbounds i8, ptr %11, i64 88
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = add i32 %9, %13
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  %17 = load volatile i32, ptr %16, align 4, !tbaa !18
  %. = select i1 %.not8, i32 67108864, i32 134217728
  %18 = or i32 %17, %.
  store volatile i32 %18, ptr %16, align 4, !tbaa !18
  br label %19

19:                                               ; preds = %.sink.split, %3
  ret void
}

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


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