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

; 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: nounwind uwtable
declare dso_local void @TIM_CCxChannelCmd(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIM_Encoder_Stop(ptr noundef %0, i32 noundef %1) #0 {
  %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 %14 [
    i32 0, label %6
    i32 4, label %10
  ]

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
  call void @TIM_CCxChannelCmd(ptr noundef %9, i32 noundef 0, i32 noundef 0)
  br label %21

10:                                               ; preds = %2
  %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
  call void @TIM_CCxChannelCmd(ptr noundef %13, i32 noundef 4, i32 noundef 0)
  br label %21

14:                                               ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %17, i32 noundef 0, i32 noundef 0)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %20, i32 noundef 4, i32 noundef 0)
  br label %21

21:                                               ; preds = %14, %10, %6
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.TIM_TypeDef, ptr %25, i32 0, i32 8
  %27 = load volatile i32, ptr %26, align 4, !tbaa !14
  %28 = and i32 %27, 4369
  %29 = zext i32 %28 to i64
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %50

31:                                               ; preds = %22
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds %struct.TIM_TypeDef, ptr %34, i32 0, i32 8
  %36 = load volatile i32, ptr %35, align 4, !tbaa !14
  %37 = and i32 %36, 1092
  %38 = zext i32 %37 to i64
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %49

40:                                               ; preds = %31
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.TIM_TypeDef, ptr %43, i32 0, i32 0
  %45 = load volatile i32, ptr %44, align 4, !tbaa !16
  %46 = zext i32 %45 to i64
  %47 = and i64 %46, -2
  %48 = trunc i64 %47 to i32
  store volatile i32 %48, ptr %44, align 4, !tbaa !16
  br label %49

49:                                               ; preds = %40, %31
  br label %50

50:                                               ; preds = %49, %22
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %57, label %54

54:                                               ; preds = %51
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 4
  br i1 %56, label %57, label %136

57:                                               ; preds = %54, %51
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %64

60:                                               ; preds = %57
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %61, i32 0, i32 6
  %63 = getelementptr inbounds [6 x i32], ptr %62, i64 0, i64 0
  store volatile i32 1, ptr %63, align 8, !tbaa !9
  br label %104

64:                                               ; preds = %57
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 4
  br i1 %66, label %67, label %71

67:                                               ; preds = %64
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %68, i32 0, i32 6
  %70 = getelementptr inbounds [6 x i32], ptr %69, i64 0, i64 1
  store volatile i32 1, ptr %70, align 4, !tbaa !9
  br label %102

71:                                               ; preds = %64
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 8
  br i1 %73, label %74, label %78

74:                                               ; preds = %71
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %75, i32 0, i32 6
  %77 = getelementptr inbounds [6 x i32], ptr %76, i64 0, i64 2
  store volatile i32 1, ptr %77, align 8, !tbaa !9
  br label %100

78:                                               ; preds = %71
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = icmp eq i32 %79, 12
  br i1 %80, label %81, label %85

81:                                               ; preds = %78
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %82, i32 0, i32 6
  %84 = getelementptr inbounds [6 x i32], ptr %83, i64 0, i64 3
  store volatile i32 1, ptr %84, align 4, !tbaa !9
  br label %98

85:                                               ; preds = %78
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = icmp eq i32 %86, 16
  br i1 %87, label %88, label %92

88:                                               ; preds = %85
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %89, i32 0, i32 6
  %91 = getelementptr inbounds [6 x i32], ptr %90, i64 0, i64 4
  store volatile i32 1, ptr %91, align 8, !tbaa !9
  br label %96

92:                                               ; preds = %85
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %93, i32 0, i32 6
  %95 = getelementptr inbounds [6 x i32], ptr %94, i64 0, i64 5
  store volatile i32 1, ptr %95, align 4, !tbaa !9
  br label %96

96:                                               ; preds = %92, %88
  %97 = phi i32 [ 1, %88 ], [ 1, %92 ]
  br label %98

98:                                               ; preds = %96, %81
  %99 = phi i32 [ 1, %81 ], [ %97, %96 ]
  br label %100

100:                                              ; preds = %98, %74
  %101 = phi i32 [ 1, %74 ], [ %99, %98 ]
  br label %102

102:                                              ; preds = %100, %67
  %103 = phi i32 [ 1, %67 ], [ %101, %100 ]
  br label %104

104:                                              ; preds = %102, %60
  %105 = phi i32 [ 1, %60 ], [ %103, %102 ]
  %106 = load i32, ptr %4, align 4, !tbaa !9
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %112

108:                                              ; preds = %104
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %109, i32 0, i32 7
  %111 = getelementptr inbounds [4 x i32], ptr %110, i64 0, i64 0
  store volatile i32 1, ptr %111, align 8, !tbaa !9
  br label %134

112:                                              ; preds = %104
  %113 = load i32, ptr %4, align 4, !tbaa !9
  %114 = icmp eq i32 %113, 4
  br i1 %114, label %115, label %119

115:                                              ; preds = %112
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %116, i32 0, i32 7
  %118 = getelementptr inbounds [4 x i32], ptr %117, i64 0, i64 1
  store volatile i32 1, ptr %118, align 4, !tbaa !9
  br label %132

119:                                              ; preds = %112
  %120 = load i32, ptr %4, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 8
  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 2
  store volatile i32 1, ptr %125, align 8, !tbaa !9
  br label %130

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

130:                                              ; preds = %126, %122
  %131 = phi i32 [ 1, %122 ], [ 1, %126 ]
  br label %132

132:                                              ; preds = %130, %115
  %133 = phi i32 [ 1, %115 ], [ %131, %130 ]
  br label %134

134:                                              ; preds = %132, %108
  %135 = phi i32 [ 1, %108 ], [ %133, %132 ]
  br label %149

136:                                              ; preds = %54
  %137 = load ptr, ptr %3, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %137, i32 0, i32 6
  %139 = getelementptr inbounds [6 x i32], ptr %138, i64 0, i64 0
  store volatile i32 1, ptr %139, align 8, !tbaa !9
  %140 = load ptr, ptr %3, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %140, i32 0, i32 6
  %142 = getelementptr inbounds [6 x i32], ptr %141, i64 0, i64 1
  store volatile i32 1, ptr %142, align 4, !tbaa !9
  %143 = load ptr, ptr %3, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %143, i32 0, i32 7
  %145 = getelementptr inbounds [4 x i32], ptr %144, i64 0, i64 0
  store volatile i32 1, ptr %145, align 8, !tbaa !9
  %146 = load ptr, ptr %3, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %146, i32 0, i32 7
  %148 = getelementptr inbounds [4 x i32], ptr %147, i64 0, i64 1
  store volatile i32 1, ptr %148, align 4, !tbaa !9
  br label %149

149:                                              ; preds = %136, %134
  ret i32 0
}

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

!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 32}
!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 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
declare dso_local void @TIM_CCxChannelCmd(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @HAL_TIM_Encoder_Stop(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  switch i32 %1, label %6 [
    i32 0, label %4
    i32 4, label %5
  ]

4:                                                ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  br label %8

5:                                                ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 4, i32 noundef 0)
  br label %8

6:                                                ; preds = %2
  tail call void @TIM_CCxChannelCmd(ptr noundef %3, i32 noundef 0, i32 noundef 0)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @TIM_CCxChannelCmd(ptr noundef %7, i32 noundef 4, i32 noundef 0)
  br label %8

8:                                                ; preds = %4, %5, %6
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load volatile i32, ptr %10, align 4, !tbaa !12
  %12 = and i32 %11, 4369
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %21

14:                                               ; preds = %8
  %15 = load volatile i32, ptr %10, align 4, !tbaa !12
  %16 = and i32 %15, 1092
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = load volatile i32, ptr %9, align 4, !tbaa !14
  %20 = and i32 %19, -2
  store volatile i32 %20, ptr %9, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %8, %18, %14
  switch i32 %1, label %28 [
    i32 0, label %22
    i32 4, label %25
  ]

22:                                               ; preds = %21
  %23 = getelementptr inbounds i8, ptr %0, i64 104
  store volatile i32 1, ptr %23, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 128
  store volatile i32 1, ptr %24, align 8, !tbaa !15
  br label %33

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %0, i64 108
  store volatile i32 1, ptr %26, align 4, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 132
  store volatile i32 1, ptr %27, align 4, !tbaa !15
  br label %33

28:                                               ; preds = %21
  %29 = getelementptr inbounds i8, ptr %0, i64 104
  store volatile i32 1, ptr %29, align 8, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %0, i64 108
  store volatile i32 1, ptr %30, align 4, !tbaa !15
  %31 = getelementptr inbounds i8, ptr %0, i64 128
  store volatile i32 1, ptr %31, align 8, !tbaa !15
  %32 = getelementptr inbounds i8, ptr %0, i64 132
  store volatile i32 1, ptr %32, align 4, !tbaa !15
  br label %33

33:                                               ; preds = %22, %25, %28
  ret i32 0
}

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

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


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