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

; 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_Close(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, 128
  %11 = icmp eq i32 %10, 128
  br i1 %11, label %12, label %22

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

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %23, i32 0, i32 4
  %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 0, ptr %31, align 1, !tbaa !10
  br label %32

32:                                               ; preds = %22, %12
  %33 = load i8, ptr %5, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = and i32 %34, 15
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %37, i32 0, i32 0
  store i8 %36, ptr %38, align 8, !tbaa !14
  br label %39

39:                                               ; preds = %32
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %61

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %46, i32 0, i32 5
  store i32 1, ptr %47, align 8, !tbaa !15
  br label %48

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call i32 @USB_DeactivateEndpoint(ptr noundef %53, ptr noundef %54)
  br label %56

56:                                               ; preds = %50
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %57, i32 0, i32 5
  store i32 0, ptr %58, align 8, !tbaa !15
  br label %59

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %61

61:                                               ; preds = %60, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %62 = load i32, ptr %3, align 4
  ret i32 %62
}

declare i32 @USB_DeactivateEndpoint(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, !7, i64 1}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !12, i64 6, !13, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !13, i64 32}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !7, i64 0}
!15 = !{!16, !13, i64 1344}
!16 = !{!"", !6, i64 0, !17, 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}
!17 = !{!"", !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}
!18 = !{!16, !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_Close(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %.not = icmp slt i8 %1, 0
  %3 = and i8 %1, 15
  %4 = zext nneg i8 %3 to i64
  %. = select i1 %.not, i64 64, i64 704
  %.lobit = lshr i8 %1, 7
  %5 = getelementptr inbounds i8, ptr %0, i64 %.
  %6 = getelementptr inbounds [16 x %struct.USB_OTG_EPTypeDef], ptr %5, i64 0, i64 %4
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  store i8 %.lobit, ptr %7, align 1, !tbaa !5
  %8 = and i8 %1, 15
  store i8 %8, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 1344
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %15, label %12

12:                                               ; preds = %2
  store i32 1, ptr %9, align 8, !tbaa !13
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = tail call i32 @USB_DeactivateEndpoint(ptr noundef %13, ptr noundef nonnull %6) #2
  store i32 0, ptr %9, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %2, %12
  %.014 = phi i32 [ 0, %12 ], [ 2, %2 ]
  ret i32 %.014
}

declare i32 @USB_DeactivateEndpoint(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 = !{!14, !10, i64 1344}
!14 = !{!"", !11, i64 0, !15, 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}
!15 = !{!"", !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}
!16 = !{!14, !11, i64 0}


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