; 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_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 }
%struct.RTC_TimeTypeDef = type { i8, i8, i8, i8, 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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_RTC_GetTime(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.RTC_TypeDef, ptr %10, i32 0, i32 10
  %12 = load volatile i32, ptr %11, align 4, !tbaa !14
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %13, i32 0, i32 4
  store i32 %12, ptr %14, align 4, !tbaa !16
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.RTC_TypeDef, ptr %17, i32 0, i32 4
  %19 = load volatile i32, ptr %18, align 4, !tbaa !18
  %20 = zext i32 %19 to i64
  %21 = and i64 %20, 32767
  %22 = trunc i64 %21 to i32
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %23, i32 0, i32 5
  store i32 %22, ptr %24, align 4, !tbaa !19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.RTC_HandleTypeDef, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.RTC_TypeDef, ptr %27, i32 0, i32 0
  %29 = load volatile i32, ptr %28, align 4, !tbaa !20
  %30 = zext i32 %29 to i64
  %31 = and i64 %30, 8355711
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %7, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = and i64 %34, 4128768
  %36 = lshr i64 %35, 16
  %37 = trunc i64 %36 to i8
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %38, i32 0, i32 0
  store i8 %37, ptr %39, align 4, !tbaa !21
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = and i64 %41, 32512
  %43 = lshr i64 %42, 8
  %44 = trunc i64 %43 to i8
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %45, i32 0, i32 1
  store i8 %44, ptr %46, align 1, !tbaa !22
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, 127
  %50 = lshr i64 %49, 0
  %51 = trunc i64 %50 to i8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %52, i32 0, i32 2
  store i8 %51, ptr %53, align 2, !tbaa !23
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = and i64 %55, 4194304
  %57 = lshr i64 %56, 22
  %58 = trunc i64 %57 to i8
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %59, i32 0, i32 3
  store i8 %58, ptr %60, align 1, !tbaa !24
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %82

63:                                               ; preds = %3
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %64, i32 0, i32 0
  %66 = load i8, ptr %65, align 4, !tbaa !21
  %67 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %66)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %68, i32 0, i32 0
  store i8 %67, ptr %69, align 4, !tbaa !21
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %70, i32 0, i32 1
  %72 = load i8, ptr %71, align 1, !tbaa !22
  %73 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %72)
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %74, i32 0, i32 1
  store i8 %73, ptr %75, align 1, !tbaa !22
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %76, i32 0, i32 2
  %78 = load i8, ptr %77, align 2, !tbaa !23
  %79 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %78)
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.RTC_TimeTypeDef, ptr %80, i32 0, i32 2
  store i8 %79, ptr %81, align 2, !tbaa !23
  br label %82

82:                                               ; preds = %63, %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext) #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, !6, i64 0}
!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 = !{!15, !10, i64 40}
!15 = !{!"", !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}
!16 = !{!17, !10, i64 4}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!18 = !{!15, !10, i64 16}
!19 = !{!17, !10, i64 8}
!20 = !{!15, !10, i64 0}
!21 = !{!17, !7, i64 0}
!22 = !{!17, !7, i64 1}
!23 = !{!17, !7, i64 2}
!24 = !{!17, !7, i64 3}


; 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 noundef i32 @HAL_RTC_GetTime(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load volatile i32, ptr %5, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %6, ptr %7, align 4, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  %9 = load volatile i32, ptr %8, align 4, !tbaa !16
  %10 = and i32 %9, 32767
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %10, ptr %11, align 4, !tbaa !17
  %12 = load volatile i32, ptr %4, align 4, !tbaa !18
  %13 = and i32 %12, 8355711
  %14 = lshr i32 %12, 16
  %15 = trunc i32 %14 to i8
  %16 = and i8 %15, 63
  store i8 %16, ptr %1, align 4, !tbaa !19
  %17 = lshr i32 %13, 8
  %18 = trunc i32 %17 to i8
  %19 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %18, ptr %19, align 1, !tbaa !20
  %20 = trunc i32 %13 to i8
  %21 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %20, ptr %21, align 2, !tbaa !21
  %22 = lshr i32 %13, 22
  %23 = trunc nuw nsw i32 %22 to i8
  %24 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %23, ptr %24, align 1, !tbaa !22
  %25 = icmp eq i32 %2, 0
  br i1 %25, label %26, label %32

26:                                               ; preds = %3
  %27 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %16)
  store i8 %27, ptr %1, align 4, !tbaa !19
  %28 = load i8, ptr %19, align 1, !tbaa !20
  %29 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %28)
  store i8 %29, ptr %19, align 1, !tbaa !20
  %30 = load i8, ptr %21, align 2, !tbaa !21
  %31 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %30)
  store i8 %31, ptr %21, align 2, !tbaa !21
  br label %32

32:                                               ; preds = %26, %3
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext) 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 0}
!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 = !{!13, !11, i64 40}
!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, !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}
!14 = !{!15, !11, i64 4}
!15 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!16 = !{!13, !11, i64 16}
!17 = !{!15, !11, i64 8}
!18 = !{!13, !11, i64 0}
!19 = !{!15, !8, i64 0}
!20 = !{!15, !8, i64 1}
!21 = !{!15, !8, i64 2}
!22 = !{!15, !8, i64 3}


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