; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (GetDate)

; 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_DateTypeDef = type { i8, i8, i8, i8 }

; 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
declare dso_local zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_RTC_GetDate(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 1
  %12 = load volatile i32, ptr %11, align 4, !tbaa !14
  %13 = zext i32 %12 to i64
  %14 = and i64 %13, 16777023
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = and i64 %17, 16711680
  %19 = lshr i64 %18, 16
  %20 = trunc i64 %19 to i8
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %21, i32 0, i32 3
  store i8 %20, ptr %22, align 1, !tbaa !16
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = and i64 %24, 7936
  %26 = lshr i64 %25, 8
  %27 = trunc i64 %26 to i8
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %28, i32 0, i32 1
  store i8 %27, ptr %29, align 1, !tbaa !18
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = and i64 %31, 63
  %33 = trunc i64 %32 to i8
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %34, i32 0, i32 2
  store i8 %33, ptr %35, align 1, !tbaa !19
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, 57344
  %39 = lshr i64 %38, 13
  %40 = trunc i64 %39 to i8
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %41, i32 0, i32 0
  store i8 %40, ptr %42, align 1, !tbaa !20
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %64

45:                                               ; preds = %3
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %46, i32 0, i32 3
  %48 = load i8, ptr %47, align 1, !tbaa !16
  %49 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %48)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %50, i32 0, i32 3
  store i8 %49, ptr %51, align 1, !tbaa !16
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %52, i32 0, i32 1
  %54 = load i8, ptr %53, align 1, !tbaa !18
  %55 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %54)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %56, i32 0, i32 1
  store i8 %55, ptr %57, align 1, !tbaa !18
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %58, i32 0, i32 2
  %60 = load i8, ptr %59, align 1, !tbaa !19
  %61 = call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %60)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.RTC_DateTypeDef, ptr %62, i32 0, i32 2
  store i8 %61, ptr %63, align 1, !tbaa !19
  br label %64

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

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 4}
!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, !7, i64 3}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!18 = !{!17, !7, i64 1}
!19 = !{!17, !7, i64 2}
!20 = !{!17, !7, i64 0}


; 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
declare dso_local zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @HAL_RTC_GetDate(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 4
  %6 = load volatile i32, ptr %5, align 4, !tbaa !12
  %7 = lshr i32 %6, 16
  %8 = trunc i32 %7 to i8
  %9 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %8, ptr %9, align 1, !tbaa !14
  %10 = lshr i32 %6, 8
  %11 = trunc i32 %10 to i8
  %12 = and i8 %11, 31
  %13 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %12, ptr %13, align 1, !tbaa !16
  %14 = trunc i32 %6 to i8
  %15 = and i8 %14, 63
  %16 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %15, ptr %16, align 1, !tbaa !17
  %17 = lshr i32 %6, 13
  %18 = trunc i32 %17 to i8
  %19 = and i8 %18, 7
  store i8 %19, ptr %1, align 1, !tbaa !18
  %20 = icmp eq i32 %2, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %3
  %22 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %8)
  store i8 %22, ptr %9, align 1, !tbaa !14
  %23 = load i8, ptr %13, align 1, !tbaa !16
  %24 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %23)
  store i8 %24, ptr %13, align 1, !tbaa !16
  %25 = load i8, ptr %16, align 1, !tbaa !17
  %26 = tail call zeroext i8 @RTC_Bcd2ToByte(i8 noundef zeroext %25)
  store i8 %26, ptr %16, align 1, !tbaa !17
  br label %27

27:                                               ; preds = %21, %3
  ret i32 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 4}
!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, !8, i64 3}
!15 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3}
!16 = !{!15, !8, i64 1}
!17 = !{!15, !8, i64 2}
!18 = !{!15, !8, i64 0}


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