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

; 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.UART_WakeUpTypeDef = type { i32, i16, i8 }
%struct.__UART_HandleTypeDef = type { ptr, %struct.UART_InitTypeDef, %struct.UART_AdvFeatureInitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i32, i16, i16, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.UART_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.UART_AdvFeatureInitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USART_TypeDef = type { 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

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

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

14:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %16, i32 0, i32 17
  store i32 1, ptr %17, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %21, i32 0, i32 18
  store volatile i32 36, ptr %22, align 4, !tbaa !16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = getelementptr inbounds %struct.USART_TypeDef, ptr %25, i32 0, i32 0
  %27 = load volatile i32, ptr %26, align 4, !tbaa !18
  %28 = zext i32 %27 to i64
  %29 = and i64 %28, -2
  %30 = trunc i64 %29 to i32
  store volatile i32 %30, ptr %26, align 4, !tbaa !18
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds %struct.USART_TypeDef, ptr %33, i32 0, i32 2
  %35 = load volatile i32, ptr %34, align 4, !tbaa !20
  %36 = zext i32 %35 to i64
  %37 = and i64 %36, -3145729
  %38 = getelementptr inbounds %struct.UART_WakeUpTypeDef, ptr %4, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !21
  %40 = zext i32 %39 to i64
  %41 = or i64 %37, %40
  %42 = trunc i64 %41 to i32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.USART_TypeDef, ptr %45, i32 0, i32 2
  store volatile i32 %42, ptr %46, align 4, !tbaa !20
  %47 = getelementptr inbounds %struct.UART_WakeUpTypeDef, ptr %4, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !21
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %20
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i64, ptr %4, align 4
  call void @UARTEx_Wakeup_AddressConfig(ptr noundef %51, i64 %52)
  br label %53

53:                                               ; preds = %50, %20
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = getelementptr inbounds %struct.USART_TypeDef, ptr %56, i32 0, i32 0
  %58 = load volatile i32, ptr %57, align 4, !tbaa !18
  %59 = zext i32 %58 to i64
  %60 = or i64 %59, 1
  %61 = trunc i64 %60 to i32
  store volatile i32 %61, ptr %57, align 4, !tbaa !18
  %62 = call i32 @HAL_GetTick()
  store i32 %62, ptr %7, align 4, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = call i32 @UART_WaitOnFlagUntilTimeout(ptr noundef %63, i32 noundef 4194304, i32 noundef 0, i32 noundef %64, i32 noundef 33554431)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %53
  store i32 3, ptr %6, align 4, !tbaa !9
  br label %71

68:                                               ; preds = %53
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %69, i32 0, i32 18
  store volatile i32 32, ptr %70, align 4, !tbaa !16
  br label %71

71:                                               ; preds = %68, %67
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %73, i32 0, i32 17
  store i32 0, ptr %74, align 8, !tbaa !11
  br label %75

75:                                               ; preds = %72
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

78:                                               ; preds = %76, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: nounwind uwtable
declare hidden void @UARTEx_Wakeup_AddressConfig(ptr noundef, i64) #1

declare i32 @HAL_GetTick() #2

declare i32 @UART_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

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 = { "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 160}
!12 = !{!"__UART_HandleTypeDef", !6, i64 0, !13, i64 8, !14, i64 44, !6, i64 88, !15, i64 96, !15, i64 98, !6, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !10, i64 120, !15, i64 124, !15, i64 126, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172}
!13 = !{!"", !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}
!14 = !{!"", !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}
!15 = !{!"short", !7, i64 0}
!16 = !{!12, !10, i64 164}
!17 = !{!12, !6, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !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}
!20 = !{!19, !10, i64 8}
!21 = !{!22, !10, i64 0}
!22 = !{!"", !10, i64 0, !15, i64 4, !7, i64 6}


; 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 @HAL_UARTEx_StopModeWakeUpSourceConfig(ptr noundef %0, i64 %1) local_unnamed_addr #0 {
  %.sroa.4.0.extract.shift = and i64 %1, -4294967296
  %3 = getelementptr inbounds i8, ptr %0, i64 160
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %27, label %6

6:                                                ; preds = %2
  store i32 1, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 164
  store volatile i32 36, ptr %7, align 4, !tbaa !14
  %8 = load ptr, ptr %0, align 8, !tbaa !15
  %9 = load volatile i32, ptr %8, align 4, !tbaa !16
  %10 = and i32 %9, -2
  store volatile i32 %10, ptr %8, align 4, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  %12 = load volatile i32, ptr %11, align 4, !tbaa !18
  %13 = and i32 %12, -3145729
  %14 = trunc i64 %1 to i32
  %15 = or i32 %13, %14
  store volatile i32 %15, ptr %11, align 4, !tbaa !18
  %16 = and i64 %1, 4294967295
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %6
  tail call void @UARTEx_Wakeup_AddressConfig(ptr noundef nonnull %0, i64 %.sroa.4.0.extract.shift)
  %.pre = load ptr, ptr %0, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %18, %6
  %20 = phi ptr [ %.pre, %18 ], [ %8, %6 ]
  %21 = load volatile i32, ptr %20, align 4, !tbaa !16
  %22 = or i32 %21, 1
  store volatile i32 %22, ptr %20, align 4, !tbaa !16
  %23 = tail call i32 @HAL_GetTick() #2
  %24 = tail call i32 @UART_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 4194304, i32 noundef 0, i32 noundef %23, i32 noundef 33554431) #2
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %25, label %26

25:                                               ; preds = %19
  store volatile i32 32, ptr %7, align 4, !tbaa !14
  br label %26

26:                                               ; preds = %19, %25
  %.015 = phi i32 [ 0, %25 ], [ 3, %19 ]
  store i32 0, ptr %3, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %2, %26
  %.0 = phi i32 [ %.015, %26 ], [ 2, %2 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @UARTEx_Wakeup_AddressConfig(ptr noundef, i64) local_unnamed_addr #0

declare i32 @HAL_GetTick() local_unnamed_addr #1

declare i32 @UART_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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" }
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 }

!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 160}
!6 = !{!"__UART_HandleTypeDef", !7, i64 0, !10, i64 8, !12, i64 44, !7, i64 88, !13, i64 96, !13, i64 98, !7, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !11, i64 120, !13, i64 124, !13, i64 126, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172}
!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, i64 28, !11, i64 32}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !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}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !11, i64 164}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !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}
!18 = !{!17, !11, i64 8}


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