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

; 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.DFSDM_Filter_HandleTypeDef = type { ptr, %struct.DFSDM_Filter_InitTypeDef, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.DFSDM_Filter_InitTypeDef = type { %struct.DFSDM_Filter_RegularParamTypeDef, %struct.DFSDM_Filter_InjectedParamTypeDef, %struct.DFSDM_Filter_FilterParamTypeDef }
%struct.DFSDM_Filter_RegularParamTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Filter_InjectedParamTypeDef = type { i32, i32, i32, i32, i32 }
%struct.DFSDM_Filter_FilterParamTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Filter_TypeDef = type { 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

declare i32 @HAL_GetTick() #1

; 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 @HAL_DFSDM_FilterErrorCallback(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_DFSDM_FilterPollForInjConversion(ptr noundef %0, i32 noundef %1) #2 {
  %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
  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) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %8, i32 0, i32 11
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp ne i32 %10, 3
  br i1 %11, label %12, label %18

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %13, i32 0, i32 11
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp ne i32 %15, 4
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %99

18:                                               ; preds = %12, %2
  %19 = call i32 @HAL_GetTick()
  store i32 %19, ptr %6, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %43, %18
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = getelementptr inbounds %struct.DFSDM_Filter_TypeDef, ptr %23, i32 0, i32 2
  %25 = load volatile i32, ptr %24, align 4, !tbaa !17
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, 1
  %28 = icmp ne i64 %27, 1
  br i1 %28, label %29, label %44

29:                                               ; preds = %20
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp ne i32 %30, -1
  br i1 %31, label %32, label %43

32:                                               ; preds = %29
  %33 = call i32 @HAL_GetTick()
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sub i32 %33, %34
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = icmp ugt i32 %35, %36
  br i1 %37, label %41, label %38

38:                                               ; preds = %32
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %38, %32
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %99

42:                                               ; preds = %38
  br label %43

43:                                               ; preds = %42, %29
  br label %20, !llvm.loop !19

44:                                               ; preds = %20
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = getelementptr inbounds %struct.DFSDM_Filter_TypeDef, ptr %47, i32 0, i32 2
  %49 = load volatile i32, ptr %48, align 4, !tbaa !17
  %50 = zext i32 %49 to i64
  %51 = and i64 %50, 4
  %52 = icmp eq i64 %51, 4
  br i1 %52, label %53, label %61

53:                                               ; preds = %44
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %54, i32 0, i32 12
  store i32 2, ptr %55, align 8, !tbaa !21
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @HAL_DFSDM_FilterErrorCallback(ptr noundef %56)
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = getelementptr inbounds %struct.DFSDM_Filter_TypeDef, ptr %59, i32 0, i32 3
  store volatile i32 4, ptr %60, align 4, !tbaa !22
  br label %61

61:                                               ; preds = %53, %44
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %62, i32 0, i32 10
  %64 = load i32, ptr %63, align 8, !tbaa !23
  %65 = add i32 %64, -1
  store i32 %65, ptr %63, align 8, !tbaa !23
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %66, i32 0, i32 10
  %68 = load i32, ptr %67, align 8, !tbaa !23
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %98

70:                                               ; preds = %61
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %71, i32 0, i32 6
  %73 = load i32, ptr %72, align 8, !tbaa !24
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %84

75:                                               ; preds = %70
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %76, i32 0, i32 11
  %78 = load i32, ptr %77, align 4, !tbaa !11
  %79 = icmp eq i32 %78, 3
  %80 = zext i1 %79 to i64
  %81 = select i1 %79, i32 1, i32 2
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %82, i32 0, i32 11
  store i32 %81, ptr %83, align 4, !tbaa !11
  br label %84

84:                                               ; preds = %75, %70
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %85, i32 0, i32 8
  %87 = load i32, ptr %86, align 8, !tbaa !25
  %88 = icmp eq i32 %87, 1
  br i1 %88, label %89, label %93

89:                                               ; preds = %84
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %90, i32 0, i32 9
  %92 = load i32, ptr %91, align 4, !tbaa !26
  br label %94

93:                                               ; preds = %84
  br label %94

94:                                               ; preds = %93, %89
  %95 = phi i32 [ %92, %89 ], [ 1, %93 ]
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %96, i32 0, i32 10
  store i32 %95, ptr %97, align 8, !tbaa !23
  br label %98

98:                                               ; preds = %94, %61
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %99

99:                                               ; preds = %98, %41, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %100 = load i32, ptr %3, align 4
  ret i32 %100
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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, !10, i64 100}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 56, !6, i64 64, !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}
!13 = !{!"", !14, i64 0, !15, i64 12, !14, i64 32}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !10, i64 8}
!18 = !{!"", !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}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 104}
!22 = !{!18, !10, i64 12}
!23 = !{!12, !10, i64 96}
!24 = !{!12, !10, i64 80}
!25 = !{!12, !10, i64 88}
!26 = !{!12, !10, i64 92}


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

