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

; 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

; 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
define dso_local i32 @HAL_DFSDM_FilterConfigInjChannel(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %6, i32 0, i32 11
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %39

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

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = and i32 %16, 65535
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.DFSDM_Filter_TypeDef, ptr %20, i32 0, i32 4
  store volatile i32 %17, ptr %21, align 4, !tbaa !17
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = call i32 @DFSDM_GetInjChannelsNbr(i32 noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %24, i32 0, i32 9
  store i32 %23, ptr %25, align 4, !tbaa !19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 8, !tbaa !20
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %34

30:                                               ; preds = %15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %31, i32 0, i32 9
  %33 = load i32, ptr %32, align 4, !tbaa !19
  br label %35

34:                                               ; preds = %15
  br label %35

35:                                               ; preds = %34, %30
  %36 = phi i32 [ %33, %30 ], [ 1, %34 ]
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.DFSDM_Filter_HandleTypeDef, ptr %37, i32 0, i32 10
  store i32 %36, ptr %38, align 8, !tbaa !21
  br label %40

39:                                               ; preds = %10, %2
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %39, %35
  %41 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %41
}

; Function Attrs: nounwind uwtable
declare hidden i32 @DFSDM_GetInjChannelsNbr(i32 noundef) #1

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, !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 16}
!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 = !{!12, !10, i64 92}
!20 = !{!12, !10, i64 88}
!21 = !{!12, !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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_DFSDM_FilterConfigInjChannel(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 100
  %4 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %4, label %5 [
    i32 0, label %15
    i32 255, label %15
  ]

5:                                                ; preds = %2
  %6 = and i32 %1, 65535
  %7 = load ptr, ptr %0, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store volatile i32 %6, ptr %8, align 4, !tbaa !15
  %9 = tail call i32 @DFSDM_GetInjChannelsNbr(i32 noundef %1)
  %10 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %9, ptr %10, align 4, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  %12 = load i32, ptr %11, align 8, !tbaa !18
  %13 = icmp eq i32 %12, 1
  %spec.select = select i1 %13, i32 %9, i32 1
  %14 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %spec.select, ptr %14, align 8, !tbaa !19
  br label %15

15:                                               ; preds = %2, %2, %5
  %.0 = phi i32 [ 0, %5 ], [ 1, %2 ], [ 1, %2 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @DFSDM_GetInjChannelsNbr(i32 noundef) local_unnamed_addr #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, !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 16}
!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 = !{!6, !12, i64 92}
!18 = !{!6, !12, i64 88}
!19 = !{!6, !12, i64 96}


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