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

; 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_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 }
%struct.RTC_HandleTypeDef = type { ptr, %struct.RTC_InitTypeDef, i32, i32 }
%struct.RTC_InitTypeDef = type { 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: nounwind uwtable
define dso_local i32 @RTC_ExitInitMode(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  %4 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 3), align 4, !tbaa !11
  %5 = zext i32 %4 to i64
  %6 = and i64 %5, -65
  %7 = trunc i64 %6 to i32
  store volatile i32 %7, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 3), align 4, !tbaa !11
  %8 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !13
  %9 = zext i32 %8 to i64
  %10 = and i64 %9, 32
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %20

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @HAL_RTC_WaitForSynchro(ptr noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %17, i32 0, i32 3
  store volatile i32 3, ptr %18, align 8, !tbaa !14
  store i32 3, ptr %3, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %16, %12
  br label %36

20:                                               ; preds = %1
  %21 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !13
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, -33
  %24 = trunc i64 %23 to i32
  store volatile i32 %24, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !13
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = call i32 @HAL_RTC_WaitForSynchro(ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %20
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %29, i32 0, i32 3
  store volatile i32 3, ptr %30, align 8, !tbaa !14
  store i32 3, ptr %3, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %28, %20
  %32 = load volatile i32, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !13
  %33 = zext i32 %32 to i64
  %34 = or i64 %33, 32
  %35 = trunc i64 %34 to i32
  store volatile i32 %35, ptr getelementptr inbounds (%struct.RTC_TypeDef, ptr inttoptr (i64 1476411392 to ptr), i32 0, i32 2), align 4, !tbaa !13
  br label %36

36:                                               ; preds = %31, %19
  %37 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %37
}

; 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
declare dso_local i32 @HAL_RTC_WaitForSynchro(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 = { 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, !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}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !10, i64 40}
!15 = !{!"", !6, i64 0, !16, i64 8, !10, i64 36, !10, i64 40}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}


; 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, 4) i32 @RTC_ExitInitMode(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load volatile i32, ptr inttoptr (i64 1476411404 to ptr), align 4, !tbaa !5
  %3 = and i32 %2, -65
  store volatile i32 %3, ptr inttoptr (i64 1476411404 to ptr), align 4, !tbaa !5
  %4 = load volatile i32, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !10
  %5 = and i32 %4, 32
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %11

7:                                                ; preds = %1
  %8 = tail call i32 @HAL_RTC_WaitForSynchro(ptr noundef %0)
  %.not4 = icmp eq i32 %8, 0
  br i1 %.not4, label %20, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store volatile i32 3, ptr %10, align 8, !tbaa !11
  br label %20

11:                                               ; preds = %1
  %12 = load volatile i32, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !10
  %13 = and i32 %12, -33
  store volatile i32 %13, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !10
  %14 = tail call i32 @HAL_RTC_WaitForSynchro(ptr noundef %0)
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %17, label %15

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  store volatile i32 3, ptr %16, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %15, %11
  %.0 = phi i32 [ 3, %15 ], [ 0, %11 ]
  %18 = load volatile i32, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !10
  %19 = or i32 %18, 32
  store volatile i32 %19, ptr inttoptr (i64 1476411400 to ptr), align 8, !tbaa !10
  br label %20

20:                                               ; preds = %7, %9, %17
  %.1 = phi i32 [ 3, %9 ], [ 0, %7 ], [ %.0, %17 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @HAL_RTC_WaitForSynchro(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" }

!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, !7, i64 48, !7, i64 52, !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, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !7, i64 168, !7, i64 172, !7, i64 176, !7, i64 180, !7, i64 184, !7, i64 188, !7, i64 192, !7, i64 196, !7, i64 200, !7, i64 204}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !7, i64 40}
!12 = !{!"", !13, i64 0, !14, i64 8, !7, i64 36, !7, i64 40}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}


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