; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_pwr_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.PWR_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SYSCFG_TypeDef = type { i32, i32, [4 x i32], i32, i32, i32, i32, i32, i32, [61 x i32], i32, [118 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

declare i32 @HAL_GetTick() #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_PWREx_ControlVoltageScaling(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %7 = zext i32 %6 to i64
  %8 = and i64 %7, 49152
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = icmp eq i64 %8, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

13:                                               ; preds = %1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %49

16:                                               ; preds = %13
  %17 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 3), align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 2
  %20 = icmp eq i64 %19, 2
  br i1 %20, label %21, label %47

21:                                               ; preds = %16
  %22 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 6), align 4, !tbaa !12
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, -49153
  %25 = or i64 %24, 49152
  %26 = trunc i64 %25 to i32
  store volatile i32 %26, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 6), align 4, !tbaa !12
  %27 = call i32 @HAL_GetTick()
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %41, %21
  %29 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = and i64 %30, 8192
  %32 = icmp eq i64 %31, 8192
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %28
  %36 = call i32 @HAL_GetTick()
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sub i32 %36, %37
  %39 = icmp ugt i32 %38, 1000
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

41:                                               ; preds = %35
  br label %28, !llvm.loop !13

42:                                               ; preds = %28
  %43 = load volatile i32, ptr getelementptr inbounds (%struct.SYSCFG_TypeDef, ptr inttoptr (i64 1476396032 to ptr), i32 0, i32 8), align 4, !tbaa !15
  %44 = zext i32 %43 to i64
  %45 = or i64 %44, 1
  %46 = trunc i64 %45 to i32
  store volatile i32 %46, ptr getelementptr inbounds (%struct.SYSCFG_TypeDef, ptr inttoptr (i64 1476396032 to ptr), i32 0, i32 8), align 4, !tbaa !15
  br label %48

47:                                               ; preds = %16
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

48:                                               ; preds = %42
  br label %89

49:                                               ; preds = %13
  %50 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = and i64 %51, 49152
  %53 = icmp eq i64 %52, 49152
  br i1 %53, label %54, label %81

54:                                               ; preds = %49
  %55 = load volatile i32, ptr getelementptr inbounds (%struct.SYSCFG_TypeDef, ptr inttoptr (i64 1476396032 to ptr), i32 0, i32 8), align 4, !tbaa !15
  %56 = zext i32 %55 to i64
  %57 = and i64 %56, 1
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %80

59:                                               ; preds = %54
  %60 = load volatile i32, ptr getelementptr inbounds (%struct.SYSCFG_TypeDef, ptr inttoptr (i64 1476396032 to ptr), i32 0, i32 8), align 4, !tbaa !15
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, -2
  %63 = trunc i64 %62 to i32
  store volatile i32 %63, ptr getelementptr inbounds (%struct.SYSCFG_TypeDef, ptr inttoptr (i64 1476396032 to ptr), i32 0, i32 8), align 4, !tbaa !15
  %64 = call i32 @HAL_GetTick()
  store i32 %64, ptr %4, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %78, %59
  %66 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = and i64 %67, 8192
  %69 = icmp eq i64 %68, 8192
  %70 = zext i1 %69 to i32
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %79

72:                                               ; preds = %65
  %73 = call i32 @HAL_GetTick()
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sub i32 %73, %74
  %76 = icmp ugt i32 %75, 1000
  br i1 %76, label %77, label %78

77:                                               ; preds = %72
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

78:                                               ; preds = %72
  br label %65, !llvm.loop !17

79:                                               ; preds = %65
  br label %80

80:                                               ; preds = %79, %54
  br label %81

81:                                               ; preds = %80, %49
  %82 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 6), align 4, !tbaa !12
  %83 = zext i32 %82 to i64
  %84 = and i64 %83, -49153
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = zext i32 %85 to i64
  %87 = or i64 %84, %86
  %88 = trunc i64 %87 to i32
  store volatile i32 %88, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 6), align 4, !tbaa !12
  br label %89

89:                                               ; preds = %81, %48
  %90 = call i32 @HAL_GetTick()
  store i32 %90, ptr %4, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %104, %89
  %92 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %93 = zext i32 %92 to i64
  %94 = and i64 %93, 8192
  %95 = icmp eq i64 %94, 8192
  %96 = zext i1 %95 to i32
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %105

98:                                               ; preds = %91
  %99 = call i32 @HAL_GetTick()
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = sub i32 %99, %100
  %102 = icmp ugt i32 %101, 1000
  br i1 %102, label %103, label %104

103:                                              ; preds = %98
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

104:                                              ; preds = %98
  br label %91, !llvm.loop !18

105:                                              ; preds = %91
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %106

