; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/Src (stm32h7xx_hal_pcd)

; 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_CfgTypeDef, i8, [16 x %struct.USB_EPTypeDef], [16 x %struct.USB_EPTypeDef], i32, i32, i32, [12 x i32], i32, i32, i32, i32, i32, ptr }
%struct.USB_CfgTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i32, ptr, i32, i32, i8, i16, i32, i32 }
%struct.USB_OTG_GlobalTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [39 x i32], i32, [15 x i32] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @USB_DisableGlobalInt(ptr noundef) #1

declare i32 @USB_DevDisconnect(ptr noundef) #1

; 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_Stop(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %4, align 8, !tbaa !5
  br label %9

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

14:                                               ; preds = %9
  store i32 2, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %57

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %16, i32 0, i32 5
  store i32 1, ptr %17, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call i32 @USB_DisableGlobalInt(ptr noundef %23)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i32 @USB_DevDisconnect(ptr noundef %27)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i32 @USB_FlushTxFifo(ptr noundef %31, i32 noundef 16)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %33, i32 0, i32 14
  %35 = load volatile i32, ptr %34, align 4, !tbaa !14
  %36 = and i32 %35, 256
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %51

38:                                               ; preds = %20
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds %struct.USB_CfgTypeDef, ptr %40, i32 0, i32 9
  %42 = load i32, ptr %41, align 4, !tbaa !16
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %51

44:                                               ; preds = %38
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %45, i32 0, i32 13
  %47 = load volatile i32, ptr %46, align 4, !tbaa !17
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, -65537
  %50 = trunc i64 %49 to i32
  store volatile i32 %50, ptr %46, align 4, !tbaa !17
  br label %51

51:                                               ; preds = %44, %38, %20
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %53, i32 0, i32 5
  store i32 0, ptr %54, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %57

57:                                               ; preds = %56, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %58 = load i32, ptr %2, align 4
  ret i32 %58
}

declare i32 @USB_FlushTxFifo(ptr noundef, i32 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 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 60, !7, i64 64, !7, i64 832, !12, i64 1600, !12, i64 1604, !12, i64 1608, !7, i64 1612, !12, i64 1660, !12, i64 1664, !12, i64 1668, !12, i64 1672, !12, i64 1676, !6, i64 1680}
!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, !12, i64 1600}
!14 = !{!15, !12, i64 60}
!15 = !{!"", !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, !7, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !12, i64 96, !7, i64 100, !12, i64 256, !7, i64 260}
!16 = !{!10, !12, i64 44}
!17 = !{!15, !12, i64 56}


; 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 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 1600
  %4 = load i32, ptr %3, align 8, !tbaa !12
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %25, label %6

6:                                                ; preds = %1
  store i32 1, ptr %3, align 8, !tbaa !12
  %7 = tail call i32 @USB_DisableGlobalInt(ptr noundef %2) #2
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = tail call i32 @USB_DevDisconnect(ptr noundef %8) #2
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = tail call i32 @USB_FlushTxFifo(ptr noundef %10, i32 noundef 16) #2
  %12 = getelementptr inbounds i8, ptr %2, i64 60
  %13 = load volatile i32, ptr %12, align 4, !tbaa !13
  %14 = and i32 %13, 256
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %24

16:                                               ; preds = %6
  %17 = getelementptr inbounds i8, ptr %0, i64 44
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %2, i64 56
  %22 = load volatile i32, ptr %21, align 4, !tbaa !16
  %23 = and i32 %22, -65537
  store volatile i32 %23, ptr %21, align 4, !tbaa !16
  br label %24

24:                                               ; preds = %6, %16, %20
  store i32 0, ptr %3, align 8, !tbaa !12
  br label %25

25:                                               ; preds = %1, %24
  %.0 = phi i32 [ 0, %24 ], [ 2, %1 ]
  ret i32 %.0
}

declare i32 @USB_FlushTxFifo(ptr noundef, i32 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !8, i64 60, !8, i64 64, !8, i64 832, !11, i64 1600, !11, i64 1604, !11, i64 1608, !8, i64 1612, !11, i64 1660, !11, i64 1664, !11, i64 1668, !11, i64 1672, !11, i64 1676, !7, i64 1680}
!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, !11, i64 1600}
!13 = !{!14, !11, i64 60}
!14 = !{!"", !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, !8, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !8, i64 100, !11, i64 256, !8, i64 260}
!15 = !{!6, !11, i64 44}
!16 = !{!14, !11, i64 56}


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