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

; 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_EventCfgTypeDef = type { i32, i32, i32, i32, i32 }
%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_SimpleCaptureChannelCfgTypeDef = type { 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_HRTIM_SimpleCaptureChannelConfig(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %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
  %10 = alloca %struct.HRTIM_EventCfgTypeDef, align 4
  %11 = 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 ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %10) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %12, i32 0, i32 4
  %14 = load volatile i32, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i32 2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %72

17:                                               ; preds = %4
  br label %18

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

23:                                               ; preds = %18
  store i32 2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %72

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

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %30, i32 0, i32 4
  store volatile i32 2, ptr %31, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.HRTIM_EventCfgTypeDef, ptr %10, i32 0, i32 4
  store i32 0, ptr %32, align 4, !tbaa !15
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.HRTIM_SimpleCaptureChannelCfgTypeDef, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = zext i32 %35 to i64
  %37 = and i64 %36, 15
  %38 = trunc i64 %37 to i32
  %39 = getelementptr inbounds %struct.HRTIM_EventCfgTypeDef, ptr %10, i32 0, i32 3
  store i32 %38, ptr %39, align 4, !tbaa !18
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.HRTIM_SimpleCaptureChannelCfgTypeDef, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !19
  %43 = zext i32 %42 to i64
  %44 = and i64 %43, 4
  %45 = trunc i64 %44 to i32
  %46 = getelementptr inbounds %struct.HRTIM_EventCfgTypeDef, ptr %10, i32 0, i32 1
  store i32 %45, ptr %46, align 4, !tbaa !20
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HRTIM_SimpleCaptureChannelCfgTypeDef, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 4, !tbaa !21
  %50 = zext i32 %49 to i64
  %51 = and i64 %50, 24
  %52 = trunc i64 %51 to i32
  %53 = getelementptr inbounds %struct.HRTIM_EventCfgTypeDef, ptr %10, i32 0, i32 2
  store i32 %52, ptr %53, align 4, !tbaa !22
  %54 = getelementptr inbounds %struct.HRTIM_EventCfgTypeDef, ptr %10, i32 0, i32 0
  store i32 0, ptr %54, align 4, !tbaa !23
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.HRTIM_SimpleCaptureChannelCfgTypeDef, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !24
  call void @HRTIM_EventConfig(ptr noundef %55, i32 noundef %58, ptr noundef %10)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.HRTIM_SimpleCaptureChannelCfgTypeDef, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 4, !tbaa !24
  call void @HRTIM_CaptureUnitConfig(ptr noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %64)
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.HRTIM_HandleTypeDef, ptr %65, i32 0, i32 4
  store volatile i32 1, ptr %66, align 8, !tbaa !11
  br label %67

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

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %71, %23, %16
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #2
  %73 = load i32, ptr %5, align 4
  ret i32 %73
}

; Function Attrs: nounwind uwtable
declare hidden void @HRTIM_EventConfig(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @HRTIM_CaptureUnitConfig(ptr noundef, i32 noundef, i32 noundef, 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 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 = !{!13, !10, i64 16}
!16 = !{!17, !10, i64 12}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!13, !10, i64 12}
!19 = !{!17, !10, i64 4}
!20 = !{!13, !10, i64 4}
!21 = !{!17, !10, i64 8}
!22 = !{!13, !10, i64 8}
!23 = !{!13, !10, i64 0}
!24 = !{!17, !10, i64 0}


; 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_EventCfgTypeDef = type { i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 range(i32 0, 3) i32 @HAL_HRTIM_SimpleCaptureChannelConfig(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = alloca %struct.HRTIM_EventCfgTypeDef, align 4
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %5) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 200
  %7 = load volatile i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %25, label %9

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

13:                                               ; preds = %9
  store i32 1, ptr %10, align 4, !tbaa !12
  store volatile i32 2, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 0, ptr %14, align 4, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %3, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = and i32 %16, 15
  %18 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %17, ptr %18, align 4, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %3, i64 4
  %20 = getelementptr inbounds i8, ptr %5, i64 4
  %21 = load <2 x i32>, ptr %19, align 4, !tbaa !17
  %22 = and <2 x i32> %21, <i32 4, i32 24>
  store <2 x i32> %22, ptr %20, align 4, !tbaa !17
  store i32 0, ptr %5, align 4, !tbaa !18
  %23 = load i32, ptr %3, align 4, !tbaa !19
  call void @HRTIM_EventConfig(ptr noundef nonnull %0, i32 noundef %23, ptr noundef nonnull %5)
  %24 = load i32, ptr %3, align 4, !tbaa !19
  call void @HRTIM_CaptureUnitConfig(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %24)
  store volatile i32 1, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %9, %4, %13
  %.0 = phi i32 [ 0, %13 ], [ 2, %4 ], [ 2, %9 ]
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %5) #2
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @HRTIM_EventConfig(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @HRTIM_CaptureUnitConfig(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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, !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 = !{!10, !11, i64 16}
!14 = !{!15, !11, i64 12}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!16 = !{!10, !11, i64 12}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !11, i64 0}
!19 = !{!15, !11, i64 0}


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