106:                                              ; preds = %105, %103, %77, %47, %40, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %107 = load i32, ptr %2, align 4
  ret i32 %107
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40}
!11 = !{!10, !6, i64 12}
!12 = !{!10, !6, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 44}
!16 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !6, i64 292, !7, i64 296, !6, i64 768, !6, i64 772, !6, i64 776, !6, i64 780, !6, i64 784, !6, i64 788, !6, i64 792, !6, i64 796, !6, i64 800, !6, i64 804, !6, i64 808, !6, i64 812, !6, i64 816, !6, i64 820, !6, i64 824, !6, i64 828, !6, i64 832, !6, i64 836}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !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"

declare i32 @HAL_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_PWREx_ControlVoltageScaling(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !5
  %3 = and i32 %2, 49152
  %4 = icmp eq i32 %3, %0
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %1
  %6 = icmp eq i32 %0, 0
  br i1 %6, label %7, label %25

7:                                                ; preds = %5
  %8 = load volatile i32, ptr inttoptr (i64 1476544524 to ptr), align 4, !tbaa !10
  %9 = and i32 %8, 2
  %.not8 = icmp eq i32 %9, 0
  br i1 %.not8, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = load volatile i32, ptr inttoptr (i64 1476544536 to ptr), align 8, !tbaa !11
  %12 = or i32 %11, 49152
  store volatile i32 %12, ptr inttoptr (i64 1476544536 to ptr), align 8, !tbaa !11
  %13 = tail call i32 @HAL_GetTick() #2
  br label %14

14:                                               ; preds = %18, %10
  %15 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !5
  %16 = and i32 %15, 8192
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  %19 = tail call i32 @HAL_GetTick() #2
  %20 = sub i32 %19, %13
  %21 = icmp ugt i32 %20, 1000
  br i1 %21, label %.loopexit, label %14, !llvm.loop !12

22:                                               ; preds = %14
  %23 = load volatile i32, ptr inttoptr (i64 1476396076 to ptr), align 4, !tbaa !14
  %24 = or i32 %23, 1
  store volatile i32 %24, ptr inttoptr (i64 1476396076 to ptr), align 4, !tbaa !14
  br label %47

25:                                               ; preds = %5
  %26 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !5
  %27 = and i32 %26, 49152
  %28 = icmp eq i32 %27, 49152
  br i1 %28, label %29, label %.loopexit10

29:                                               ; preds = %25
  %30 = load volatile i32, ptr inttoptr (i64 1476396076 to ptr), align 4, !tbaa !14
  %31 = and i32 %30, 1
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %.loopexit10, label %32

32:                                               ; preds = %29
  %33 = load volatile i32, ptr inttoptr (i64 1476396076 to ptr), align 4, !tbaa !14
  %34 = and i32 %33, -2
  store volatile i32 %34, ptr inttoptr (i64 1476396076 to ptr), align 4, !tbaa !14
  %35 = tail call i32 @HAL_GetTick() #2
  br label %36

36:                                               ; preds = %40, %32
  %37 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !5
  %38 = and i32 %37, 8192
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %.loopexit10

40:                                               ; preds = %36
  %41 = tail call i32 @HAL_GetTick() #2
  %42 = sub i32 %41, %35
  %43 = icmp ugt i32 %42, 1000
  br i1 %43, label %.loopexit, label %36, !llvm.loop !16

.loopexit10:                                      ; preds = %36, %29, %25
  %44 = load volatile i32, ptr inttoptr (i64 1476544536 to ptr), align 8, !tbaa !11
  %45 = and i32 %44, -49153
  %46 = or i32 %45, %0
  store volatile i32 %46, ptr inttoptr (i64 1476544536 to ptr), align 8, !tbaa !11
  br label %47

47:                                               ; preds = %.loopexit10, %22
  %48 = tail call i32 @HAL_GetTick() #2
  br label %49

49:                                               ; preds = %53, %47
  %50 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !5
  %51 = and i32 %50, 8192
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %.loopexit

53:                                               ; preds = %49
  %54 = tail call i32 @HAL_GetTick() #2
  %55 = sub i32 %54, %48
  %56 = icmp ugt i32 %55, 1000
  br i1 %56, label %.loopexit, label %49, !llvm.loop !17

.loopexit:                                        ; preds = %40, %18, %49, %53, %7, %1
  %.0 = phi i32 [ 0, %1 ], [ 1, %7 ], [ 0, %49 ], [ 1, %53 ], [ 1, %18 ], [ 1, %40 ]
  ret i32 %.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 4}
!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 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 24}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !7, i64 44}
!15 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !8, i64 48, !7, i64 292, !8, i64 296, !7, i64 768, !7, i64 772, !7, i64 776, !7, i64 780, !7, i64 784, !7, i64 788, !7, i64 792, !7, i64 796, !7, i64 800, !7, i64 804, !7, i64 808, !7, i64 812, !7, i64 816, !7, i64 820, !7, i64 824, !7, i64 828, !7, i64 832, !7, i64 836}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass