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

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

declare i32 @USB_DisableGlobalInt(ptr noundef) #0

declare i32 @USB_DevDisconnect(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_PCD_Stop(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %5, i32 0, i32 5
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %10

9:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  br label %38

10:                                               ; preds = %4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %11, i32 0, i32 5
  store i32 1, ptr %12, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = call i32 @USB_DisableGlobalInt(ptr noundef %17)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = call i32 @USB_StopDevice(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %29

24:                                               ; preds = %14
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %26, i32 0, i32 5
  store i32 0, ptr %27, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %25
  store i32 1, ptr %2, align 4
  br label %38

29:                                               ; preds = %14
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = call i32 @USB_DevDisconnect(ptr noundef %32)
  br label %34

34:                                               ; preds = %29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %35, i32 0, i32 5
  store i32 0, ptr %36, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %34
  store i32 0, ptr %2, align 4
  br label %38

38:                                               ; preds = %37, %28, %9
  %39 = load i32, ptr %2, align 4
  ret i32 %39
}

declare i32 @USB_StopDevice(ptr noundef) #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" }

!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 1344}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 60, !7, i64 64, !7, i64 704, !12, i64 1344, !12, i64 1348, !12, i64 1352, !7, i64 1356, !12, i64 1404, !12, i64 1408, !12, i64 1412, !12, i64 1416, !6, i64 1424}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !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"

declare i32 @USB_DisableGlobalInt(ptr noundef) local_unnamed_addr #0

declare i32 @USB_DevDisconnect(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_PCD_Stop(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 1344
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %13, label %5

5:                                                ; preds = %1
  store i32 1, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = tail call i32 @USB_DisableGlobalInt(ptr noundef %6) #2
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = tail call i32 @USB_StopDevice(ptr noundef %8) #2
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %.sink.split

10:                                               ; preds = %5
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = tail call i32 @USB_DevDisconnect(ptr noundef %11) #2
  br label %.sink.split

.sink.split:                                      ; preds = %5, %10
  %.0.ph = phi i32 [ 0, %10 ], [ 1, %5 ]
  store i32 0, ptr %2, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %.sink.split, %1
  %.0 = phi i32 [ 2, %1 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

declare i32 @USB_StopDevice(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 1344}
!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 = !{!6, !7, i64 0}


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