; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_rtc_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.RTC_HandleTypeDef = type { ptr, %struct.RTC_InitTypeDef, i32, i32 }
%struct.RTC_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.RTC_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, 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

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

declare i32 @HAL_GetTick() #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_RTCEx_SetWakeUpTimer(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %123

17:                                               ; preds = %11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %18, i32 0, i32 2
  store i32 1, ptr %19, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %23, i32 0, i32 3
  store volatile i32 2, ptr %24, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %struct.RTC_TypeDef, ptr %28, i32 0, i32 9
  store volatile i32 202, ptr %29, align 4, !tbaa !16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct.RTC_TypeDef, ptr %32, i32 0, i32 9
  store volatile i32 83, ptr %33, align 4, !tbaa !16
  br label %34

34:                                               ; preds = %25
  br label %35

35:                                               ; preds = %34
  %36 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !18
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, -1025
  %39 = trunc i64 %38 to i32
  store volatile i32 %39, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !18
  %40 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 3), align 4, !tbaa !19
  %41 = zext i32 %40 to i64
  %42 = and i64 %41, 64
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %44, label %80

44:                                               ; preds = %35
  %45 = call i32 @HAL_GetTick()
  store i32 %45, ptr %8, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %78, %44
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.RTC_TypeDef, ptr %49, i32 0, i32 3
  %51 = load volatile i32, ptr %50, align 4, !tbaa !19
  %52 = zext i32 %51 to i64
  %53 = and i64 %52, 4
  %54 = icmp ne i64 %53, 0
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, i32 1, i32 0
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %79

58:                                               ; preds = %46
  %59 = call i32 @HAL_GetTick()
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = sub i32 %59, %60
  %62 = icmp ugt i32 %61, 1000
  br i1 %62, label %63, label %78

63:                                               ; preds = %58
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = getelementptr inbounds %struct.RTC_TypeDef, ptr %67, i32 0, i32 9
  store volatile i32 255, ptr %68, align 4, !tbaa !16
  br label %69

69:                                               ; preds = %64
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %71, i32 0, i32 3
  store volatile i32 3, ptr %72, align 8, !tbaa !14
  br label %73

73:                                               ; preds = %70
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %74, i32 0, i32 2
  store i32 0, ptr %75, align 4, !tbaa !11
  br label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  store i32 3, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %123

78:                                               ; preds = %58
  br label %46, !llvm.loop !20

79:                                               ; preds = %46
  br label %80

80:                                               ; preds = %79, %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  %84 = getelementptr inbounds %struct.RTC_TypeDef, ptr %83, i32 0, i32 2
  %85 = load volatile i32, ptr %84, align 4, !tbaa !18
  store i32 %85, ptr %10, align 4, !tbaa !9
  %86 = load i32, ptr %10, align 4, !tbaa !9
  %87 = and i32 %86, -8
  store i32 %87, ptr %10, align 4, !tbaa !9
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = or i32 %89, %88
  store i32 %90, ptr %10, align 4, !tbaa !9
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !15
  %95 = getelementptr inbounds %struct.RTC_TypeDef, ptr %94, i32 0, i32 2
  store volatile i32 %91, ptr %95, align 4, !tbaa !18
  %96 = load i32, ptr %6, align 4, !tbaa !9
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !15
  %100 = getelementptr inbounds %struct.RTC_TypeDef, ptr %99, i32 0, i32 5
  store volatile i32 %96, ptr %100, align 4, !tbaa !22
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !15
  %104 = getelementptr inbounds %struct.RTC_TypeDef, ptr %103, i32 0, i32 2
  %105 = load volatile i32, ptr %104, align 4, !tbaa !18
  %106 = zext i32 %105 to i64
  %107 = or i64 %106, 1024
  %108 = trunc i64 %107 to i32
  store volatile i32 %108, ptr %104, align 4, !tbaa !18
  br label %109

109:                                              ; preds = %80
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %110, i32 0, i32 0
  %112 = load ptr, ptr %111, align 8, !tbaa !15
  %113 = getelementptr inbounds %struct.RTC_TypeDef, ptr %112, i32 0, i32 9
  store volatile i32 255, ptr %113, align 4, !tbaa !16
  br label %114