declare i32 @HAL_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_DFSDM_FilterErrorCallback(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_DFSDM_FilterPollForInjConversion(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 100
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.off = add i32 %4, -3
  %switch = icmp ult i32 %.off, 2
  br i1 %switch, label %5, label %.loopexit

5:                                                ; preds = %2
  %6 = tail call i32 @HAL_GetTick() #2
  %7 = load ptr, ptr %0, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load volatile i32, ptr %8, align 4, !tbaa !15
  %10 = and i32 %9, 1
  %.not23.not28 = icmp eq i32 %10, 0
  br i1 %.not23.not28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  switch i32 %1, label %.lr.ph.split.split [
    i32 -1, label %.lr.ph.split.us
    i32 0, label %.lr.ph.split.split.us
  ]

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %11 = load volatile i32, ptr %8, align 4, !tbaa !15
  %12 = and i32 %11, 1
  %.not23.not.us = icmp eq i32 %12, 0
  br i1 %.not23.not.us, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !17

.lr.ph.split.split.us:                            ; preds = %.lr.ph
  %13 = tail call i32 @HAL_GetTick() #2
  br label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph, %17
  %14 = tail call i32 @HAL_GetTick() #2
  %15 = sub i32 %14, %6
  %16 = icmp ugt i32 %15, %1
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %.lr.ph.split.split
  %18 = load ptr, ptr %0, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load volatile i32, ptr %19, align 4, !tbaa !15
  %21 = and i32 %20, 1
  %.not23.not = icmp eq i32 %21, 0
  br i1 %.not23.not, label %.lr.ph.split.split, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph.split.us, %17, %5
  %.lcssa27 = phi ptr [ %7, %5 ], [ %18, %17 ], [ %7, %.lr.ph.split.us ]
  %22 = getelementptr inbounds i8, ptr %.lcssa27, i64 8
  %23 = load volatile i32, ptr %22, align 4, !tbaa !15
  %24 = and i32 %23, 4
  %.not24 = icmp eq i32 %24, 0
  br i1 %.not24, label %29, label %25

25:                                               ; preds = %._crit_edge
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 2, ptr %26, align 8, !tbaa !19
  tail call void @HAL_DFSDM_FilterErrorCallback(ptr noundef nonnull %0)
  %27 = load ptr, ptr %0, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %27, i64 12
  store volatile i32 4, ptr %28, align 4, !tbaa !20
  br label %29

29:                                               ; preds = %25, %._crit_edge
  %30 = getelementptr inbounds i8, ptr %0, i64 96
  %31 = load i32, ptr %30, align 8, !tbaa !21
  %32 = add i32 %31, -1
  store i32 %32, ptr %30, align 8, !tbaa !21
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %.loopexit

34:                                               ; preds = %29
  %35 = getelementptr inbounds i8, ptr %0, i64 80
  %36 = load i32, ptr %35, align 8, !tbaa !22
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %34
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 3
  %41 = select i1 %40, i32 1, i32 2
  store i32 %41, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %38, %34
  %43 = getelementptr inbounds i8, ptr %0, i64 88
  %44 = load i32, ptr %43, align 8, !tbaa !23
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %49

46:                                               ; preds = %42
  %47 = getelementptr inbounds i8, ptr %0, i64 92
  %48 = load i32, ptr %47, align 4, !tbaa !24
  br label %49

49:                                               ; preds = %42, %46
  %50 = phi i32 [ %48, %46 ], [ 1, %42 ]
  store i32 %50, ptr %30, align 8, !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.split.split, %.lr.ph.split.split.us, %2, %29, %49
  %.0 = phi i32 [ 1, %2 ], [ 0, %49 ], [ 0, %29 ], [ 3, %.lr.ph.split.split.us ], [ 3, %.lr.ph.split.split ]
  ret i32 %.0
}

attributes #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 #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, !12, i64 100}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 56, !7, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !13, i64 12, !11, i64 32}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !12, i64 8}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !12, i64 104}
!20 = !{!16, !12, i64 12}
!21 = !{!6, !12, i64 96}
!22 = !{!6, !12, i64 80}
!23 = !{!6, !12, i64 88}
!24 = !{!6, !12, i64 92}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass