; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (WaveformCaptureConfig)

; 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.HRTIM_HandleTypeDef = type { ptr, %struct.HRTIM_InitTypeDef, [6 x %struct.HRTIM_TimerParamTypeDef], i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.HRTIM_InitTypeDef = type { i32, i32, i32, i32, i32 }
%struct.HRTIM_TimerParamTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.HRTIM_CaptureCfgTypeDef = type { i32 }
%struct.HRTIM_TypeDef = type { %struct.HRTIM_Master_TypeDef, [5 x %struct.HRTIM_Timerx_TypeDef], [32 x i32], %struct.HRTIM_Common_TypeDef }
%struct.HRTIM_Master_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [20 x i32] }
%struct.HRTIM_Timerx_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, [5 x i32] }
%struct.HRTIM_Common_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, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_HRTIM_WaveformCaptureConfig(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %10, i32 0, i32 4
  %12 = load volatile i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  store i32 2, ptr %5, align 4
  br label %74

15:                                               ; preds = %4
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 2, ptr %5, align 4
  br label %74

22:                                               ; preds = %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %23, i32 0, i32 3
  store i32 1, ptr %24, align 4, !tbaa !14
  br label %25

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %27, i32 0, i32 4
  store volatile i32 2, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %29, label %54 [
    i32 1, label %30
    i32 2, label %42
  ]

30:                                               ; preds = %26
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.HRTIM_CaptureCfgTypeDef, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds %struct.HRTIM_TypeDef, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %37, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.HRTIM_Timerx_TypeDef, ptr %40, i32 0, i32 23
  store volatile i32 %33, ptr %41, align 4, !tbaa !18
  br label %61

42:                                               ; preds = %26
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HRTIM_CaptureCfgTypeDef, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = getelementptr inbounds %struct.HRTIM_TypeDef, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %49, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.HRTIM_Timerx_TypeDef, ptr %52, i32 0, i32 24
  store volatile i32 %45, ptr %53, align 4, !tbaa !20
  br label %61

54:                                               ; preds = %26
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %55, i32 0, i32 4
  store volatile i32 7, ptr %56, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %58, i32 0, i32 3
  store i32 0, ptr %59, align 4, !tbaa !14
  br label %60

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60, %42, %30
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %62, i32 0, i32 4
  %64 = load volatile i32, ptr %63, align 8, !tbaa !11
  %65 = icmp eq i32 %64, 7
  br i1 %65, label %66, label %67

66:                                               ; preds = %61
  store i32 1, ptr %5, align 4
  br label %74

67:                                               ; preds = %61
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %68, i32 0, i32 4
  store volatile i32 1, ptr %69, align 8, !tbaa !11
  br label %70

70:                                               ; preds = %67
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %71, i32 0, i32 3
  store i32 0, ptr %72, align 4, !tbaa !14
  br label %73

73:                                               ; preds = %70
  store i32 0, ptr %5, align 4
  br label %74

74:                                               ; preds = %73, %66, %21, %14
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

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, !10, i64 200}
!12 = !{!"", !6, i64 0, !13, i64 8, !7, i64 28, !10, i64 196, !10, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!14 = !{!12, !10, i64 196}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0}
!17 = !{!12, !6, i64 0}
!18 = !{!19, !10, i64 92}
!19 = !{!"", !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, !7, i64 108}
!20 = !{!19, !10, i64 96}


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

%struct.HRTIM_Timerx_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, [5 x i32] }

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_HRTIM_WaveformCaptureConfig(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 200
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %30, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 196
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %30, label %12

12:                                               ; preds = %8
  store i32 1, ptr %9, align 4, !tbaa !12
  store volatile i32 2, ptr %5, align 8, !tbaa !5
  switch i32 %2, label %25 [
    i32 1, label %13
    i32 2, label %19
  ]

13:                                               ; preds = %12
  %14 = load i32, ptr %3, align 4, !tbaa !13
  %15 = load ptr, ptr %0, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 128
  %17 = zext i32 %1 to i64
  %18 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %16, i64 0, i64 %17, i32 23
  store volatile i32 %14, ptr %18, align 4, !tbaa !16
  br label %26

19:                                               ; preds = %12
  %20 = load i32, ptr %3, align 4, !tbaa !13
  %21 = load ptr, ptr %0, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 128
  %23 = zext i32 %1 to i64
  %24 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %22, i64 0, i64 %23, i32 24
  store volatile i32 %20, ptr %24, align 4, !tbaa !18
  br label %26

25:                                               ; preds = %12
  store volatile i32 7, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %26

26:                                               ; preds = %25, %19, %13
  %27 = load volatile i32, ptr %5, align 8, !tbaa !5
  %28 = icmp eq i32 %27, 7
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store volatile i32 1, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %30

30:                                               ; preds = %26, %8, %4, %29
  %.0 = phi i32 [ 0, %29 ], [ 2, %4 ], [ 2, %8 ], [ 1, %26 ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse 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, !11, i64 200}
!6 = !{!"", !7, i64 0, !10, i64 8, !8, i64 28, !11, i64 196, !11, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248}
!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 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 196}
!13 = !{!14, !11, i64 0}
!14 = !{!"", !11, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 92}
!17 = !{!"", !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, !8, i64 108}
!18 = !{!17, !11, i64 96}


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