114:                                              ; preds = %109
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %116, i32 0, i32 3
  store volatile i32 1, ptr %117, align 8, !tbaa !14
  br label %118

118:                                              ; preds = %115
  %119 = load ptr, ptr %5, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %119, i32 0, i32 2
  store i32 0, ptr %120, align 4, !tbaa !11
  br label %121

121:                                              ; preds = %118
  br label %122

122:                                              ; preds = %121
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %123

123:                                              ; preds = %122, %77, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %124 = load i32, ptr %4, align 4
  ret i32 %124
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 36}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 36, !10, i64 40}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!14 = !{!12, !10, i64 40}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 36}
!17 = !{!"", !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, !10, i64 48, !10, i64 52, !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, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204}
!18 = !{!17, !10, i64 8}
!19 = !{!17, !10, i64 12}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!17, !10, i64 20}


; 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, 4) i32 @HAL_RTCEx_SetWakeUpTimer(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 36
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %39, label %7

7:                                                ; preds = %3
  store i32 1, ptr %4, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  store volatile i32 2, ptr %8, align 8, !tbaa !12
  %9 = load ptr, ptr %0, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 36
  store volatile i32 202, ptr %10, align 4, !tbaa !14
  store volatile i32 83, ptr %10, align 4, !tbaa !14
  %11 = load volatile i32, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !16
  %12 = and i32 %11, -1025
  store volatile i32 %12, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !16
  %13 = load volatile i32, ptr inttoptr (i64 1476411404 to ptr), align 4, !tbaa !17
  %14 = and i32 %13, 64
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %.loopexit

16:                                               ; preds = %7
  %17 = tail call i32 @HAL_GetTick() #2
  br label %18

18:                                               ; preds = %24, %16
  %19 = load ptr, ptr %0, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 12
  %21 = load volatile i32, ptr %20, align 4, !tbaa !17
  %22 = and i32 %21, 4
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.loopexit

24:                                               ; preds = %18
  %25 = tail call i32 @HAL_GetTick() #2
  %26 = sub i32 %25, %17
  %27 = icmp ugt i32 %26, 1000
  br i1 %27, label %28, label %18, !llvm.loop !18

28:                                               ; preds = %24
  %29 = load ptr, ptr %0, align 8, !tbaa !13
  br label %.sink.split

.loopexit:                                        ; preds = %18, %7
  %30 = phi ptr [ %9, %7 ], [ %19, %18 ]
  %31 = getelementptr inbounds i8, ptr %30, i64 8
  %32 = load volatile i32, ptr %31, align 4, !tbaa !16
  %33 = and i32 %32, -8
  %34 = or i32 %33, %2
  store volatile i32 %34, ptr %31, align 4, !tbaa !16
  %35 = getelementptr inbounds i8, ptr %30, i64 20
  store volatile i32 %1, ptr %35, align 4, !tbaa !20
  %36 = load volatile i32, ptr %31, align 4, !tbaa !16
  %37 = or i32 %36, 1024
  store volatile i32 %37, ptr %31, align 4, !tbaa !16
  br label %.sink.split

.sink.split:                                      ; preds = %28, %.loopexit
  %.sink24 = phi ptr [ %30, %.loopexit ], [ %29, %28 ]
  %.sink = phi i32 [ 1, %.loopexit ], [ 3, %28 ]
  %.0.ph = phi i32 [ 0, %.loopexit ], [ 3, %28 ]
  %38 = getelementptr inbounds i8, ptr %.sink24, i64 36
  store volatile i32 255, ptr %38, align 4, !tbaa !14
  store volatile i32 %.sink, ptr %8, align 8, !tbaa !12
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %.sink.split, %3
  %.0 = phi i32 [ 2, %3 ], [ %.0.ph, %.sink.split ]
  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, !11, i64 36}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 36, !11, i64 40}
!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 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 40}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !11, i64 36}
!15 = !{!"", !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, i64 52, !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, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204}
!16 = !{!15, !11, i64 8}
!17 = !{!15, !11, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!15, !11, i64 20}


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