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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIM_Encoder_Start(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %11, i32 0, i32 6
  %13 = getelementptr inbounds [6 x i32], ptr %12, i64 0, i64 0
  %14 = load volatile i32, ptr %13, align 8, !tbaa !9
  store i32 %14, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds [6 x i32], ptr %16, i64 0, i64 1
  %18 = load volatile i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %19, i32 0, i32 7
  %21 = getelementptr inbounds [4 x i32], ptr %20, i64 0, i64 0
  %22 = load volatile i32, ptr %21, align 8, !tbaa !9
  store i32 %22, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %23, i32 0, i32 7
  %25 = getelementptr inbounds [4 x i32], ptr %24, i64 0, i64 1
  %26 = load volatile i32, ptr %25, align 4, !tbaa !9
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %44

29:                                               ; preds = %2
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %29
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %116

36:                                               ; preds = %32
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %37, i32 0, i32 6
  %39 = getelementptr inbounds [6 x i32], ptr %38, i64 0, i64 0
  store volatile i32 2, ptr %39, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %40, i32 0, i32 7
  %42 = getelementptr inbounds [4 x i32], ptr %41, i64 0, i64 0
  store volatile i32 2, ptr %42, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %36
  br label %90

44:                                               ; preds = %2
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = icmp eq i32 %45, 4
  br i1 %46, label %47, label %62

47:                                               ; preds = %44
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %53, label %50

50:                                               ; preds = %47
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %53, label %54

53:                                               ; preds = %50, %47
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %116

54:                                               ; preds = %50
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %55, i32 0, i32 6
  %57 = getelementptr inbounds [6 x i32], ptr %56, i64 0, i64 1
  store volatile i32 2, ptr %57, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %58, i32 0, i32 7
  %60 = getelementptr inbounds [4 x i32], ptr %59, i64 0, i64 1
  store volatile i32 2, ptr %60, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %54
  br label %89

62:                                               ; preds = %44
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = icmp ne i32 %63, 1
  br i1 %64, label %74, label %65

65:                                               ; preds = %62
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = icmp ne i32 %66, 1
  br i1 %67, label %74, label %68

68:                                               ; preds = %65
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 1
  br i1 %70, label %74, label %71

71:                                               ; preds = %68
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 1
  br i1 %73, label %74, label %75

74:                                               ; preds = %71, %68, %65, %62
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %116

75:                                               ; preds = %71
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %76, i32 0, i32 6
  %78 = getelementptr inbounds [6 x i32], ptr %77, i64 0, i64 0
  store volatile i32 2, ptr %78, align 8, !tbaa !9
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %79, i32 0, i32 6
  %81 = getelementptr inbounds [6 x i32], ptr %80, i64 0, i64 1
  store volatile i32 2, ptr %81, align 4, !tbaa !9
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %82, i32 0, i32 7
  %84 = getelementptr inbounds [4 x i32], ptr %83, i64 0, i64 0
  store volatile i32 2, ptr %84, align 8, !tbaa !9
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %85, i32 0, i32 7
  %87 = getelementptr inbounds [4 x i32], ptr %86, i64 0, i64 1
  store volatile i32 2, ptr %87, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %75
  br label %89

89:                                               ; preds = %88, %61
  br label %90

90:                                               ; preds = %89, %43
  %91 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %91, label %100 [
    i32 0, label %92
    i32 4, label %96
  ]

92:                                               ; preds = %90
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %95, i32 noundef 0, i32 noundef 1)
  br label %107

96:                                               ; preds = %90
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %99, i32 noundef 4, i32 noundef 1)
  br label %107

100:                                              ; preds = %90
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %103, i32 noundef 0, i32 noundef 1)
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %106, i32 noundef 4, i32 noundef 1)
  br label %107

107:                                              ; preds = %100, %96, %92
  %108 = load ptr, ptr %4, 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 !14
  %113 = zext i32 %112 to i64
  %114 = or i64 %113, 1
  %115 = trunc i64 %114 to i32
  store volatile i32 %115, ptr %111, align 4, !tbaa !14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %116

116:                                              ; preds = %107, %74, %53, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %117 = load i32, ptr %3, align 4
  ret i32 %117
}

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


; 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 range(i32 0, 2) i32 @HAL_TIM_Encoder_Start(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 104
  %4 = load volatile i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 108
  %6 = load volatile i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 128
  %8 = load volatile i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 132
  %10 = load volatile i32, ptr %9, align 4, !tbaa !5
  switch i32 %1, label %17 [
    i32 0, label %11
    i32 4, label %14
  ]

11:                                               ; preds = %2
  %12 = icmp ne i32 %4, 1
  %13 = icmp ne i32 %8, 1
  %or.cond = select i1 %12, i1 true, i1 %13
  br i1 %or.cond, label %30, label %.thread

.thread:                                          ; preds = %11
  store volatile i32 2, ptr %3, align 8, !tbaa !5
  store volatile i32 2, ptr %7, align 8, !tbaa !5
  br label %25

14:                                               ; preds = %2
  %15 = icmp ne i32 %6, 1
  %16 = icmp ne i32 %10, 1
  %or.cond3 = select i1 %15, i1 true, i1 %16
  br i1 %or.cond3, label %30, label %.thread38

.thread38:                                        ; preds = %14
  store volatile i32 2, ptr %5, align 4, !tbaa !5
  store volatile i32 2, ptr %9, align 4, !tbaa !5
  br label %25

17:                                               ; preds = %2
  %18 = icmp ne i32 %4, 1
  %19 = icmp ne i32 %6, 1
  %or.cond5 = select i1 %18, i1 true, i1 %19
  %20 = icmp ne i32 %8, 1
  %or.cond7 = select i1 %or.cond5, i1 true, i1 %20
  %21 = icmp ne i32 %10, 1
  %or.cond9 = select i1 %or.cond7, i1 true, i1 %21
  br i1 %or.cond9, label %30, label %22

22:                                               ; preds = %17
  store volatile i32 2, ptr %3, align 8, !tbaa !5
  store volatile i32 2, ptr %5, align 4, !tbaa !5
  store volatile i32 2, ptr %7, align 8, !tbaa !5
  store volatile i32 2, ptr %9, align 4, !tbaa !5
  %cond = icmp eq i32 %1, 0
  br i1 %cond, label %25, label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @TIM_CCxChannelCmd(ptr noundef %24, i32 noundef 0, i32 noundef 1)
  br label %25

25:                                               ; preds = %.thread, %22, %23, %.thread38
  %.sink39 = phi i32 [ 4, %23 ], [ 4, %.thread38 ], [ 0, %22 ], [ 0, %.thread ]
  %26 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @TIM_CCxChannelCmd(ptr noundef %26, i32 noundef %.sink39, i32 noundef 1)
  %27 = load ptr, ptr %0, align 8, !tbaa !9
  %28 = load volatile i32, ptr %27, align 4, !tbaa !13
  %29 = or i32 %28, 1
  store volatile i32 %29, ptr %27, align 4, !tbaa !13
  br label %30

30:                                               ; preds = %17, %14, %11, %25
  %.0 = phi i32 [ 0, %25 ], [ 1, %11 ], [ 1, %14 ], [ 1, %17 ]
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 32, !7, i64 40, !6, i64 96, !6, i64 100, !7, i64 104, !7, i64 128, !6, i64 144}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104}


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