; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_tim_ex)

; 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, [6 x i32], [4 x 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 }
%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 }

declare void @TIM_DMAError(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIMEx_ConfigCommutEvent_DMA(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
  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
  br label %8

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

13:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  br label %116

14:                                               ; preds = %8
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %15, i32 0, i32 4
  store i32 1, ptr %16, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %41, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = icmp eq i64 %23, 16
  br i1 %24, label %41, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = icmp eq i64 %27, 32
  br i1 %28, label %41, label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = icmp eq i64 %31, 48
  br i1 %32, label %41, label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = icmp eq i64 %35, 2097152
  br i1 %36, label %41, label %37

37:                                               ; preds = %33
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = icmp eq i64 %39, 2097168
  br i1 %40, label %41, label %57

41:                                               ; preds = %37, %33, %29, %25, %21, %18
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %struct.TIM_TypeDef, ptr %44, i32 0, i32 2
  %46 = load volatile i32, ptr %45, align 4, !tbaa !15
  %47 = zext i32 %46 to i64
  %48 = and i64 %47, -3145841
  %49 = trunc i64 %48 to i32
  store volatile i32 %49, ptr %45, align 4, !tbaa !15
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = getelementptr inbounds %struct.TIM_TypeDef, ptr %53, i32 0, i32 2
  %55 = load volatile i32, ptr %54, align 4, !tbaa !15
  %56 = or i32 %55, %50
  store volatile i32 %56, ptr %54, align 4, !tbaa !15
  br label %57

57:                                               ; preds = %41, %37
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.TIM_TypeDef, ptr %60, i32 0, i32 1
  %62 = load volatile i32, ptr %61, align 4, !tbaa !17
  %63 = zext i32 %62 to i64
  %64 = or i64 %63, 1
  %65 = trunc i64 %64 to i32
  store volatile i32 %65, ptr %61, align 4, !tbaa !17
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = getelementptr inbounds %struct.TIM_TypeDef, ptr %68, i32 0, i32 1
  %70 = load volatile i32, ptr %69, align 4, !tbaa !17
  %71 = zext i32 %70 to i64
  %72 = and i64 %71, -5
  %73 = trunc i64 %72 to i32
  store volatile i32 %73, ptr %69, align 4, !tbaa !17
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %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 !14
  %78 = getelementptr inbounds %struct.TIM_TypeDef, ptr %77, i32 0, i32 1
  %79 = load volatile i32, ptr %78, align 4, !tbaa !17
  %80 = or i32 %79, %74
  store volatile i32 %80, ptr %78, align 4, !tbaa !17
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %81, i32 0, i32 3
  %83 = getelementptr inbounds [7 x ptr], ptr %82, i64 0, i64 5
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %84, i32 0, i32 5
  store ptr @TIMEx_DMACommutationCplt, ptr %85, align 8, !tbaa !18
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %86, i32 0, i32 3
  %88 = getelementptr inbounds [7 x ptr], ptr %87, i64 0, i64 5
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %89, i32 0, i32 6
  store ptr @TIMEx_DMACommutationHalfCplt, ptr %90, align 8, !tbaa !21
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %91, i32 0, i32 3
  %93 = getelementptr inbounds [7 x ptr], ptr %92, i64 0, i64 5
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.__DMA_HandleTypeDef, ptr %94, i32 0, i32 9
  store ptr @TIM_DMAError, ptr %95, align 8, !tbaa !22
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !14
  %99 = getelementptr inbounds %struct.TIM_TypeDef, ptr %98, i32 0, i32 3
  %100 = load volatile i32, ptr %99, align 4, !tbaa !23
  %101 = zext i32 %100 to i64
  %102 = and i64 %101, -33
  %103 = trunc i64 %102 to i32
  store volatile i32 %103, ptr %99, align 4, !tbaa !23
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !14
  %107 = getelementptr inbounds %struct.TIM_TypeDef, ptr %106, i32 0, i32 3
  %108 = load volatile i32, ptr %107, align 4, !tbaa !23
  %109 = zext i32 %108 to i64
  %110 = or i64 %109, 8192
  %111 = trunc i64 %110 to i32
  store volatile i32 %111, ptr %107, align 4, !tbaa !23
  br label %112

112:                                              ; preds = %57
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %113, i32 0, i32 4
  store i32 0, ptr %114, align 8, !tbaa !11
  br label %115

115:                                              ; preds = %112
  store i32 0, ptr %4, align 4
  br label %116

116:                                              ; preds = %115, %13
  %117 = load i32, ptr %4, align 4
  ret i32 %117
}

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

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

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, !10, i64 96}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 32, !7, i64 40, !10, i64 96, !10, i64 100, !7, i64 104, !7, i64 128, !10, i64 144}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !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}
!17 = !{!16, !10, i64 4}
!18 = !{!19, !6, i64 72}
!19 = !{!"__DMA_HandleTypeDef", !6, i64 0, !20, i64 8, !10, i64 56, !10, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !6, i64 160, !6, i64 168, !10, i64 176}
!20 = !{!"", !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}
!21 = !{!19, !6, i64 80}
!22 = !{!19, !6, i64 104}
!23 = !{!16, !10, i64 12}


; 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 void @TIM_DMAError(ptr noundef) #0

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_TIMEx_ConfigCommutEvent_DMA(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %36, label %7

7:                                                ; preds = %3
  switch i32 %1, label %._crit_edge [
    i32 2097168, label %8
    i32 2097152, label %8
    i32 48, label %8
    i32 32, label %8
    i32 16, label %8
    i32 0, label %8
  ]

._crit_edge:                                      ; preds = %7
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br label %15

8:                                                ; preds = %7, %7, %7, %7, %7, %7
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load volatile i32, ptr %10, align 4, !tbaa !13
  %12 = and i32 %11, -3145841
  store volatile i32 %12, ptr %10, align 4, !tbaa !13
  %13 = load volatile i32, ptr %10, align 4, !tbaa !13
  %14 = or i32 %13, %1
  store volatile i32 %14, ptr %10, align 4, !tbaa !13
  br label %15

15:                                               ; preds = %._crit_edge, %8
  %16 = phi ptr [ %.pre, %._crit_edge ], [ %9, %8 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load volatile i32, ptr %17, align 4, !tbaa !15
  %19 = or i32 %18, 1
  store volatile i32 %19, ptr %17, align 4, !tbaa !15
  %20 = load volatile i32, ptr %17, align 4, !tbaa !15
  %21 = and i32 %20, -5
  store volatile i32 %21, ptr %17, align 4, !tbaa !15
  %22 = load volatile i32, ptr %17, align 4, !tbaa !15
  %23 = or i32 %22, %2
  store volatile i32 %23, ptr %17, align 4, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 80
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %25, i64 72
  store ptr @TIMEx_DMACommutationCplt, ptr %26, align 8, !tbaa !17
  %27 = load ptr, ptr %24, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %27, i64 80
  store ptr @TIMEx_DMACommutationHalfCplt, ptr %28, align 8, !tbaa !20
  %29 = load ptr, ptr %24, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %29, i64 104
  store ptr @TIM_DMAError, ptr %30, align 8, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %16, i64 12
  %32 = load volatile i32, ptr %31, align 4, !tbaa !22
  %33 = and i32 %32, -33
  store volatile i32 %33, ptr %31, align 4, !tbaa !22
  %34 = load volatile i32, ptr %31, align 4, !tbaa !22
  %35 = or i32 %34, 8192
  store volatile i32 %35, ptr %31, align 4, !tbaa !22
  store i32 0, ptr %4, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %3, %15
  %.0 = phi i32 [ 0, %15 ], [ 2, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local void @TIMEx_DMACommutationCplt(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @TIMEx_DMACommutationHalfCplt(ptr noundef) #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 = { 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" }
attributes #2 = { 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 96}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 32, !8, i64 40, !11, i64 96, !11, i64 100, !8, i64 104, !8, i64 128, !11, i64 144}
!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 = !{!6, !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"", !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}
!15 = !{!14, !11, i64 4}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 72}
!18 = !{!"__DMA_HandleTypeDef", !7, i64 0, !19, 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}
!19 = !{!"", !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}
!20 = !{!18, !7, i64 80}
!21 = !{!18, !7, i64 104}
!22 = !{!14, !11, i64 12}


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