; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/usart/stm32 (usart)

; 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.usart_t = type { [32 x i8], [32 x i8], %struct.file_operations, %struct.__UART_HandleTypeDef, %struct.dma_t, %struct.dma_t, i32, ptr, ptr, i32, i32, i32, i32, i32, %struct.usart_private_t }
%struct.file_operations = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.__UART_HandleTypeDef = type { ptr, %struct.UART_InitTypeDef, %struct.UART_AdvFeatureInitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i32, i16, i16, i32, 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.dma_t = type { %struct.__DMA_HandleTypeDef, i32, %struct.dma_private_t }
%struct.__DMA_HandleTypeDef = type { ptr, %struct.DMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, i32 }
%struct.DMA_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.dma_private_t = type { i32 }
%struct.usart_private_t = type { i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i8, 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
define dso_local i32 @usart_transmit(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  %10 = load i16, ptr %7, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %3
  store i32 22, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %80

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.usart_t, ptr %18, i32 0, i32 14
  %20 = getelementptr inbounds %struct.usart_private_t, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = call i64 @xQueueSemaphoreTake(ptr noundef %21, i32 noundef 0)
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %17
  store i32 16, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %80

25:                                               ; preds = %17
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.usart_t, ptr %26, i32 0, i32 14
  %28 = getelementptr inbounds %struct.usart_private_t, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !25
  %30 = call i64 @xQueueSemaphoreTake(ptr noundef %29, i32 noundef 0)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.usart_t, ptr %31, i32 0, i32 14
  %33 = getelementptr inbounds %struct.usart_private_t, ptr %32, i32 0, i32 5
  store i32 1, ptr %33, align 8, !tbaa !26
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.usart_t, ptr %34, i32 0, i32 14
  %36 = getelementptr inbounds %struct.usart_private_t, ptr %35, i32 0, i32 8
  store i32 0, ptr %36, align 4, !tbaa !27
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.usart_t, ptr %37, i32 0, i32 14
  %39 = getelementptr inbounds %struct.usart_private_t, ptr %38, i32 0, i32 17
  %40 = load i8, ptr %39, align 1, !tbaa !28, !range !29, !noundef !30
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %48

42:                                               ; preds = %25
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.usart_t, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i16, ptr %7, align 2, !tbaa !9
  %47 = call i32 @HAL_UART_Transmit_DMA(ptr noundef %44, ptr noundef %45, i16 noundef zeroext %46)
  store i32 %47, ptr %8, align 4, !tbaa !11
  br label %54

48:                                               ; preds = %25
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.usart_t, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i16, ptr %7, align 2, !tbaa !9
  %53 = call i32 @HAL_UART_Transmit_IT(ptr noundef %50, ptr noundef %51, i16 noundef zeroext %52)
  store i32 %53, ptr %8, align 4, !tbaa !11
  br label %54

54:                                               ; preds = %48, %42
  %55 = load i32, ptr %8, align 4, !tbaa !11
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %70

57:                                               ; preds = %54
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.usart_t, ptr %58, i32 0, i32 14
  %60 = getelementptr inbounds %struct.usart_private_t, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !25
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.usart_t, ptr %62, i32 0, i32 10
  %64 = load i32, ptr %63, align 4, !tbaa !31
  %65 = mul i32 %64, 1000
  %66 = udiv i32 %65, 1000
  %67 = call i64 @xQueueSemaphoreTake(ptr noundef %61, i32 noundef %66)
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %70, label %69

69:                                               ; preds = %57
  store i32 116, ptr %8, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %69, %57, %54
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.usart_t, ptr %71, i32 0, i32 14
  %73 = getelementptr inbounds %struct.usart_private_t, ptr %72, i32 0, i32 5
  store i32 0, ptr %73, align 8, !tbaa !26
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.usart_t, ptr %74, i32 0, i32 14
  %76 = getelementptr inbounds %struct.usart_private_t, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  %78 = call i64 @xQueueGenericSend(ptr noundef %77, ptr noundef null, i32 noundef 0, i64 noundef 0)
  %79 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %79, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %80

80:                                               ; preds = %70, %24, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %81 = load i32, ptr %4, align 4
  ret i32 %81
}

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) #2

declare i32 @HAL_UART_Transmit_DMA(ptr noundef, ptr noundef, i16 noundef zeroext) #2

declare i32 @HAL_UART_Transmit_IT(ptr noundef, ptr noundef, i16 noundef zeroext) #2

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 792}
!14 = !{!"", !7, i64 0, !7, i64 32, !15, i64 64, !16, i64 152, !19, i64 336, !19, i64 528, !12, i64 720, !6, i64 728, !6, i64 736, !12, i64 744, !12, i64 748, !12, i64 752, !12, i64 756, !12, i64 760, !23, i64 768}
!15 = !{!"file_operations", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!16 = !{!"__UART_HandleTypeDef", !6, i64 0, !17, i64 8, !18, i64 44, !6, i64 88, !10, i64 96, !10, i64 98, !6, i64 104, !10, i64 112, !10, i64 114, !10, i64 116, !12, i64 120, !10, i64 124, !10, i64 126, !12, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !12, i64 168, !12, i64 172, !12, i64 176, !12, i64 180}
!17 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!19 = !{!"", !20, i64 0, !12, i64 184, !22, i64 188}
!20 = !{!"__DMA_HandleTypeDef", !6, i64 0, !21, i64 8, !12, i64 56, !12, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !12, i64 120, !12, i64 124, !12, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !6, i64 160, !6, i64 168, !12, i64 176}
!21 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!22 = !{!"", !12, i64 0}
!23 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !24, i64 92, !24, i64 93, !24, i64 94, !24, i64 95, !24, i64 96}
!24 = !{!"_Bool", !7, i64 0}
!25 = !{!14, !6, i64 776}
!26 = !{!14, !12, i64 808}
!27 = !{!14, !12, i64 820}
!28 = !{!14, !24, i64 863}
!29 = !{i8 0, i8 2}
!30 = !{}
!31 = !{!14, !12, i64 748}


; 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 i32 @usart_transmit(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = icmp eq i16 %2, 0
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %4
  br i1 %or.cond, label %37, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 792
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call i64 @xQueueSemaphoreTake(ptr noundef %8, i32 noundef 0) #2
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %37, label %11

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 776
  %13 = load ptr, ptr %12, align 8, !tbaa !22
  %14 = tail call i64 @xQueueSemaphoreTake(ptr noundef %13, i32 noundef 0) #2
  %15 = getelementptr inbounds i8, ptr %0, i64 808
  store i32 1, ptr %15, align 8, !tbaa !23
  %16 = getelementptr inbounds i8, ptr %0, i64 820
  store i32 0, ptr %16, align 4, !tbaa !24
  %17 = getelementptr inbounds i8, ptr %0, i64 863
  %18 = load i8, ptr %17, align 1, !tbaa !25, !range !26, !noundef !27
  %19 = trunc nuw i8 %18 to i1
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  br i1 %19, label %21, label %23

21:                                               ; preds = %11
  %22 = tail call i32 @HAL_UART_Transmit_DMA(ptr noundef nonnull %20, ptr noundef nonnull %1, i16 noundef zeroext %2) #2
  br label %25

23:                                               ; preds = %11
  %24 = tail call i32 @HAL_UART_Transmit_IT(ptr noundef nonnull %20, ptr noundef nonnull %1, i16 noundef zeroext %2) #2
  br label %25

25:                                               ; preds = %23, %21
  %.0 = phi i32 [ %22, %21 ], [ %24, %23 ]
  %26 = icmp eq i32 %.0, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %25
  %28 = load ptr, ptr %12, align 8, !tbaa !22
  %29 = getelementptr inbounds i8, ptr %0, i64 748
  %30 = load i32, ptr %29, align 4, !tbaa !28
  %31 = mul i32 %30, 1000
  %32 = udiv i32 %31, 1000
  %33 = tail call i64 @xQueueSemaphoreTake(ptr noundef %28, i32 noundef %32) #2
  %.not = icmp eq i64 %33, 0
  %spec.select = select i1 %.not, i32 116, i32 0
  br label %34

34:                                               ; preds = %27, %25
  %.1 = phi i32 [ %.0, %25 ], [ %spec.select, %27 ]
  store i32 0, ptr %15, align 8, !tbaa !23
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = tail call i64 @xQueueGenericSend(ptr noundef %35, ptr noundef null, i32 noundef 0, i64 noundef 0) #2
  br label %37

37:                                               ; preds = %6, %3, %34
  %.020 = phi i32 [ %.1, %34 ], [ 22, %3 ], [ 16, %6 ]
  ret i32 %.020
}

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @HAL_UART_Transmit_DMA(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare i32 @HAL_UART_Transmit_IT(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 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, !10, i64 792}
!6 = !{!"", !7, i64 0, !7, i64 32, !9, i64 64, !11, i64 152, !16, i64 336, !16, i64 528, !13, i64 720, !10, i64 728, !10, i64 736, !13, i64 744, !13, i64 748, !13, i64 752, !13, i64 756, !13, i64 760, !20, i64 768}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"file_operations", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"__UART_HandleTypeDef", !10, i64 0, !12, i64 8, !14, i64 44, !10, i64 88, !15, i64 96, !15, i64 98, !10, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !13, i64 120, !15, i64 124, !15, i64 126, !13, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !17, i64 0, !13, i64 184, !19, i64 188}
!17 = !{!"__DMA_HandleTypeDef", !10, i64 0, !18, i64 8, !13, i64 56, !13, i64 60, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !13, i64 120, !13, i64 124, !13, i64 128, !10, i64 136, !10, i64 144, !13, i64 152, !10, i64 160, !10, i64 168, !13, i64 176}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44}
!19 = !{!"", !13, i64 0}
!20 = !{!"", !13, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !13, i64 88, !21, i64 92, !21, i64 93, !21, i64 94, !21, i64 95, !21, i64 96}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!6, !10, i64 776}
!23 = !{!6, !13, i64 808}
!24 = !{!6, !13, i64 820}
!25 = !{!6, !21, i64 863}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!6, !13, i64 748}


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