; 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.__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.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 }

; 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_TIM_Base_Start_DMA(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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %10, i32 0, i32 5
  %12 = load volatile i32, ptr %11, align 4, !tbaa !11
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 2, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

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

20:                                               ; preds = %15
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load i16, ptr %7, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = icmp ugt i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

28:                                               ; preds = %23, %20
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %29, i32 0, i32 5
  store volatile i32 2, ptr %30, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %28
  br label %33

32:                                               ; preds = %15
  br label %33

33:                                               ; preds = %32, %31
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %35, i32 0, i32 3
  %37 = getelementptr inbounds [7 x ptr], ptr %36, i64 0, i64 0
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %38, i32 0, i32 5
  store ptr @TIM_DMAPeriodElapsedCplt, ptr %39, align 8, !tbaa !15
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %40, i32 0, i32 3
  %42 = getelementptr inbounds [7 x ptr], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %43, i32 0, i32 6
  store ptr @TIM_DMAPeriodElapsedHalfCplt, ptr %44, align 8, !tbaa !18
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %45, i32 0, i32 3
  %47 = getelementptr inbounds [7 x ptr], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %48, i32 0, i32 9
  store ptr @TIM_DMAError, ptr %49, align 8, !tbaa !19
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %50, i32 0, i32 3
  %52 = getelementptr inbounds [7 x ptr], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = ptrtoint ptr %54 to i32
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !20
  %59 = getelementptr inbounds %struct.TIM_TypeDef, ptr %58, i32 0, i32 11
  %60 = ptrtoint ptr %59 to i32
  %61 = load i16, ptr %7, align 2, !tbaa !9
  %62 = zext i16 %61 to i32
  %63 = call i32 @HAL_DMA_Start_IT(ptr noundef %53, i32 noundef %55, i32 noundef %60, i32 noundef %62)
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %34
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

66:                                               ; preds = %34
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = getelementptr inbounds %struct.TIM_TypeDef, ptr %69, i32 0, i32 3
  %71 = load volatile i32, ptr %70, align 4, !tbaa !21
  %72 = zext i32 %71 to i64
  %73 = or i64 %72, 256
  %74 = trunc i64 %73 to i32
  store volatile i32 %74, ptr %70, align 4, !tbaa !21
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !20
  %78 = getelementptr inbounds %struct.TIM_TypeDef, ptr %77, i32 0, i32 2
  %79 = load volatile i32, ptr %78, align 4, !tbaa !23
  %80 = zext i32 %79 to i64
  %81 = and i64 %80, 65543
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %8, align 4, !tbaa !24
  %83 = load i32, ptr %8, align 4, !tbaa !24
  %84 = zext i32 %83 to i64
  %85 = icmp eq i64 %84, 6
  br i1 %85, label %99, label %86

86:                                               ; preds = %66
  %87 = load i32, ptr %8, align 4, !tbaa !24
  %88 = zext i32 %87 to i64
  %89 = icmp eq i64 %88, 65536
  br i1 %89, label %99, label %90

90:                                               ; preds = %86
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !20
  %94 = getelementptr inbounds %struct.TIM_TypeDef, ptr %93, i32 0, i32 0
  %95 = load volatile i32, ptr %94, align 4, !tbaa !25
  %96 = zext i32 %95 to i64
  %97 = or i64 %96, 1
  %98 = trunc i64 %97 to i32
  store volatile i32 %98, ptr %94, align 4, !tbaa !25
  br label %99

99:                                               ; preds = %90, %86, %66
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %100

100:                                              ; preds = %99, %65, %27, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %101 = load i32, ptr %4, align 4
  ret i32 %101
}

