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

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

16:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

17:                                               ; preds = %2
  %18 = load i8, ptr %5, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = and i32 128, %19
  %21 = icmp eq i32 %20, 128
  br i1 %21, label %22, label %32

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %23, i32 0, i32 3
  %25 = load i8, ptr %5, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = and i32 %26, 15
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %24, i64 0, i64 %28
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %30, i32 0, i32 1
  store i8 1, ptr %31, align 1, !tbaa !14
  br label %42

32:                                               ; preds = %17
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %33, i32 0, i32 4
  %35 = load i8, ptr %5, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 15
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %34, i64 0, i64 %38
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %40, i32 0, i32 1
  store i8 0, ptr %41, align 1, !tbaa !14
  br label %42

42:                                               ; preds = %32, %22
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %43, i32 0, i32 2
  store i8 0, ptr %44, align 2, !tbaa !17
  %45 = load i8, ptr %5, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 15
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %49, i32 0, i32 0
  store i8 %48, ptr %50, align 8, !tbaa !18
  br label %51

51:                                               ; preds = %42
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %52, i32 0, i32 5
  %54 = load i32, ptr %53, align 8, !tbaa !19
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

57:                                               ; preds = %51
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %58, i32 0, i32 5
  store i32 1, ptr %59, align 8, !tbaa !19
  br label %60

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = call i32 @USB_EPClearStall(ptr noundef %65, ptr noundef %66)
  br label %68

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %69, i32 0, i32 5
  store i32 0, ptr %70, align 8, !tbaa !19
  br label %71

71:                                               ; preds = %68
  br label %72

72:                                               ; preds = %71
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %72, %56, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

declare i32 @USB_EPClearStall(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, !13, i64 8}
!11 = !{!"", !6, i64 0, !12, 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}
!12 = !{!"", !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}
!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, !16, i64 6, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !7, i64 2}
!18 = !{!15, !7, i64 0}
!19 = !{!11, !13, i64 1344}
!20 = !{!11, !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_ClrStall(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = and i8 %1, 15
  %4 = zext nneg i8 %3 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp ult i32 %6, %4
  br i1 %7, label %20, label %8

8:                                                ; preds = %2
  %.not = icmp slt i8 %1, 0
  %9 = zext nneg i8 %3 to i64
  %. = select i1 %.not, i64 64, i64 704
  %.lobit = lshr i8 %1, 7
  %10 = getelementptr inbounds i8, ptr %0, i64 %.
  %11 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %10, i64 0, i64 %9
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  store i8 %.lobit, ptr %12, align 1, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %11, i64 2
  store i8 0, ptr %13, align 2, !tbaa !15
  store i8 %3, ptr %11, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 1344
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %20, label %17

17:                                               ; preds = %8
  store i32 1, ptr %14, align 8, !tbaa !17
  %18 = load ptr, ptr %0, align 8, !tbaa !18
  %19 = tail call i32 @USB_EPClearStall(ptr noundef %18, ptr noundef nonnull %11) #2
  store i32 0, ptr %14, align 8, !tbaa !17
  br label %20

20:                                               ; preds = %8, %2, %17
  %.017 = phi i32 [ 0, %17 ], [ 1, %2 ], [ 2, %8 ]
  ret i32 %.017
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass