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

; 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.TIM_HandleTypeDef = type { ptr, %struct.TIM_Base_InitTypeDef, i32, [7 x ptr], i32, i32 }
%struct.TIM_Base_InitTypeDef = type { i32, i32, i32, i32, i32, i32 }
%struct.TIM_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 }

declare i32 @HAL_DMA_Abort_IT(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @TIM_CCxChannelCmd(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIM_OC_Stop_DMA(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %5, label %62 [
    i32 0, label %6
    i32 4, label %20
    i32 8, label %34
    i32 12, label %48
  ]

6:                                                ; preds = %2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.TIM_TypeDef, ptr %9, i32 0, i32 3
  %11 = load volatile i32, ptr %10, align 4, !tbaa !14
  %12 = zext i32 %11 to i64
  %13 = and i64 %12, -513
  %14 = trunc i64 %13 to i32
  store volatile i32 %14, ptr %10, align 4, !tbaa !14
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %15, i32 0, i32 3
  %17 = getelementptr inbounds [7 x ptr], ptr %16, i64 0, i64 1
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = call i32 @HAL_DMA_Abort_IT(ptr noundef %18)
  br label %63

20:                                               ; preds = %2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.TIM_TypeDef, ptr %23, i32 0, i32 3
  %25 = load volatile i32, ptr %24, align 4, !tbaa !14
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, -1025
  %28 = trunc i64 %27 to i32
  store volatile i32 %28, ptr %24, align 4, !tbaa !14
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %29, i32 0, i32 3
  %31 = getelementptr inbounds [7 x ptr], ptr %30, i64 0, i64 2
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = call i32 @HAL_DMA_Abort_IT(ptr noundef %32)
  br label %63

34:                                               ; preds = %2
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.TIM_TypeDef, ptr %37, i32 0, i32 3
  %39 = load volatile i32, ptr %38, align 4, !tbaa !14
  %40 = zext i32 %39 to i64
  %41 = and i64 %40, -2049
  %42 = trunc i64 %41 to i32
  store volatile i32 %42, ptr %38, align 4, !tbaa !14
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %43, i32 0, i32 3
  %45 = getelementptr inbounds [7 x ptr], ptr %44, i64 0, i64 3
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = call i32 @HAL_DMA_Abort_IT(ptr noundef %46)
  br label %63

48:                                               ; preds = %2
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.TIM_TypeDef, ptr %51, i32 0, i32 3
  %53 = load volatile i32, ptr %52, align 4, !tbaa !14
  %54 = zext i32 %53 to i64
  %55 = and i64 %54, -4097
  %56 = trunc i64 %55 to i32
  store volatile i32 %56, ptr %52, align 4, !tbaa !14
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds [7 x ptr], ptr %58, i64 0, i64 4
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = call i32 @HAL_DMA_Abort_IT(ptr noundef %60)
  br label %63

62:                                               ; preds = %2
  br label %63

63:                                               ; preds = %62, %48, %34, %20, %6
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load i32, ptr %4, align 4, !tbaa !9
  call void @TIM_CCxChannelCmd(ptr noundef %66, i32 noundef %67, i32 noundef 0)
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  %71 = icmp eq ptr %70, inttoptr (i64 1073807360 to ptr)
  br i1 %71, label %92, label %72

72:                                               ; preds = %63
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = icmp eq ptr %75, inttoptr (i64 1073808384 to ptr)
  br i1 %76, label %92, label %77

77:                                               ; preds = %72
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = icmp eq ptr %80, inttoptr (i64 1073823744 to ptr)
  br i1 %81, label %92, label %82

82:                                               ; preds = %77
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = icmp eq ptr %85, inttoptr (i64 1073824768 to ptr)
  br i1 %86, label %92, label %87

87:                                               ; preds = %82
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  %91 = icmp eq ptr %90, inttoptr (i64 1073825792 to ptr)
  br label %92

92:                                               ; preds = %87, %82, %77, %72, %63
  %93 = phi i1 [ true, %82 ], [ true, %77 ], [ true, %72 ], [ true, %63 ], [ %91, %87 ]
  %94 = zext i1 %93 to i32
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %127

96:                                               ; preds = %92
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  %101 = getelementptr inbounds %struct.TIM_TypeDef, ptr %100, i32 0, i32 8
  %102 = load volatile i32, ptr %101, align 4, !tbaa !16
  %103 = and i32 %102, 4369
  %104 = zext i32 %103 to i64
  %105 = icmp eq i64 %104, 0
  br i1 %105, label %106, label %125

106:                                              ; preds = %97
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !11
  %110 = getelementptr inbounds %struct.TIM_TypeDef, ptr %109, i32 0, i32 8
  %111 = load volatile i32, ptr %110, align 4, !tbaa !16
  %112 = and i32 %111, 1092
  %113 = zext i32 %112 to i64
  %114 = icmp eq i64 %113, 0
  br i1 %114, label %115, label %124

115:                                              ; preds = %106
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !11
  %119 = getelementptr inbounds %struct.TIM_TypeDef, ptr %118, i32 0, i32 17
  %120 = load volatile i32, ptr %119, align 4, !tbaa !17
  %121 = zext i32 %120 to i64
  %122 = and i64 %121, -32769
  %123 = trunc i64 %122 to i32
  store volatile i32 %123, ptr %119, align 4, !tbaa !17
  br label %124

124:                                              ; preds = %115, %106
  br label %125

125:                                              ; preds = %124, %97
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126, %92
  br label %128

128:                                              ; preds = %127
  %129 = load ptr, ptr %3, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %129, i32 0, i32 0
  %131 = load ptr, ptr %130, align 8, !tbaa !11
  %132 = getelementptr inbounds %struct.TIM_TypeDef, ptr %131, i32 0, i32 8
  %133 = load volatile i32, ptr %132, align 4, !tbaa !16
  %134 = and i32 %133, 4369
  %135 = zext i32 %134 to i64
  %136 = icmp eq i64 %135, 0
  br i1 %136, label %137, label %156

137:                                              ; preds = %128
  %138 = load ptr, ptr %3, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %138, i32 0, i32 0
  %140 = load ptr, ptr %139, align 8, !tbaa !11
  %141 = getelementptr inbounds %struct.TIM_TypeDef, ptr %140, i32 0, i32 8
  %142 = load volatile i32, ptr %141, align 4, !tbaa !16
  %143 = and i32 %142, 1092
  %144 = zext i32 %143 to i64
  %145 = icmp eq i64 %144, 0
  br i1 %145, label %146, label %155

146:                                              ; preds = %137
  %147 = load ptr, ptr %3, align 8, !tbaa !5
  %148 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %147, i32 0, i32 0
  %149 = load ptr, ptr %148, align 8, !tbaa !11
  %150 = getelementptr inbounds %struct.TIM_TypeDef, ptr %149, i32 0, i32 0
  %151 = load volatile i32, ptr %150, align 4, !tbaa !18
  %152 = zext i32 %151 to i64
  %153 = and i64 %152, -2
  %154 = trunc i64 %153 to i32
  store volatile i32 %154, ptr %150, align 4, !tbaa !18
  br label %155

155:                                              ; preds = %146, %137
  br label %156

156:                                              ; preds = %155, %128
  br label %157

157:                                              ; preds = %156
  %158 = load ptr, ptr %3, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %158, i32 0, i32 5
  store volatile i32 1, ptr %159, align 4, !tbaa !19
  ret i32 0
}

attributes #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 = { 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, !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 32, !7, i64 40, !10, i64 96, !10, i64 100}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = !{!15, !10, i64 12}
!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}
!16 = !{!15, !10, i64 32}
!17 = !{!15, !10, i64 68}
!18 = !{!15, !10, i64 0}
!19 = !{!12, !10, i64 100}


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

@switch.table.HAL_TIM_OC_Stop_DMA = private unnamed_addr constant [4 x i32] [i32 -513, i32 -1025, i32 -2049, i32 -4097], align 4

declare i32 @HAL_DMA_Abort_IT(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @TIM_CCxChannelCmd(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @HAL_TIM_OC_Stop_DMA(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 30)
  %4 = icmp ult i32 %3, 4
  br i1 %4, label %switch.lookup, label %16

switch.lookup:                                    ; preds = %2
  %5 = zext nneg i32 %3 to i64
  %switch.gep = getelementptr inbounds [4 x i32], ptr @switch.table.HAL_TIM_OC_Stop_DMA, i64 0, i64 %5
  %switch.load = load i32, ptr %switch.gep, align 4
  %6 = shl nuw nsw i32 %3, 3
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 12
  %9 = load volatile i32, ptr %8, align 4, !tbaa !12
  %10 = and i32 %9, %switch.load
  store volatile i32 %10, ptr %8, align 4, !tbaa !12
  %11 = zext nneg i32 %6 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = tail call i32 @HAL_DMA_Abort_IT(ptr noundef %14) #3
  br label %16

16:                                               ; preds = %2, %switch.lookup
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @TIM_CCxChannelCmd(ptr noundef %17, i32 noundef %1, i32 noundef 0)
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %magicptr23 = ptrtoint ptr %18 to i64
  switch i64 %magicptr23, label %31 [
    i64 1073807360, label %.critedge
    i64 1073808384, label %.critedge
    i64 1073823744, label %.critedge
    i64 1073824768, label %.critedge
    i64 1073825792, label %.critedge
  ]

.critedge:                                        ; preds = %16, %16, %16, %16, %16
  %19 = getelementptr inbounds i8, ptr %18, i64 32
  %20 = load volatile i32, ptr %19, align 4, !tbaa !15
  %21 = and i32 %20, 4369
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %31

23:                                               ; preds = %.critedge
  %24 = load volatile i32, ptr %19, align 4, !tbaa !15
  %25 = and i32 %24, 1092
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %23
  %28 = getelementptr inbounds i8, ptr %18, i64 68
  %29 = load volatile i32, ptr %28, align 4, !tbaa !16
  %30 = and i32 %29, -32769
  store volatile i32 %30, ptr %28, align 4, !tbaa !16
  br label %31

31:                                               ; preds = %16, %.critedge, %27, %23
  %32 = getelementptr inbounds i8, ptr %18, i64 32
  %33 = load volatile i32, ptr %32, align 4, !tbaa !15
  %34 = and i32 %33, 4369
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %31
  %37 = load volatile i32, ptr %32, align 4, !tbaa !15
  %38 = and i32 %37, 1092
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %36
  %41 = load volatile i32, ptr %18, align 4, !tbaa !17
  %42 = and i32 %41, -2
  store volatile i32 %42, ptr %18, align 4, !tbaa !17
  br label %43

43:                                               ; preds = %31, %40, %36
  %44 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 1, ptr %44, align 4, !tbaa !18
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #2

attributes #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 32, !8, i64 40, !11, i64 96, !11, i64 100}
!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 = !{!"int", !8, i64 0}
!12 = !{!13, !11, i64 12}
!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}
!14 = !{!7, !7, i64 0}
!15 = !{!13, !11, i64 32}
!16 = !{!13, !11, i64 68}
!17 = !{!13, !11, i64 0}
!18 = !{!6, !11, i64 100}


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