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

; 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.__SPI_HandleTypeDef = type { ptr, %struct.SPI_InitTypeDef, ptr, i16, i16, ptr, i16, i16, i32, ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.SPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SPI_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, [3 x 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_SPIEx_ConfigureUnderrun(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %10

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

15:                                               ; preds = %10
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %138

16:                                               ; preds = %10
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %17, i32 0, i32 13
  store i32 1, ptr %18, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %16
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %22, i32 0, i32 14
  %24 = load volatile i32, ptr %23, align 4, !tbaa !15
  %25 = icmp ne i32 %24, 1
  br i1 %25, label %33, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.SPI_InitTypeDef, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = zext i32 %30 to i64
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %42

33:                                               ; preds = %26, %21
  store i32 2, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %34, i32 0, i32 14
  store volatile i32 1, ptr %35, align 4, !tbaa !15
  br label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %37, i32 0, i32 13
  store i32 0, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %41, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %138

42:                                               ; preds = %26
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %struct.SPI_TypeDef, ptr %45, i32 0, i32 0
  %47 = load volatile i32, ptr %46, align 4, !tbaa !18
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, 1
  %50 = icmp ne i64 %49, 1
  br i1 %50, label %51, label %82

51:                                               ; preds = %42
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = getelementptr inbounds %struct.SPI_TypeDef, ptr %54, i32 0, i32 2
  %56 = load volatile i32, ptr %55, align 4, !tbaa !20
  %57 = zext i32 %56 to i64
  %58 = and i64 %57, -6145
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = or i64 %58, %60
  %62 = trunc i64 %61 to i32
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = getelementptr inbounds %struct.SPI_TypeDef, ptr %65, i32 0, i32 2
  store volatile i32 %62, ptr %66, align 4, !tbaa !20
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = getelementptr inbounds %struct.SPI_TypeDef, ptr %69, i32 0, i32 2
  %71 = load volatile i32, ptr %70, align 4, !tbaa !20
  %72 = zext i32 %71 to i64
  %73 = and i64 %72, -1537
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = or i64 %73, %75
  %77 = trunc i64 %76 to i32
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !17
  %81 = getelementptr inbounds %struct.SPI_TypeDef, ptr %80, i32 0, i32 2
  store volatile i32 %77, ptr %81, align 4, !tbaa !20
  br label %129

82:                                               ; preds = %42
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !17
  %86 = getelementptr inbounds %struct.SPI_TypeDef, ptr %85, i32 0, i32 0
  %87 = load volatile i32, ptr %86, align 4, !tbaa !18
  %88 = zext i32 %87 to i64
  %89 = and i64 %88, -2
  %90 = trunc i64 %89 to i32
  store volatile i32 %90, ptr %86, align 4, !tbaa !18
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !17
  %94 = getelementptr inbounds %struct.SPI_TypeDef, ptr %93, i32 0, i32 2
  %95 = load volatile i32, ptr %94, align 4, !tbaa !20
  %96 = zext i32 %95 to i64
  %97 = and i64 %96, -6145
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = or i64 %97, %99
  %101 = trunc i64 %100 to i32
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !17
  %105 = getelementptr inbounds %struct.SPI_TypeDef, ptr %104, i32 0, i32 2
  store volatile i32 %101, ptr %105, align 4, !tbaa !20
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %106, i32 0, i32 0
  %108 = load ptr, ptr %107, align 8, !tbaa !17
  %109 = getelementptr inbounds %struct.SPI_TypeDef, ptr %108, i32 0, i32 2
  %110 = load volatile i32, ptr %109, align 4, !tbaa !20
  %111 = zext i32 %110 to i64
  %112 = and i64 %111, -1537
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = zext i32 %113 to i64
  %115 = or i64 %112, %114
  %116 = trunc i64 %115 to i32
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %117, i32 0, i32 0
  %119 = load ptr, ptr %118, align 8, !tbaa !17
  %120 = getelementptr inbounds %struct.SPI_TypeDef, ptr %119, i32 0, i32 2
  store volatile i32 %116, ptr %120, align 4, !tbaa !20
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %121, i32 0, i32 0
  %123 = load ptr, ptr %122, align 8, !tbaa !17
  %124 = getelementptr inbounds %struct.SPI_TypeDef, ptr %123, i32 0, i32 0
  %125 = load volatile i32, ptr %124, align 4, !tbaa !18
  %126 = zext i32 %125 to i64
  %127 = or i64 %126, 1
  %128 = trunc i64 %127 to i32
  store volatile i32 %128, ptr %124, align 4, !tbaa !18
  br label %129

129:                                              ; preds = %82, %51
  %130 = load ptr, ptr %5, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %130, i32 0, i32 14
  store volatile i32 1, ptr %131, align 4, !tbaa !15
  br label %132

132:                                              ; preds = %129
  %133 = load ptr, ptr %5, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.__SPI_HandleTypeDef, ptr %133, i32 0, i32 13
  store i32 0, ptr %134, align 8, !tbaa !11
  br label %135

135:                                              ; preds = %132
  br label %136

136:                                              ; preds = %135
  %137 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %137, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %138

138:                                              ; preds = %136, %40, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %139 = load i32, ptr %4, align 4
  ret i32 %139
}

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, !10, i64 160}
!12 = !{!"__SPI_HandleTypeDef", !6, i64 0, !13, i64 8, !6, i64 96, !14, i64 104, !14, i64 106, !6, i64 112, !14, i64 120, !14, i64 122, !10, i64 124, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168}
!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, !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}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 164}
!16 = !{!12, !10, i64 8}
!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, !7, i64 36, !10, i64 48, !7, i64 52, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80}
!20 = !{!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: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_SPIEx_ConfigureUnderrun(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 160
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %37, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 164
  %9 = load volatile i32, ptr %8, align 4, !tbaa !13
  %.not = icmp eq i32 %9, 1
  br i1 %.not, label %10, label %.sink.split

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %.not25 = icmp eq i32 %12, 0
  br i1 %.not25, label %13, label %.sink.split

13:                                               ; preds = %10
  %14 = load ptr, ptr %0, align 8, !tbaa !15
  %15 = load volatile i32, ptr %14, align 4, !tbaa !16
  %16 = and i32 %15, 1
  %.not26.not = icmp eq i32 %16, 0
  br i1 %.not26.not, label %17, label %25

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  %19 = load volatile i32, ptr %18, align 4, !tbaa !18
  %20 = and i32 %19, -6145
  %21 = or i32 %20, %1
  store volatile i32 %21, ptr %18, align 4, !tbaa !18
  %22 = load volatile i32, ptr %18, align 4, !tbaa !18
  %23 = and i32 %22, -1537
  %24 = or i32 %23, %2
  store volatile i32 %24, ptr %18, align 4, !tbaa !18
  br label %.sink.split

25:                                               ; preds = %13
  %26 = load volatile i32, ptr %14, align 4, !tbaa !16
  %27 = and i32 %26, -2
  store volatile i32 %27, ptr %14, align 4, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %14, i64 8
  %29 = load volatile i32, ptr %28, align 4, !tbaa !18
  %30 = and i32 %29, -6145
  %31 = or i32 %30, %1
  store volatile i32 %31, ptr %28, align 4, !tbaa !18
  %32 = load volatile i32, ptr %28, align 4, !tbaa !18
  %33 = and i32 %32, -1537
  %34 = or i32 %33, %2
  store volatile i32 %34, ptr %28, align 4, !tbaa !18
  %35 = load volatile i32, ptr %14, align 4, !tbaa !16
  %36 = or i32 %35, 1
  store volatile i32 %36, ptr %14, align 4, !tbaa !16
  br label %.sink.split

.sink.split:                                      ; preds = %17, %25, %7, %10
  %.0.ph = phi i32 [ 2, %10 ], [ 2, %7 ], [ 0, %25 ], [ 0, %17 ]
  store volatile i32 1, ptr %8, align 4, !tbaa !13
  store i32 0, ptr %4, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %.sink.split, %3
  %.0 = phi i32 [ 2, %3 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse 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, !11, i64 160}
!6 = !{!"__SPI_HandleTypeDef", !7, i64 0, !10, i64 8, !7, i64 96, !12, i64 104, !12, i64 106, !7, i64 112, !12, i64 120, !12, i64 122, !11, i64 124, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !11, i64 160, !11, i64 164, !11, i64 168}
!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, 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 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 164}
!14 = !{!6, !11, i64 8}
!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, !8, i64 36, !11, i64 48, !8, i64 52, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80}
!18 = !{!17, !11, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass