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

; 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

; 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 void @HAL_PCDEx_BCD_VBUSDetect(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.PCD_HandleTypeDef, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = call i32 @HAL_GetTick()
  store i32 %8, ptr %4, align 4, !tbaa !13
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %9, i32 0, i32 13
  %11 = load volatile i32, ptr %10, align 4, !tbaa !14
  %12 = zext i32 %11 to i64
  %13 = or i64 %12, 262144
  %14 = trunc i64 %13 to i32
  store volatile i32 %14, ptr %10, align 4, !tbaa !14
  call void @HAL_Delay(i32 noundef 300)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %15, i32 0, i32 13
  %17 = load volatile i32, ptr %16, align 4, !tbaa !14
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 1
  %20 = icmp eq i64 %19, 1
  br i1 %20, label %21, label %23

21:                                               ; preds = %1
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %22, i32 noundef 254)
  br label %23

23:                                               ; preds = %21, %1
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %24, i32 0, i32 13
  %26 = load volatile i32, ptr %25, align 4, !tbaa !14
  %27 = zext i32 %26 to i64
  %28 = and i64 %27, -262145
  %29 = trunc i64 %28 to i32
  store volatile i32 %29, ptr %25, align 4, !tbaa !14
  call void @HAL_Delay(i32 noundef 50)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %30, i32 0, i32 13
  %32 = load volatile i32, ptr %31, align 4, !tbaa !14
  %33 = zext i32 %32 to i64
  %34 = or i64 %33, 524288
  %35 = trunc i64 %34 to i32
  store volatile i32 %35, ptr %31, align 4, !tbaa !14
  call void @HAL_Delay(i32 noundef 50)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %36, i32 0, i32 13
  %38 = load volatile i32, ptr %37, align 4, !tbaa !14
  %39 = zext i32 %38 to i64
  %40 = and i64 %39, 2
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %23
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %43, i32 noundef 253)
  br label %68

44:                                               ; preds = %23
  %45 = load ptr, ptr %3, 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 !14
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, -524289
  %50 = trunc i64 %49 to i32
  store volatile i32 %50, ptr %46, align 4, !tbaa !14
  call void @HAL_Delay(i32 noundef 50)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %51, i32 0, i32 13
  %53 = load volatile i32, ptr %52, align 4, !tbaa !14
  %54 = zext i32 %53 to i64
  %55 = or i64 %54, 1048576
  %56 = trunc i64 %55 to i32
  store volatile i32 %56, ptr %52, align 4, !tbaa !14
  call void @HAL_Delay(i32 noundef 50)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %57, i32 0, i32 13
  %59 = load volatile i32, ptr %58, align 4, !tbaa !14
  %60 = zext i32 %59 to i64
  %61 = and i64 %60, 4
  %62 = icmp eq i64 %61, 4
  br i1 %62, label %63, label %65

63:                                               ; preds = %44
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %64, i32 noundef 251)
  br label %67

65:                                               ; preds = %44
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %66, i32 noundef 252)
  br label %67

67:                                               ; preds = %65, %63
  br label %68

68:                                               ; preds = %67, %42
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = call i32 @HAL_PCDEx_DeActivateBCD(ptr noundef %69)
  %71 = call i32 @HAL_GetTick()
  %72 = load i32, ptr %4, align 4, !tbaa !13
  %73 = sub i32 %71, %72
  %74 = icmp ugt i32 %73, 1000
  br i1 %74, label %75, label %77

75:                                               ; preds = %68
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %76, i32 noundef 255)
  br label %79

77:                                               ; preds = %68
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  call void @HAL_PCDEx_BCD_Callback(ptr noundef %78, i32 noundef 0)
  br label %79

79:                                               ; preds = %77, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare i32 @HAL_GetTick() #2

declare void @HAL_Delay(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_PCDEx_BCD_Callback(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @HAL_PCDEx_DeActivateBCD(ptr noundef) #1

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 = !{!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 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 56}
!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}


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

; Function Attrs: nounwind uwtable
define dso_local void @HAL_PCDEx_BCD_VBUSDetect(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call i32 @HAL_GetTick() #2
  %4 = getelementptr inbounds i8, ptr %2, i64 56
  %5 = load volatile i32, ptr %4, align 4, !tbaa !12
  %6 = or i32 %5, 262144
  store volatile i32 %6, ptr %4, align 4, !tbaa !12
  tail call void @HAL_Delay(i32 noundef 300) #2
  %7 = load volatile i32, ptr %4, align 4, !tbaa !12
  %8 = and i32 %7, 1
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %1
  tail call void @HAL_PCDEx_BCD_Callback(ptr noundef nonnull %0, i32 noundef 254)
  br label %10

10:                                               ; preds = %9, %1
  %11 = load volatile i32, ptr %4, align 4, !tbaa !12
  %12 = and i32 %11, -262145
  store volatile i32 %12, ptr %4, align 4, !tbaa !12
  tail call void @HAL_Delay(i32 noundef 50) #2
  %13 = load volatile i32, ptr %4, align 4, !tbaa !12
  %14 = or i32 %13, 524288
  store volatile i32 %14, ptr %4, align 4, !tbaa !12
  tail call void @HAL_Delay(i32 noundef 50) #2
  %15 = load volatile i32, ptr %4, align 4, !tbaa !12
  %16 = and i32 %15, 2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %25, label %18

18:                                               ; preds = %10
  %19 = load volatile i32, ptr %4, align 4, !tbaa !12
  %20 = and i32 %19, -524289
  store volatile i32 %20, ptr %4, align 4, !tbaa !12
  tail call void @HAL_Delay(i32 noundef 50) #2
  %21 = load volatile i32, ptr %4, align 4, !tbaa !12
  %22 = or i32 %21, 1048576
  store volatile i32 %22, ptr %4, align 4, !tbaa !12
  tail call void @HAL_Delay(i32 noundef 50) #2
  %23 = load volatile i32, ptr %4, align 4, !tbaa !12
  %24 = and i32 %23, 4
  %.not16 = icmp eq i32 %24, 0
  %. = select i1 %.not16, i32 252, i32 251
  br label %25

25:                                               ; preds = %18, %10
  %.sink = phi i32 [ 253, %10 ], [ %., %18 ]
  tail call void @HAL_PCDEx_BCD_Callback(ptr noundef nonnull %0, i32 noundef %.sink)
  %26 = tail call i32 @HAL_PCDEx_DeActivateBCD(ptr noundef nonnull %0)
  %27 = tail call i32 @HAL_GetTick() #2
  %28 = sub i32 %27, %3
  %29 = icmp ugt i32 %28, 1000
  %.18 = select i1 %29, i32 255, i32 0
  tail call void @HAL_PCDEx_BCD_Callback(ptr noundef nonnull %0, i32 noundef %.18)
  ret void
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

declare void @HAL_Delay(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_PCDEx_BCD_Callback(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @HAL_PCDEx_DeActivateBCD(ptr noundef) local_unnamed_addr #0

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 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 = !{!13, !11, i64 56}
!13 = !{!"", !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}


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