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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIMEx_OCN_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 ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load i32, ptr %4, align 4, !tbaa !9
  call void @TIM_CCxNChannelCmd(ptr noundef %7, i32 noundef %8, i32 noundef 0)
  br label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.TIM_TypeDef, ptr %12, i32 0, i32 8
  %14 = load volatile i32, ptr %13, align 4, !tbaa !14
  %15 = and i32 %14, 4369
  %16 = zext i32 %15 to i64
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %37

18:                                               ; preds = %9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.TIM_TypeDef, ptr %21, i32 0, i32 8
  %23 = load volatile i32, ptr %22, align 4, !tbaa !14
  %24 = and i32 %23, 1092
  %25 = zext i32 %24 to i64
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %36

27:                                               ; preds = %18
  %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
  %31 = getelementptr inbounds %struct.TIM_TypeDef, ptr %30, i32 0, i32 17
  %32 = load volatile i32, ptr %31, align 4, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = and i64 %33, -32769
  %35 = trunc i64 %34 to i32
  store volatile i32 %35, ptr %31, align 4, !tbaa !16
  br label %36

36:                                               ; preds = %27, %18
  br label %37

37:                                               ; preds = %36, %9
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.TIM_TypeDef, ptr %42, i32 0, i32 8
  %44 = load volatile i32, ptr %43, align 4, !tbaa !14
  %45 = and i32 %44, 4369
  %46 = zext i32 %45 to i64
  %47 = icmp eq i64 %46, 0
  br i1 %47, label %48, label %67

48:                                               ; preds = %39
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.TIM_TypeDef, ptr %51, i32 0, i32 8
  %53 = load volatile i32, ptr %52, align 4, !tbaa !14
  %54 = and i32 %53, 1092
  %55 = zext i32 %54 to i64
  %56 = icmp eq i64 %55, 0
  br i1 %56, label %57, label %66

57:                                               ; preds = %48
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.TIM_TypeDef, ptr %60, i32 0, i32 0
  %62 = load volatile i32, ptr %61, align 4, !tbaa !17
  %63 = zext i32 %62 to i64
  %64 = and i64 %63, -2
  %65 = trunc i64 %64 to i32
  store volatile i32 %65, ptr %61, align 4, !tbaa !17
  br label %66

66:                                               ; preds = %57, %48
  br label %67

67:                                               ; preds = %66, %39
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = icmp eq i32 %69, 0
  br i1 %70, label %71, label %75

71:                                               ; preds = %68
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %72, i32 0, i32 7
  %74 = getelementptr inbounds [4 x i32], ptr %73, i64 0, i64 0
  store volatile i32 1, ptr %74, align 8, !tbaa !9
  br label %97

75:                                               ; preds = %68
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = icmp eq i32 %76, 4
  br i1 %77, label %78, label %82

78:                                               ; preds = %75
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %79, i32 0, i32 7
  %81 = getelementptr inbounds [4 x i32], ptr %80, i64 0, i64 1
  store volatile i32 1, ptr %81, align 4, !tbaa !9
  br label %95

82:                                               ; preds = %75
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = icmp eq i32 %83, 8
  br i1 %84, label %85, label %89

85:                                               ; preds = %82
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %86, i32 0, i32 7
  %88 = getelementptr inbounds [4 x i32], ptr %87, i64 0, i64 2
  store volatile i32 1, ptr %88, align 8, !tbaa !9
  br label %93

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

93:                                               ; preds = %89, %85
  %94 = phi i32 [ 1, %85 ], [ 1, %89 ]
  br label %95

95:                                               ; preds = %93, %78
  %96 = phi i32 [ 1, %78 ], [ %94, %93 ]
  br label %97

97:                                               ; preds = %95, %71
  %98 = phi i32 [ 1, %71 ], [ %96, %95 ]
  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 68}
!17 = !{!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 hidden void @TIM_CCxNChannelCmd(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @HAL_TIMEx_OCN_Stop(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @TIM_CCxNChannelCmd(ptr noundef %3, i32 noundef %1, i32 noundef 0)
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 32
  %6 = load volatile i32, ptr %5, align 4, !tbaa !12
  %7 = and i32 %6, 4369
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %17

9:                                                ; preds = %2
  %10 = load volatile i32, ptr %5, align 4, !tbaa !12
  %11 = and i32 %10, 1092
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %4, i64 68
  %15 = load volatile i32, ptr %14, align 4, !tbaa !14
  %16 = and i32 %15, -32769
  store volatile i32 %16, ptr %14, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %9, %13, %2
  %18 = load volatile i32, ptr %5, align 4, !tbaa !12
  %19 = and i32 %18, 4369
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %28

21:                                               ; preds = %17
  %22 = load volatile i32, ptr %5, align 4, !tbaa !12
  %23 = and i32 %22, 1092
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load volatile i32, ptr %4, align 4, !tbaa !15
  %27 = and i32 %26, -2
  store volatile i32 %27, ptr %4, align 4, !tbaa !15
  br label %28

28:                                               ; preds = %17, %25, %21
  switch i32 %1, label %35 [
    i32 0, label %29
    i32 4, label %31
    i32 8, label %33
  ]

29:                                               ; preds = %28
  %30 = getelementptr inbounds i8, ptr %0, i64 128
  store volatile i32 1, ptr %30, align 8, !tbaa !16
  br label %37

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %0, i64 132
  store volatile i32 1, ptr %32, align 4, !tbaa !16
  br label %37

33:                                               ; preds = %28
  %34 = getelementptr inbounds i8, ptr %0, i64 136
  store volatile i32 1, ptr %34, align 8, !tbaa !16
  br label %37

35:                                               ; preds = %28
  %36 = getelementptr inbounds i8, ptr %0, i64 140
  store volatile i32 1, ptr %36, align 4, !tbaa !16
  br label %37

37:                                               ; preds = %33, %35, %31, %29
  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 68}
!15 = !{!13, !11, i64 0}
!16 = !{!11, !11, i64 0}


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