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

; 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

declare i32 @HAL_DMA_Abort_IT(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @TIM_CCxNChannelCmd(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIMEx_OCN_Stop_DMA(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %6, label %49 [
    i32 0, label %7
    i32 4, label %21
    i32 8, label %35
  ]

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
  %11 = getelementptr inbounds %struct.TIM_TypeDef, ptr %10, i32 0, i32 3
  %12 = load volatile i32, ptr %11, align 4, !tbaa !14
  %13 = zext i32 %12 to i64
  %14 = and i64 %13, -513
  %15 = trunc i64 %14 to i32
  store volatile i32 %15, ptr %11, align 4, !tbaa !14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %16, i32 0, i32 3
  %18 = getelementptr inbounds [7 x ptr], ptr %17, i64 0, i64 1
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = call i32 @HAL_DMA_Abort_IT(ptr noundef %19)
  br label %50

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

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

49:                                               ; preds = %2
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %49, %35, %21, %7
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %150

53:                                               ; preds = %50
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %4, align 4, !tbaa !9
  call void @TIM_CCxNChannelCmd(ptr noundef %56, i32 noundef %57, i32 noundef 0)
  br label %58

58:                                               ; preds = %53
  %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 8
  %63 = load volatile i32, ptr %62, align 4, !tbaa !16
  %64 = and i32 %63, 4369
  %65 = zext i32 %64 to i64
  %66 = icmp eq i64 %65, 0
  br i1 %66, label %67, label %86

67:                                               ; preds = %58
  %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 = getelementptr inbounds %struct.TIM_TypeDef, ptr %70, i32 0, i32 8
  %72 = load volatile i32, ptr %71, align 4, !tbaa !16
  %73 = and i32 %72, 1092
  %74 = zext i32 %73 to i64
  %75 = icmp eq i64 %74, 0
  br i1 %75, label %76, label %85

76:                                               ; preds = %67
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = getelementptr inbounds %struct.TIM_TypeDef, ptr %79, i32 0, i32 17
  %81 = load volatile i32, ptr %80, align 4, !tbaa !17
  %82 = zext i32 %81 to i64
  %83 = and i64 %82, -32769
  %84 = trunc i64 %83 to i32
  store volatile i32 %84, ptr %80, align 4, !tbaa !17
  br label %85

85:                                               ; preds = %76, %67
  br label %86

86:                                               ; preds = %85, %58
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  br label %89

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

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

107:                                              ; preds = %98
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !11
  %111 = getelementptr inbounds %struct.TIM_TypeDef, ptr %110, i32 0, i32 0
  %112 = load volatile i32, ptr %111, align 4, !tbaa !18
  %113 = zext i32 %112 to i64
  %114 = and i64 %113, -2
  %115 = trunc i64 %114 to i32
  store volatile i32 %115, ptr %111, align 4, !tbaa !18
  br label %116

116:                                              ; preds = %107, %98
  br label %117

117:                                              ; preds = %116, %89
  br label %118

118:                                              ; preds = %117
  br label %119

119:                                              ; preds = %118
  %120 = load i32, ptr %4, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 0
  br i1 %121, label %122, label %126

122:                                              ; preds = %119
  %123 = load ptr, ptr %3, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %123, i32 0, i32 7
  %125 = getelementptr inbounds [4 x i32], ptr %124, i64 0, i64 0
  store volatile i32 1, ptr %125, align 8, !tbaa !9
  br label %148

126:                                              ; preds = %119
  %127 = load i32, ptr %4, align 4, !tbaa !9
  %128 = icmp eq i32 %127, 4
  br i1 %128, label %129, label %133

129:                                              ; preds = %126
  %130 = load ptr, ptr %3, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %130, i32 0, i32 7
  %132 = getelementptr inbounds [4 x i32], ptr %131, i64 0, i64 1
  store volatile i32 1, ptr %132, align 4, !tbaa !9
  br label %146

133:                                              ; preds = %126
  %134 = load i32, ptr %4, align 4, !tbaa !9
  %135 = icmp eq i32 %134, 8
  br i1 %135, label %136, label %140

136:                                              ; preds = %133
  %137 = load ptr, ptr %3, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %137, i32 0, i32 7
  %139 = getelementptr inbounds [4 x i32], ptr %138, i64 0, i64 2
  store volatile i32 1, ptr %139, align 8, !tbaa !9
  br label %144

140:                                              ; preds = %133
  %141 = load ptr, ptr %3, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %141, i32 0, i32 7
  %143 = getelementptr inbounds [4 x i32], ptr %142, i64 0, i64 3
  store volatile i32 1, ptr %143, align 4, !tbaa !9
  br label %144

144:                                              ; preds = %140, %136
  %145 = phi i32 [ 1, %136 ], [ 1, %140 ]
  br label %146

146:                                              ; preds = %144, %129
  %147 = phi i32 [ 1, %129 ], [ %145, %144 ]
  br label %148

148:                                              ; preds = %146, %122
  %149 = phi i32 [ 1, %122 ], [ %147, %146 ]
  br label %150

150:                                              ; preds = %148, %50
  %151 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %151
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"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, !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 = !{!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}


; 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 hidden void @TIM_CCxNChannelCmd(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_TIMEx_OCN_Stop_DMA(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  switch i32 %1, label %47 [
    i32 0, label %5
    i32 4, label %3
    i32 8, label %4
  ]

3:                                                ; preds = %2
  br label %5

4:                                                ; preds = %2
  br label %5

5:                                                ; preds = %2, %4, %3
  %.sink31 = phi i32 [ -2049, %4 ], [ -1025, %3 ], [ -513, %2 ]
  %.sink = phi i64 [ 64, %4 ], [ 56, %3 ], [ 48, %2 ]
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load volatile i32, ptr %7, align 4, !tbaa !12
  %9 = and i32 %8, %.sink31
  store volatile i32 %9, ptr %7, align 4, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = tail call i32 @HAL_DMA_Abort_IT(ptr noundef %11) #2
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @TIM_CCxNChannelCmd(ptr noundef %13, i32 noundef %1, i32 noundef 0)
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 32
  %16 = load volatile i32, ptr %15, align 4, !tbaa !15
  %17 = and i32 %16, 4369
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %5
  %20 = load volatile i32, ptr %15, align 4, !tbaa !15
  %21 = and i32 %20, 1092
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %14, i64 68
  %25 = load volatile i32, ptr %24, align 4, !tbaa !16
  %26 = and i32 %25, -32769
  store volatile i32 %26, ptr %24, align 4, !tbaa !16
  br label %27

27:                                               ; preds = %5, %23, %19
  %28 = load volatile i32, ptr %15, align 4, !tbaa !15
  %29 = and i32 %28, 4369
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %27
  %32 = load volatile i32, ptr %15, align 4, !tbaa !15
  %33 = and i32 %32, 1092
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %31
  %36 = load volatile i32, ptr %14, align 4, !tbaa !17
  %37 = and i32 %36, -2
  store volatile i32 %37, ptr %14, align 4, !tbaa !17
  br label %38

38:                                               ; preds = %31, %35, %27
  switch i32 %1, label %45 [
    i32 0, label %39
    i32 4, label %41
    i32 8, label %43
  ]

39:                                               ; preds = %38
  %40 = getelementptr inbounds i8, ptr %0, i64 128
  store volatile i32 1, ptr %40, align 8, !tbaa !18
  br label %47

41:                                               ; preds = %38
  %42 = getelementptr inbounds i8, ptr %0, i64 132
  store volatile i32 1, ptr %42, align 4, !tbaa !18
  br label %47

43:                                               ; preds = %38
  %44 = getelementptr inbounds i8, ptr %0, i64 136
  store volatile i32 1, ptr %44, align 8, !tbaa !18
  br label %47

45:                                               ; preds = %38
  %46 = getelementptr inbounds i8, ptr %0, i64 140
  store volatile i32 1, ptr %46, align 4, !tbaa !18
  br label %47

47:                                               ; preds = %2, %43, %45, %39, %41
  %.025 = phi i32 [ 0, %43 ], [ 0, %45 ], [ 0, %39 ], [ 0, %41 ], [ 1, %2 ]
  ret i32 %.025
}

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, !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 = !{!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 = !{!11, !11, i64 0}


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