; 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_OnePulse_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 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 1
  br i1 %29, label %39, label %30

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

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

36:                                               ; preds = %33
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 1
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33, %30, %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %97

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %41, i32 0, i32 6
  %43 = getelementptr inbounds [6 x i32], ptr %42, i64 0, i64 0
  store volatile i32 2, ptr %43, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %44, i32 0, i32 6
  %46 = getelementptr inbounds [6 x i32], ptr %45, i64 0, i64 1
  store volatile i32 2, ptr %46, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %47, i32 0, i32 7
  %49 = getelementptr inbounds [4 x i32], ptr %48, i64 0, i64 0
  store volatile i32 2, ptr %49, align 8, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %50, i32 0, i32 7
  %52 = getelementptr inbounds [4 x i32], ptr %51, i64 0, i64 1
  store volatile i32 2, ptr %52, align 4, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %55, i32 noundef 0, i32 noundef 1)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  call void @TIM_CCxChannelCmd(ptr noundef %58, i32 noundef 4, i32 noundef 1)
  %59 = load ptr, ptr %4, 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 = icmp eq ptr %61, inttoptr (i64 1073807360 to ptr)
  br i1 %62, label %83, label %63

63:                                               ; preds = %40
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = icmp eq ptr %66, inttoptr (i64 1073808384 to ptr)
  br i1 %67, label %83, label %68

68:                                               ; preds = %63
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = icmp eq ptr %71, inttoptr (i64 1073823744 to ptr)
  br i1 %72, label %83, label %73

73:                                               ; preds = %68
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = icmp eq ptr %76, inttoptr (i64 1073824768 to ptr)
  br i1 %77, label %83, label %78

78:                                               ; preds = %73
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  %82 = icmp eq ptr %81, inttoptr (i64 1073825792 to ptr)
  br label %83

83:                                               ; preds = %78, %73, %68, %63, %40
  %84 = phi i1 [ true, %73 ], [ true, %68 ], [ true, %63 ], [ true, %40 ], [ %82, %78 ]
  %85 = zext i1 %84 to i32
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %96

87:                                               ; preds = %83
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  %91 = getelementptr inbounds %struct.TIM_TypeDef, ptr %90, i32 0, i32 17
  %92 = load volatile i32, ptr %91, align 4, !tbaa !14
  %93 = zext i32 %92 to i64
  %94 = or i64 %93, 32768
  %95 = trunc i64 %94 to i32
  store volatile i32 %95, ptr %91, align 4, !tbaa !14
  br label %96

96:                                               ; preds = %87, %83
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %97

97:                                               ; preds = %96, %39
  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
  %98 = load i32, ptr %3, align 4
  ret i32 %98
}

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 68}
!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_OnePulse_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
  %11 = icmp ne i32 %4, 1
  %12 = icmp ne i32 %6, 1
  %or.cond = select i1 %11, i1 true, i1 %12
  %13 = icmp ne i32 %8, 1
  %or.cond3 = select i1 %or.cond, i1 true, i1 %13
  %14 = icmp ne i32 %10, 1
  %or.cond5 = select i1 %or.cond3, i1 true, i1 %14
  br i1 %or.cond5, label %22, label %15

15:                                               ; preds = %2
  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
  %16 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @TIM_CCxChannelCmd(ptr noundef %16, i32 noundef 0, i32 noundef 1)
  %17 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @TIM_CCxChannelCmd(ptr noundef %17, i32 noundef 4, i32 noundef 1)
  %18 = load ptr, ptr %0, align 8, !tbaa !9
  %magicptr28 = ptrtoint ptr %18 to i64
  switch i64 %magicptr28, label %22 [
    i64 1073807360, label %.critedge
    i64 1073808384, label %.critedge
    i64 1073823744, label %.critedge
    i64 1073824768, label %.critedge
    i64 1073825792, label %.critedge
  ]

.critedge:                                        ; preds = %15, %15, %15, %15, %15
  %19 = getelementptr inbounds i8, ptr %18, i64 68
  %20 = load volatile i32, ptr %19, align 4, !tbaa !13
  %21 = or i32 %20, 32768
  store volatile i32 %21, ptr %19, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %15, %.critedge, %2
  %.0 = phi i32 [ 1, %2 ], [ 0, %.critedge ], [ 0, %15 ]
  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 68}
!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass