; 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 void @dwc_endpoints_reset(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._usbd_device, ptr %4, i32 0, i32 20
  %6 = load i16, ptr %5, align 2, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._usbd_device, ptr %7, i32 0, i32 19
  store i16 %6, ptr %8, align 8, !tbaa !16
  store i32 1, ptr %3, align 4, !tbaa !17
  br label %9

9:                                                ; preds = %71, %1
  %10 = load i32, ptr %3, align 4, !tbaa !17
  %11 = icmp slt i32 %10, 4
  br i1 %11, label %12, label %74

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !17
  %14 = mul nsw i32 32, %13
  %15 = add nsw i32 2816, %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._usbd_device, ptr %16, i32 0, i32 18
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = getelementptr inbounds %struct._usbd_driver, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 8, !tbaa !19
  %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 !17
  %25 = and i32 %24, -2147483648
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %41

27:                                               ; preds = %12
  %28 = load i32, ptr %3, align 4, !tbaa !17
  %29 = mul nsw i32 32, %28
  %30 = add nsw i32 2816, %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._usbd_device, ptr %31, i32 0, i32 18
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = getelementptr inbounds %struct._usbd_driver, ptr %33, i32 0, i32 11
  %35 = load i32, ptr %34, align 8, !tbaa !19
  %36 = add i32 %30, %35
  %37 = zext i32 %36 to i64
  %38 = inttoptr i64 %37 to ptr
  %39 = load volatile i32, ptr %38, align 4, !tbaa !17
  %40 = or i32 %39, 1073741824
  store volatile i32 %40, ptr %38, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %27, %12
  %42 = load i32, ptr %3, align 4, !tbaa !17
  %43 = mul nsw i32 32, %42
  %44 = add nsw i32 2304, %43
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._usbd_device, ptr %45, i32 0, i32 18
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct._usbd_driver, ptr %47, i32 0, i32 11
  %49 = load i32, ptr %48, align 8, !tbaa !19
  %50 = add i32 %44, %49
  %51 = zext i32 %50 to i64
  %52 = inttoptr i64 %51 to ptr
  %53 = load volatile i32, ptr %52, align 4, !tbaa !17
  %54 = and i32 %53, -2147483648
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %70

56:                                               ; preds = %41
  %57 = load i32, ptr %3, align 4, !tbaa !17
  %58 = mul nsw i32 32, %57
  %59 = add nsw i32 2304, %58
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._usbd_device, ptr %60, i32 0, i32 18
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = getelementptr inbounds %struct._usbd_driver, ptr %62, i32 0, i32 11
  %64 = load i32, ptr %63, align 8, !tbaa !19
  %65 = add i32 %59, %64
  %66 = zext i32 %65 to i64
  %67 = inttoptr i64 %66 to ptr
  %68 = load volatile i32, ptr %67, align 4, !tbaa !17
  %69 = or i32 %68, 1073741824
  store volatile i32 %69, ptr %67, align 4, !tbaa !17
  br label %70

70:                                               ; preds = %56, %41
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %3, align 4, !tbaa !17
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !17
  br label %9, !llvm.loop !21

74:                                               ; preds = %9
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._usbd_device, ptr %75, i32 0, i32 18
  %77 = load ptr, ptr %76, align 8, !tbaa !18
  %78 = getelementptr inbounds %struct._usbd_driver, ptr %77, i32 0, i32 11
  %79 = load i32, ptr %78, align 8, !tbaa !19
  %80 = add i32 16, %79
  %81 = zext i32 %80 to i64
  %82 = inttoptr i64 %81 to ptr
  store volatile i32 1072, ptr %82, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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

13:                                               ; preds = %1
  %14 = load volatile i32, ptr %11, align 4, !tbaa !19
  %15 = or i32 %14, 1073741824
  store volatile i32 %15, ptr %11, align 4, !tbaa !19
  %.pre = load i32, ptr %7, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %13, %1
  %17 = phi i32 [ %.pre, %13 ], [ %8, %1 ]
  %18 = add i32 %17, 2336
  %19 = zext i32 %18 to i64
  %20 = inttoptr i64 %19 to ptr
  %21 = load volatile i32, ptr %20, align 4, !tbaa !19
  %.not12 = icmp sgt i32 %21, -1
  br i1 %.not12, label %25, label %22

22:                                               ; preds = %16
  %23 = load volatile i32, ptr %20, align 4, !tbaa !19
  %24 = or i32 %23, 1073741824
  store volatile i32 %24, ptr %20, align 4, !tbaa !19
  %.pre14 = load i32, ptr %7, align 8, !tbaa !17
  br label %25

25:                                               ; preds = %16, %22
  %26 = phi i32 [ %17, %16 ], [ %.pre14, %22 ]
  %27 = add i32 %26, 2880
  %28 = zext i32 %27 to i64
  %29 = inttoptr i64 %28 to ptr
  %30 = load volatile i32, ptr %29, align 4, !tbaa !19
  %.not.1 = icmp sgt i32 %30, -1
  br i1 %.not.1, label %34, label %31

31:                                               ; preds = %25
  %32 = load volatile i32, ptr %29, align 4, !tbaa !19
  %33 = or i32 %32, 1073741824
  store volatile i32 %33, ptr %29, align 4, !tbaa !19
  %.pre15 = load i32, ptr %7, align 8, !tbaa !17
  br label %34

34:                                               ; preds = %31, %25
  %35 = phi i32 [ %.pre15, %31 ], [ %26, %25 ]
  %36 = add i32 %35, 2368
  %37 = zext i32 %36 to i64
  %38 = inttoptr i64 %37 to ptr
  %39 = load volatile i32, ptr %38, align 4, !tbaa !19
  %.not12.1 = icmp sgt i32 %39, -1
  br i1 %.not12.1, label %43, label %40

40:                                               ; preds = %34
  %41 = load volatile i32, ptr %38, align 4, !tbaa !19
  %42 = or i32 %41, 1073741824
  store volatile i32 %42, ptr %38, align 4, !tbaa !19
  %.pre16 = load i32, ptr %7, align 8, !tbaa !17
  br label %43

43:                                               ; preds = %40, %34
  %44 = phi i32 [ %.pre16, %40 ], [ %35, %34 ]
  %45 = add i32 %44, 2912
  %46 = zext i32 %45 to i64
  %47 = inttoptr i64 %46 to ptr
  %48 = load volatile i32, ptr %47, align 4, !tbaa !19
  %.not.2 = icmp sgt i32 %48, -1
  br i1 %.not.2, label %52, label %49

49:                                               ; preds = %43
  %50 = load volatile i32, ptr %47, align 4, !tbaa !19
  %51 = or i32 %50, 1073741824
  store volatile i32 %51, ptr %47, align 4, !tbaa !19
  %.pre17 = load i32, ptr %7, align 8, !tbaa !17
  br label %52

52:                                               ; preds = %49, %43
  %53 = phi i32 [ %.pre17, %49 ], [ %44, %43 ]
  %54 = add i32 %53, 2400
  %55 = zext i32 %54 to i64
  %56 = inttoptr i64 %55 to ptr
  %57 = load volatile i32, ptr %56, align 4, !tbaa !19
  %.not12.2 = icmp sgt i32 %57, -1
  br i1 %.not12.2, label %61, label %58

58:                                               ; preds = %52
  %59 = load volatile i32, ptr %56, align 4, !tbaa !19
  %60 = or i32 %59, 1073741824
  store volatile i32 %60, ptr %56, align 4, !tbaa !19
  %.pre18 = load i32, ptr %7, align 8, !tbaa !17
  br label %61

61:                                               ; preds = %58, %52
  %62 = phi i32 [ %.pre18, %58 ], [ %53, %52 ]
  %63 = add i32 %62, 16
  %64 = zext i32 %63 to i64
  %65 = inttoptr i64 %64 to ptr
  store volatile i32 1072, ptr %65, align 4, !tbaa !19
  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, !11, i64 434}
!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 = !{!6, !11, i64 432}
!16 = !{!6, !7, i64 424}
!17 = !{!18, !10, i64 88}
!18 = !{!"_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}
!19 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass