; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (Open)

; 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.PCD_HandleTypeDef = type { ptr, %struct.USB_OTG_CfgTypeDef, i8, [16 x %struct.USB_OTG_EPTypeDef], [16 x %struct.USB_OTG_EPTypeDef], i32, i32, i32, [12 x i32], i32, i32, i32, i32, ptr }
%struct.USB_OTG_CfgTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }

; 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 i32 @HAL_PCD_EP_Open(ptr noundef %0, i8 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i16, align 2
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store i16 %2, ptr %8, align 2, !tbaa !10
  store i8 %3, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load i8, ptr %7, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = and i32 %14, 128
  %16 = icmp eq i32 %15, 128
  br i1 %16, label %17, label %27

17:                                               ; preds = %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %18, i32 0, i32 3
  %20 = load i8, ptr %7, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = and i32 %21, 15
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %19, i64 0, i64 %23
  store ptr %24, ptr %11, align 8, !tbaa !5
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %25, i32 0, i32 1
  store i8 1, ptr %26, align 1, !tbaa !14
  br label %37

27:                                               ; preds = %4
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %28, i32 0, i32 4
  %30 = load i8, ptr %7, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 15
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %29, i64 0, i64 %33
  store ptr %34, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %35, i32 0, i32 1
  store i8 0, ptr %36, align 1, !tbaa !14
  br label %37

37:                                               ; preds = %27, %17
  %38 = load i8, ptr %7, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 15
  %41 = trunc i32 %40 to i8
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %42, i32 0, i32 0
  store i8 %41, ptr %43, align 8, !tbaa !16
  %44 = load i16, ptr %8, align 2, !tbaa !10
  %45 = zext i16 %44 to i32
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %46, i32 0, i32 7
  store i32 %45, ptr %47, align 8, !tbaa !17
  %48 = load i8, ptr %9, align 1, !tbaa !9
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %49, i32 0, i32 3
  store i8 %48, ptr %50, align 1, !tbaa !18
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %51, i32 0, i32 1
  %53 = load i8, ptr %52, align 1, !tbaa !14
  %54 = zext i8 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %63

56:                                               ; preds = %37
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %57, i32 0, i32 0
  %59 = load i8, ptr %58, align 8, !tbaa !16
  %60 = zext i8 %59 to i16
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %61, i32 0, i32 6
  store i16 %60, ptr %62, align 2, !tbaa !19
  br label %63

63:                                               ; preds = %56, %37
  %64 = load i8, ptr %9, align 1, !tbaa !9
  %65 = zext i8 %64 to i32
  %66 = icmp eq i32 %65, 2
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %68, i32 0, i32 4
  store i8 0, ptr %69, align 4, !tbaa !20
  br label %70

70:                                               ; preds = %67, %63
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %72, i32 0, i32 5
  %74 = load i32, ptr %73, align 8, !tbaa !21
  %75 = icmp eq i32 %74, 1
  br i1 %75, label %76, label %77

76:                                               ; preds = %71
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

77:                                               ; preds = %71
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %78, i32 0, i32 5
  store i32 1, ptr %79, align 8, !tbaa !21
  br label %80

80:                                               ; preds = %77
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !24
  %86 = load ptr, ptr %11, align 8, !tbaa !5
  %87 = call i32 @USB_ActivateEndpoint(ptr noundef %85, ptr noundef %86)
  br label %88

88:                                               ; preds = %82
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %89, i32 0, i32 5
  store i32 0, ptr %90, align 8, !tbaa !21
  br label %91

91:                                               ; preds = %88
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %10, align 4, !tbaa !12
  store i32 %93, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

94:                                               ; preds = %92, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

declare i32 @USB_ActivateEndpoint(ptr noundef, ptr noundef) #2

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 = { "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 #3 = { 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, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !7, i64 1}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !11, i64 6, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32}
!16 = !{!15, !7, i64 0}
!17 = !{!15, !13, i64 8}
!18 = !{!15, !7, i64 3}
!19 = !{!15, !11, i64 6}
!20 = !{!15, !7, i64 4}
!21 = !{!22, !13, i64 1344}
!22 = !{!"", !6, i64 0, !23, i64 8, !7, i64 60, !7, i64 64, !7, i64 704, !13, i64 1344, !13, i64 1348, !13, i64 1352, !7, i64 1356, !13, i64 1404, !13, i64 1408, !13, i64 1412, !13, i64 1416, !6, i64 1424}
!23 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48}
!24 = !{!22, !6, 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"

%struct.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_PCD_EP_Open(ptr noundef %0, i8 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %.not = icmp sgt i8 %1, -1
  %5 = and i8 %1, 15
  %6 = zext nneg i8 %5 to i64
  %7 = and i8 %1, 15
  %8 = zext i16 %2 to i32
  br i1 %.not, label %.thread, label %14

.thread:                                          ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 704
  %10 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %9, i64 0, i64 %6
  %11 = getelementptr inbounds i8, ptr %10, i64 1
  store i8 0, ptr %11, align 1, !tbaa !5
  store i8 %7, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %10, i64 8
  store i32 %8, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %10, i64 3
  store i8 %3, ptr %13, align 1, !tbaa !14
  br label %22

14:                                               ; preds = %4
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  %16 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %15, i64 0, i64 %6
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  store i8 1, ptr %17, align 1, !tbaa !5
  store i8 %7, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  store i32 %8, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %16, i64 3
  store i8 %3, ptr %19, align 1, !tbaa !14
  %20 = zext nneg i8 %7 to i16
  %21 = getelementptr inbounds i8, ptr %16, i64 6
  store i16 %20, ptr %21, align 2, !tbaa !15
  br label %22

22:                                               ; preds = %.thread, %14
  %.027 = phi ptr [ %10, %.thread ], [ %16, %14 ]
  %23 = icmp eq i8 %3, 2
  br i1 %23, label %24, label %26

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %.027, i64 4
  store i8 0, ptr %25, align 4, !tbaa !16
  br label %26

26:                                               ; preds = %22, %24
  %27 = getelementptr inbounds i8, ptr %0, i64 1344
  %28 = load i32, ptr %27, align 8, !tbaa !17
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %33, label %30

30:                                               ; preds = %26
  store i32 1, ptr %27, align 8, !tbaa !17
  %31 = load ptr, ptr %0, align 8, !tbaa !20
  %32 = tail call i32 @USB_ActivateEndpoint(ptr noundef %31, ptr noundef nonnull %.027) #2
  store i32 0, ptr %27, align 8, !tbaa !17
  br label %33

33:                                               ; preds = %26, %30
  %.024 = phi i32 [ 0, %30 ], [ 2, %26 ]
  ret i32 %.024
}

declare i32 @USB_ActivateEndpoint(ptr noundef, ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { "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, !7, i64 1}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !9, i64 6, !10, i64 8, !11, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 3}
!15 = !{!6, !9, i64 6}
!16 = !{!6, !7, i64 4}
!17 = !{!18, !10, i64 1344}
!18 = !{!"", !11, i64 0, !19, i64 8, !7, i64 60, !7, i64 64, !7, i64 704, !10, i64 1344, !10, i64 1348, !10, i64 1352, !7, i64 1356, !10, i64 1404, !10, i64 1408, !10, i64 1412, !10, i64 1416, !11, i64 1424}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48}
!20 = !{!18, !11, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass