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

; 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_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: nounwind uwtable
define dso_local i32 @HAL_RS485Ex_Init(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %102

15:                                               ; preds = %4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %16, i32 0, i32 18
  %18 = load volatile i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %21, i32 0, i32 17
  store i32 0, ptr %22, align 8, !tbaa !16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void @HAL_UART_MspInit(ptr noundef %23)
  br label %24

24:                                               ; preds = %20, %15
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %25, i32 0, i32 18
  store volatile i32 36, ptr %26, align 4, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds %struct.USART_TypeDef, ptr %29, i32 0, i32 0
  %31 = load volatile i32, ptr %30, align 4, !tbaa !18
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, -2
  %34 = trunc i64 %33 to i32
  store volatile i32 %34, ptr %30, align 4, !tbaa !18
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call i32 @UART_SetConfig(ptr noundef %35)
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %24
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %102

39:                                               ; preds = %24
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds %struct.UART_AdvFeatureInitTypeDef, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !20
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %39
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @UART_AdvFeatureConfig(ptr noundef %46)
  br label %47

47:                                               ; preds = %45, %39
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %struct.USART_TypeDef, ptr %50, i32 0, i32 2
  %52 = load volatile i32, ptr %51, align 4, !tbaa !21
  %53 = zext i32 %52 to i64
  %54 = or i64 %53, 16384
  %55 = trunc i64 %54 to i32
  store volatile i32 %55, ptr %51, align 4, !tbaa !21
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = getelementptr inbounds %struct.USART_TypeDef, ptr %58, i32 0, i32 2
  %60 = load volatile i32, ptr %59, align 4, !tbaa !21
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, -32769
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = or i64 %62, %64
  %66 = trunc i64 %65 to i32
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = getelementptr inbounds %struct.USART_TypeDef, ptr %69, i32 0, i32 2
  store volatile i32 %66, ptr %70, align 4, !tbaa !21
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = shl i32 %71, 21
  store i32 %72, ptr %10, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = shl i32 %73, 16
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = or i32 %75, %74
  store i32 %76, ptr %10, align 4, !tbaa !9
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  %80 = getelementptr inbounds %struct.USART_TypeDef, ptr %79, i32 0, i32 0
  %81 = load volatile i32, ptr %80, align 4, !tbaa !18
  %82 = zext i32 %81 to i64
  %83 = and i64 %82, -67043329
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = or i64 %83, %85
  %87 = trunc i64 %86 to i32
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  %91 = getelementptr inbounds %struct.USART_TypeDef, ptr %90, i32 0, i32 0
  store volatile i32 %87, ptr %91, align 4, !tbaa !18
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.__UART_HandleTypeDef, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !17
  %95 = getelementptr inbounds %struct.USART_TypeDef, ptr %94, i32 0, i32 0
  %96 = load volatile i32, ptr %95, align 4, !tbaa !18
  %97 = zext i32 %96 to i64
  %98 = or i64 %97, 1
  %99 = trunc i64 %98 to i32
  store volatile i32 %99, ptr %95, align 4, !tbaa !18
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = call i32 @UART_CheckIdleState(ptr noundef %100)
  store i32 %101, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %102

102:                                              ; preds = %47, %38, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %103 = load i32, ptr %5, align 4
  ret i32 %103
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @HAL_UART_MspInit(ptr noundef) #2

declare i32 @UART_SetConfig(ptr noundef) #2

declare void @UART_AdvFeatureConfig(ptr noundef) #2

declare i32 @UART_CheckIdleState(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 164}
!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 160}
!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 = !{!12, !10, i64 44}
!21 = !{!19, !10, i64 8}


; 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 @HAL_RS485Ex_Init(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %39, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 164
  %8 = load volatile i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 0, ptr %11, align 8, !tbaa !14
  tail call void @HAL_UART_MspInit(ptr noundef nonnull %0) #2
  br label %12

12:                                               ; preds = %10, %6
  store volatile i32 36, ptr %7, align 4, !tbaa !5
  %13 = load ptr, ptr %0, align 8, !tbaa !15
  %14 = load volatile i32, ptr %13, align 4, !tbaa !16
  %15 = and i32 %14, -2
  store volatile i32 %15, ptr %13, align 4, !tbaa !16
  %16 = tail call i32 @UART_SetConfig(ptr noundef nonnull %0) #2
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %39, label %18

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 44
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %22, label %21

21:                                               ; preds = %18
  tail call void @UART_AdvFeatureConfig(ptr noundef nonnull %0) #2
  br label %22

22:                                               ; preds = %21, %18
  %23 = load ptr, ptr %0, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load volatile i32, ptr %24, align 4, !tbaa !19
  %26 = or i32 %25, 16384
  store volatile i32 %26, ptr %24, align 4, !tbaa !19
  %27 = load volatile i32, ptr %24, align 4, !tbaa !19
  %28 = and i32 %27, -32769
  %29 = or i32 %28, %1
  store volatile i32 %29, ptr %24, align 4, !tbaa !19
  %30 = shl i32 %2, 21
  %31 = shl i32 %3, 16
  %32 = or i32 %31, %30
  %33 = load volatile i32, ptr %23, align 4, !tbaa !16
  %34 = and i32 %33, -67043329
  %35 = or i32 %32, %34
  store volatile i32 %35, ptr %23, align 4, !tbaa !16
  %36 = load volatile i32, ptr %23, align 4, !tbaa !16
  %37 = or i32 %36, 1
  store volatile i32 %37, ptr %23, align 4, !tbaa !16
  %38 = tail call i32 @UART_CheckIdleState(ptr noundef nonnull %0) #2
  br label %39

39:                                               ; preds = %12, %4, %22
  %.0 = phi i32 [ %38, %22 ], [ 1, %4 ], [ 1, %12 ]
  ret i32 %.0
}

declare void @HAL_UART_MspInit(ptr noundef) local_unnamed_addr #1

declare i32 @UART_SetConfig(ptr noundef) local_unnamed_addr #1

declare void @UART_AdvFeatureConfig(ptr noundef) local_unnamed_addr #1

declare i32 @UART_CheckIdleState(ptr 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 164}
!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 160}
!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 = !{!6, !11, i64 44}
!19 = !{!17, !11, i64 8}


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