; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_ll_usb)

; 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.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 i32 @USB_SetCurrentMode(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %8, i32 0, i32 3
  %10 = load volatile i32, ptr %9, align 4, !tbaa !11
  %11 = zext i32 %10 to i64
  %12 = and i64 %11, -1610612737
  %13 = trunc i64 %12 to i32
  store volatile i32 %13, ptr %9, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %36

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %17, i32 0, i32 3
  %19 = load volatile i32, ptr %18, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = or i64 %20, 536870912
  %22 = trunc i64 %21 to i32
  store volatile i32 %22, ptr %18, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %33, %16
  call void @HAL_Delay(i32 noundef 1)
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i32 @USB_GetMode(ptr noundef %27)
  %29 = icmp ne i32 %28, 1
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp ult i32 %31, 50
  br label %33

33:                                               ; preds = %30, %26
  %34 = phi i1 [ false, %26 ], [ %32, %30 ]
  br i1 %34, label %23, label %35, !llvm.loop !13

35:                                               ; preds = %33
  br label %61

36:                                               ; preds = %2
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %59

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %40, i32 0, i32 3
  %42 = load volatile i32, ptr %41, align 4, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = or i64 %43, 1073741824
  %45 = trunc i64 %44 to i32
  store volatile i32 %45, ptr %41, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %56, %39
  call void @HAL_Delay(i32 noundef 1)
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = add i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %46
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call i32 @USB_GetMode(ptr noundef %50)
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %49
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = icmp ult i32 %54, 50
  br label %56

56:                                               ; preds = %53, %49
  %57 = phi i1 [ false, %49 ], [ %55, %53 ]
  br i1 %57, label %46, label %58, !llvm.loop !15

58:                                               ; preds = %56
  br label %60

59:                                               ; preds = %36
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %66

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60, %35
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp eq i32 %62, 50
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %66

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

66:                                               ; preds = %65, %64, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %67 = load i32, ptr %3, align 4
  ret i32 %67
}

declare void @HAL_Delay(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @USB_GetMode(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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"", !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, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 100, !10, i64 256, !7, i64 260}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 range(i32 0, 2) i32 @USB_SetCurrentMode(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load volatile i32, ptr %3, align 4, !tbaa !5
  %5 = and i32 %4, -1610612737
  store volatile i32 %5, ptr %3, align 4, !tbaa !5
  switch i32 %1, label %25 [
    i32 1, label %6
    i32 0, label %15
  ]

6:                                                ; preds = %2
  %7 = load volatile i32, ptr %3, align 4, !tbaa !5
  %8 = or i32 %7, 536870912
  store volatile i32 %8, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %9, %6
  %.0 = phi i32 [ 0, %6 ], [ %10, %9 ]
  tail call void @HAL_Delay(i32 noundef 1) #2
  %10 = add nuw nsw i32 %.0, 1
  %11 = tail call i32 @USB_GetMode(ptr noundef %0)
  %12 = icmp ne i32 %11, 1
  %13 = icmp ult i32 %.0, 49
  %14 = select i1 %12, i1 %13, i1 false
  br i1 %14, label %9, label %.loopexit, !llvm.loop !10

15:                                               ; preds = %2
  %16 = load volatile i32, ptr %3, align 4, !tbaa !5
  %17 = or i32 %16, 1073741824
  store volatile i32 %17, ptr %3, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %18, %15
  %.1 = phi i32 [ 0, %15 ], [ %19, %18 ]
  tail call void @HAL_Delay(i32 noundef 1) #2
  %19 = add nuw nsw i32 %.1, 1
  %20 = tail call i32 @USB_GetMode(ptr noundef %0)
  %21 = icmp ne i32 %20, 0
  %22 = icmp ult i32 %.1, 49
  %23 = select i1 %21, i1 %22, i1 false
  br i1 %23, label %18, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %18, %9
  %.2 = phi i32 [ %10, %9 ], [ %19, %18 ]
  %24 = icmp eq i32 %.2, 50
  %. = zext i1 %24 to i32
  br label %25

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

declare void @HAL_Delay(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @USB_GetMode(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 12}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !8, i64 48, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !8, i64 100, !7, i64 256, !8, i64 260}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass