; 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_Encoder_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
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %24

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

24:                                               ; preds = %2
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 4
  br i1 %26, label %27, label %44

27:                                               ; preds = %24
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %30, i32 noundef 4, i32 noundef 0)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.TIM_TypeDef, ptr %33, i32 0, i32 3
  %35 = load volatile i32, ptr %34, align 4, !tbaa !14
  %36 = zext i32 %35 to i64
  %37 = and i64 %36, -1025
  %38 = trunc i64 %37 to i32
  store volatile i32 %38, ptr %34, align 4, !tbaa !14
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %39, i32 0, i32 3
  %41 = getelementptr inbounds [7 x ptr], ptr %40, i64 0, i64 2
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = call i32 @HAL_DMA_Abort_IT(ptr noundef %42)
  br label %77

44:                                               ; preds = %24
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %47, i32 noundef 0, i32 noundef 0)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %50, i32 noundef 4, i32 noundef 0)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.TIM_TypeDef, ptr %53, i32 0, i32 3
  %55 = load volatile i32, ptr %54, align 4, !tbaa !14
  %56 = zext i32 %55 to i64
  %57 = and i64 %56, -513
  %58 = trunc i64 %57 to i32
  store volatile i32 %58, ptr %54, align 4, !tbaa !14
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.TIM_TypeDef, ptr %61, i32 0, i32 3
  %63 = load volatile i32, ptr %62, align 4, !tbaa !14
  %64 = zext i32 %63 to i64
  %65 = and i64 %64, -1025
  %66 = trunc i64 %65 to i32
  store volatile i32 %66, ptr %62, align 4, !tbaa !14
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %67, i32 0, i32 3
  %69 = getelementptr inbounds [7 x ptr], ptr %68, i64 0, i64 1
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = call i32 @HAL_DMA_Abort_IT(ptr noundef %70)
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %72, i32 0, i32 3
  %74 = getelementptr inbounds [7 x ptr], ptr %73, i64 0, i64 2
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = call i32 @HAL_DMA_Abort_IT(ptr noundef %75)
  br label %77

77:                                               ; preds = %44, %27
  br label %78

78:                                               ; preds = %77, %7
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !11
  %83 = getelementptr inbounds %struct.TIM_TypeDef, ptr %82, i32 0, i32 8
  %84 = load volatile i32, ptr %83, align 4, !tbaa !16
  %85 = and i32 %84, 4369
  %86 = zext i32 %85 to i64
  %87 = icmp eq i64 %86, 0
  br i1 %87, label %88, label %107

88:                                               ; preds = %79
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !11
  %92 = getelementptr inbounds %struct.TIM_TypeDef, ptr %91, i32 0, i32 8
  %93 = load volatile i32, ptr %92, align 4, !tbaa !16
  %94 = and i32 %93, 1092
  %95 = zext i32 %94 to i64
  %96 = icmp eq i64 %95, 0
  br i1 %96, label %97, label %106

97:                                               ; preds = %88
  %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 0
  %102 = load volatile i32, ptr %101, align 4, !tbaa !17
  %103 = zext i32 %102 to i64
  %104 = and i64 %103, -2
  %105 = trunc i64 %104 to i32
  store volatile i32 %105, ptr %101, align 4, !tbaa !17
  br label %106

106:                                              ; preds = %97, %88
  br label %107

107:                                              ; preds = %106, %79
  br label %108

108:                                              ; preds = %107
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %109, i32 0, i32 5
  store volatile i32 1, ptr %110, align 4, !tbaa !18
  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 0}
!18 = !{!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"

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_Encoder_Stop_DMA(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  switch i32 %1, label %14 [
    i32 0, label %4
    i32 4, label %9
  ]

4:                                                ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 12
  %7 = load volatile i32, ptr %6, align 4, !tbaa !12
  %8 = and i32 %7, -513
  store volatile i32 %8, ptr %6, align 4, !tbaa !12
  br label %25

9:                                                ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 4, i32 noundef 0)
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 12
  %12 = load volatile i32, ptr %11, align 4, !tbaa !12
  %13 = and i32 %12, -1025
  store volatile i32 %13, ptr %11, align 4, !tbaa !12
  br label %25

14:                                               ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @TIM_CCxChannelCmd(ptr noundef %15, i32 noundef 4, i32 noundef 0)
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 12
  %18 = load volatile i32, ptr %17, align 4, !tbaa !12
  %19 = and i32 %18, -513
  store volatile i32 %19, ptr %17, align 4, !tbaa !12
  %20 = load volatile i32, ptr %17, align 4, !tbaa !12
  %21 = and i32 %20, -1025
  store volatile i32 %21, ptr %17, align 4, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = tail call i32 @HAL_DMA_Abort_IT(ptr noundef %23) #2
  br label %25

25:                                               ; preds = %4, %14, %9
  %.sink = phi i64 [ 48, %4 ], [ 56, %14 ], [ 56, %9 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = tail call i32 @HAL_DMA_Abort_IT(ptr noundef %27) #2
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 32
  %31 = load volatile i32, ptr %30, align 4, !tbaa !15
  %32 = and i32 %31, 4369
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %41

34:                                               ; preds = %25
  %35 = load volatile i32, ptr %30, align 4, !tbaa !15
  %36 = and i32 %35, 1092
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load volatile i32, ptr %29, align 4, !tbaa !16
  %40 = and i32 %39, -2
  store volatile i32 %40, ptr %29, align 4, !tbaa !16
  br label %41

41:                                               ; preds = %25, %38, %34
  %42 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 1, ptr %42, align 4, !tbaa !17
  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" }
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, !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 0}
!17 = !{!6, !11, i64 100}


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