; Function Attrs: nounwind uwtable
declare hidden void @TIM_DMAPeriodElapsedCplt(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @TIM_DMAPeriodElapsedHalfCplt(ptr noundef) #1

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

declare i32 @HAL_DMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 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, !14, i64 100}
!12 = !{!"", !6, i64 0, !13, i64 8, !14, i64 32, !7, i64 40, !14, i64 96, !14, i64 100}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 72}
!16 = !{!"__DMA_HandleTypeDef", !6, i64 0, !17, i64 8, !14, i64 56, !14, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !14, i64 120, !14, i64 124, !14, i64 128, !6, i64 136, !6, i64 144, !14, i64 152, !6, i64 160, !6, i64 168, !14, i64 176}
!17 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44}
!18 = !{!16, !6, i64 80}
!19 = !{!16, !6, i64 104}
!20 = !{!12, !6, i64 0}
!21 = !{!22, !14, i64 12}
!22 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !14, i64 48, !14, i64 52, !14, i64 56, !14, i64 60, !14, i64 64, !14, i64 68, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !14, i64 92, !14, i64 96, !14, i64 100, !14, i64 104}
!23 = !{!22, !14, i64 8}
!24 = !{!14, !14, i64 0}
!25 = !{!22, !14, i64 0}


; 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 range(i32 0, 3) i32 @HAL_TIM_Base_Start_DMA(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 100
  %5 = load volatile i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %42, label %7

7:                                                ; preds = %3
  %8 = load volatile i32, ptr %4, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = icmp eq ptr %1, null
  %12 = icmp ne i16 %2, 0
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %42, label %13

13:                                               ; preds = %10
  store volatile i32 2, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %13, %7
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 72
  store ptr @TIM_DMAPeriodElapsedCplt, ptr %17, align 8, !tbaa !13
  %18 = load ptr, ptr %15, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %18, i64 80
  store ptr @TIM_DMAPeriodElapsedHalfCplt, ptr %19, align 8, !tbaa !16
  %20 = load ptr, ptr %15, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %20, i64 104
  store ptr @TIM_DMAError, ptr %21, align 8, !tbaa !17
  %22 = load ptr, ptr %15, align 8, !tbaa !12
  %23 = ptrtoint ptr %1 to i64
  %24 = trunc i64 %23 to i32
  %25 = load ptr, ptr %0, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %25, i64 44
  %27 = ptrtoint ptr %26 to i64
  %28 = trunc i64 %27 to i32
  %29 = zext i16 %2 to i32
  %30 = tail call i32 @HAL_DMA_Start_IT(ptr noundef %22, i32 noundef %24, i32 noundef %28, i32 noundef %29) #2
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %31, label %42

31:                                               ; preds = %14
  %32 = load ptr, ptr %0, align 8, !tbaa !18
  %33 = getelementptr inbounds i8, ptr %32, i64 12
  %34 = load volatile i32, ptr %33, align 4, !tbaa !19
  %35 = or i32 %34, 256
  store volatile i32 %35, ptr %33, align 4, !tbaa !19
  %36 = getelementptr inbounds i8, ptr %32, i64 8
  %37 = load volatile i32, ptr %36, align 4, !tbaa !21
  %38 = and i32 %37, 65543
  switch i32 %38, label %39 [
    i32 65536, label %42
    i32 6, label %42
  ]

39:                                               ; preds = %31
  %40 = load volatile i32, ptr %32, align 4, !tbaa !22
  %41 = or i32 %40, 1
  store volatile i32 %41, ptr %32, align 4, !tbaa !22
  br label %42

42:                                               ; preds = %39, %31, %31, %14, %10, %3
  %.0 = phi i32 [ 2, %3 ], [ 1, %10 ], [ 1, %14 ], [ 0, %31 ], [ 0, %31 ], [ 0, %39 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @TIM_DMAPeriodElapsedCplt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @TIM_DMAPeriodElapsedHalfCplt(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @TIM_DMAError(ptr noundef) #0

declare i32 @HAL_DMA_Start_IT(ptr noundef, i32 noundef, i32 noundef, i32 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 100}
!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 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 72}
!14 = !{!"__DMA_HandleTypeDef", !7, i64 0, !15, i64 8, !11, i64 56, !11, i64 60, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !7, i64 136, !7, i64 144, !11, i64 152, !7, i64 160, !7, i64 168, !11, i64 176}
!15 = !{!"", !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}
!16 = !{!14, !7, i64 80}
!17 = !{!14, !7, i64 104}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !11, i64 12}
!20 = !{!"", !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}
!21 = !{!20, !11, i64 8}
!22 = !{!20, !11, i64 0}


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