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

; 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_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_WaveformSetOutputLevel(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 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 i32, align 4
  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 i32 %3, ptr %9, align 4, !tbaa !9
  %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 %110

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 %110

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 %90 [
    i32 1, label %30
    i32 4, label %30
    i32 16, label %30
    i32 64, label %30
    i32 256, label %30
    i32 2, label %60
    i32 8, label %60
    i32 32, label %60
    i32 128, label %60
    i32 512, label %60
  ]

30:                                               ; preds = %26, %26, %26, %26, %26
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %46

33:                                               ; preds = %30
  %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 !15
  %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 15
  %42 = load volatile i32, ptr %41, align 4, !tbaa !16
  %43 = zext i32 %42 to i64
  %44 = or i64 %43, 1
  %45 = trunc i64 %44 to i32
  store volatile i32 %45, ptr %41, align 4, !tbaa !16
  br label %59

46:                                               ; preds = %30
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds %struct.HRTIM_TypeDef, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %50, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.HRTIM_Timerx_TypeDef, ptr %53, i32 0, i32 16
  %55 = load volatile i32, ptr %54, align 4, !tbaa !18
  %56 = zext i32 %55 to i64
  %57 = or i64 %56, 1
  %58 = trunc i64 %57 to i32
  store volatile i32 %58, ptr %54, align 4, !tbaa !18
  br label %59

59:                                               ; preds = %46, %33
  br label %97

60:                                               ; preds = %26, %26, %26, %26, %26
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = icmp eq i32 %61, 1
  br i1 %62, label %63, label %76

63:                                               ; preds = %60
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = getelementptr inbounds %struct.HRTIM_TypeDef, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %67, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.HRTIM_Timerx_TypeDef, ptr %70, i32 0, i32 17
  %72 = load volatile i32, ptr %71, align 4, !tbaa !19
  %73 = zext i32 %72 to i64
  %74 = or i64 %73, 1
  %75 = trunc i64 %74 to i32
  store volatile i32 %75, ptr %71, align 4, !tbaa !19
  br label %89

76:                                               ; preds = %60
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !15
  %80 = getelementptr inbounds %struct.HRTIM_TypeDef, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %80, i64 0, i64 %82
  %84 = getelementptr inbounds %struct.HRTIM_Timerx_TypeDef, ptr %83, i32 0, i32 18
  %85 = load volatile i32, ptr %84, align 4, !tbaa !20
  %86 = zext i32 %85 to i64
  %87 = or i64 %86, 1
  %88 = trunc i64 %87 to i32
  store volatile i32 %88, ptr %84, align 4, !tbaa !20
  br label %89

89:                                               ; preds = %76, %63
  br label %97

90:                                               ; preds = %26
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %91, i32 0, i32 4
  store volatile i32 7, ptr %92, align 8, !tbaa !11
  br label %93

93:                                               ; preds = %90
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %94, i32 0, i32 3
  store i32 0, ptr %95, align 4, !tbaa !14
  br label %96

96:                                               ; preds = %93
  br label %97

97:                                               ; preds = %96, %89, %59
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %98, i32 0, i32 4
  %100 = load volatile i32, ptr %99, align 8, !tbaa !11
  %101 = icmp eq i32 %100, 7
  br i1 %101, label %102, label %103

102:                                              ; preds = %97
  store i32 1, ptr %5, align 4
  br label %110

103:                                              ; preds = %97
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %104, i32 0, i32 4
  store volatile i32 1, ptr %105, align 8, !tbaa !11
  br label %106

106:                                              ; preds = %103
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %107, i32 0, i32 3
  store i32 0, ptr %108, align 4, !tbaa !14
  br label %109

109:                                              ; preds = %106
  store i32 0, ptr %5, align 4
  br label %110

110:                                              ; preds = %109, %102, %21, %14
  %111 = load i32, ptr %5, align 4
  ret i32 %111
}

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 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 60}
!17 = !{!"", !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}
!18 = !{!17, !10, i64 64}
!19 = !{!17, !10, i64 68}
!20 = !{!17, !10, i64 72}


; 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_WaveformSetOutputLevel(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %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 %44, 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 %44, 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 %39 [
    i32 1, label %13
    i32 4, label %13
    i32 16, label %13
    i32 64, label %13
    i32 256, label %13
    i32 2, label %26
    i32 8, label %26
    i32 32, label %26
    i32 128, label %26
    i32 512, label %26
  ]

13:                                               ; preds = %12, %12, %12, %12, %12
  %14 = icmp eq i32 %3, 1
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %15, i64 128
  %17 = zext i32 %1 to i64
  br i1 %14, label %18, label %22

18:                                               ; preds = %13
  %19 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %16, i64 0, i64 %17, i32 15
  %20 = load volatile i32, ptr %19, align 4, !tbaa !14
  %21 = or i32 %20, 1
  store volatile i32 %21, ptr %19, align 4, !tbaa !14
  br label %40

22:                                               ; preds = %13
  %23 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %16, i64 0, i64 %17, i32 16
  %24 = load volatile i32, ptr %23, align 4, !tbaa !16
  %25 = or i32 %24, 1
  store volatile i32 %25, ptr %23, align 4, !tbaa !16
  br label %40

26:                                               ; preds = %12, %12, %12, %12, %12
  %27 = icmp eq i32 %3, 1
  %28 = load ptr, ptr %0, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %28, i64 128
  %30 = zext i32 %1 to i64
  br i1 %27, label %31, label %35

31:                                               ; preds = %26
  %32 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %29, i64 0, i64 %30, i32 17
  %33 = load volatile i32, ptr %32, align 4, !tbaa !17
  %34 = or i32 %33, 1
  store volatile i32 %34, ptr %32, align 4, !tbaa !17
  br label %40

35:                                               ; preds = %26
  %36 = getelementptr inbounds [5 x %struct.HRTIM_Timerx_TypeDef], ptr %29, i64 0, i64 %30, i32 18
  %37 = load volatile i32, ptr %36, align 4, !tbaa !18
  %38 = or i32 %37, 1
  store volatile i32 %38, ptr %36, align 4, !tbaa !18
  br label %40

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

40:                                               ; preds = %31, %35, %18, %22, %39
  %41 = load volatile i32, ptr %5, align 8, !tbaa !5
  %42 = icmp eq i32 %41, 7
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store volatile i32 1, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !12
  br label %44

44:                                               ; preds = %40, %8, %4, %43
  %.0 = phi i32 [ 0, %43 ], [ 2, %4 ], [ 2, %8 ], [ 1, %40 ]
  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 = !{!6, !7, i64 0}
!14 = !{!15, !11, i64 60}
!15 = !{!"", !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}
!16 = !{!15, !11, i64 64}
!17 = !{!15, !11, i64 68}
!18 = !{!15, !11, i64 72}


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