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

; 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

declare i32 @USB_EP0_OutStart(ptr noundef, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_PCD_EP_SetStall(ptr noundef %0, i8 noundef zeroext %1) #2 {
  %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 %89

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 %40

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 i64
  %37 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %34, i64 0, i64 %36
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %38, i32 0, i32 1
  store i8 0, ptr %39, align 1, !tbaa !14
  br label %40

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

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

54:                                               ; preds = %49
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

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

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = call i32 @USB_EPSetStall(ptr noundef %63, ptr noundef %64)
  %66 = load i8, ptr %5, align 1, !tbaa !9
  %67 = zext i8 %66 to i32
  %68 = and i32 %67, 15
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %83

70:                                               ; preds = %60
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %74, i32 0, i32 1
  %76 = getelementptr inbounds %struct.USB_OTG_CfgTypeDef, ptr %75, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !21
  %78 = trunc i32 %77 to i8
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %79, i32 0, i32 8
  %81 = getelementptr inbounds [12 x i32], ptr %80, i64 0, i64 0
  %82 = call i32 @USB_EP0_OutStart(ptr noundef %73, i8 noundef zeroext %78, ptr noundef %81)
  br label %83

83:                                               ; preds = %70, %60
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %85, i32 0, i32 5
  store i32 0, ptr %86, align 8, !tbaa !19
  br label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

89:                                               ; preds = %88, %54, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %90 = load i32, ptr %3, align 4
  ret i32 %90
}

declare i32 @USB_EPSetStall(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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}
!21 = !{!11, !13, i64 20}


; 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 }

declare i32 @USB_EP0_OutStart(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_PCD_EP_SetStall(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %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 %29, label %8

8:                                                ; preds = %2
  %.not = icmp slt i8 %1, 0
  %. = select i1 %.not, i64 64, i64 704
  %.29 = select i1 %.not, i8 %3, i8 %1
  %.lobit = lshr i8 %1, 7
  %9 = getelementptr inbounds i8, ptr %0, i64 %.
  %10 = zext nneg i8 %.29 to i64
  %11 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %9, i64 0, i64 %10
  %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 1, 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 %29, 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_EPSetStall(ptr noundef %18, ptr noundef nonnull %11) #2
  %20 = icmp eq i8 %3, 0
  br i1 %20, label %21, label %28

21:                                               ; preds = %17
  %22 = load ptr, ptr %0, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %0, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !19
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds i8, ptr %0, i64 1356
  %27 = tail call i32 @USB_EP0_OutStart(ptr noundef %22, i8 noundef zeroext %25, ptr noundef nonnull %26) #2
  br label %28

28:                                               ; preds = %17, %21
  store i32 0, ptr %14, align 8, !tbaa !17
  br label %29

29:                                               ; preds = %8, %2, %28
  %.021 = phi i32 [ 0, %28 ], [ 1, %2 ], [ 2, %8 ]
  ret i32 %.021
}

declare i32 @USB_EPSetStall(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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, !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}
!19 = !{!6, !11, i64 20}


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