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

; 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_Channel_HandleTypeDef = type { ptr, %struct.DFSDM_Channel_InitTypeDef, i32 }
%struct.DFSDM_Channel_InitTypeDef = type { %struct.DFSDM_Channel_OutputClockTypeDef, %struct.DFSDM_Channel_InputTypeDef, %struct.DFSDM_Channel_SerialInterfaceTypeDef, %struct.DFSDM_Channel_AwdTypeDef, i32, i32 }
%struct.DFSDM_Channel_OutputClockTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Channel_InputTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Channel_SerialInterfaceTypeDef = type { i32, i32 }
%struct.DFSDM_Channel_AwdTypeDef = type { i32, i32 }
%struct.DFSDM_Filter_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.DFSDM_Channel_TypeDef = type { i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare hidden i32 @DFSDM_GetChannelFromInstance(ptr noundef) #0

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

declare i32 @HAL_GetTick() #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_DFSDM_ChannelCkabStart_IT(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %6, i32 0, i32 2
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp ne i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %56

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = call i32 @DFSDM_GetChannelFromInstance(ptr noundef %14)
  store i32 %15, ptr %4, align 4, !tbaa !9
  %16 = call i32 @HAL_GetTick()
  store i32 %16, ptr %5, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %38, %11
  %18 = load volatile i32, ptr getelementptr inbounds (%struct.DFSDM_Filter_TypeDef, ptr inttoptr (i64 1073836288 to ptr), i32 0, i32 2), align 4, !tbaa !17
  %19 = zext i32 %18 to i64
  %20 = and i64 %19, 16711680
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = add i32 16, %21
  %23 = zext i32 %22 to i64
  %24 = lshr i64 %20, %23
  %25 = and i64 %24, 1
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %39

27:                                               ; preds = %17
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add i32 16, %28
  %30 = zext i32 %29 to i64
  %31 = shl i64 1, %30
  %32 = trunc i64 %31 to i32
  store volatile i32 %32, ptr getelementptr inbounds (%struct.DFSDM_Filter_TypeDef, ptr inttoptr (i64 1073836288 to ptr), i32 0, i32 3), align 4, !tbaa !19
  %33 = call i32 @HAL_GetTick()
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sub i32 %33, %34
  %36 = icmp ugt i32 %35, 5000
  br i1 %36, label %37, label %38

37:                                               ; preds = %27
  store i32 3, ptr %3, align 4, !tbaa !9
  br label %39

38:                                               ; preds = %27
  br label %17, !llvm.loop !20

39:                                               ; preds = %37, %17
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %55

42:                                               ; preds = %39
  %43 = load volatile i32, ptr getelementptr inbounds (%struct.DFSDM_Filter_TypeDef, ptr inttoptr (i64 1073836288 to ptr), i32 0, i32 1), align 4, !tbaa !22
  %44 = zext i32 %43 to i64
  %45 = or i64 %44, 64
  %46 = trunc i64 %45 to i32
  store volatile i32 %46, ptr getelementptr inbounds (%struct.DFSDM_Filter_TypeDef, ptr inttoptr (i64 1073836288 to ptr), i32 0, i32 1), align 4, !tbaa !22
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.DFSDM_Channel_TypeDef, ptr %49, i32 0, i32 0
  %51 = load volatile i32, ptr %50, align 4, !tbaa !23
  %52 = zext i32 %51 to i64
  %53 = or i64 %52, 64
  %54 = trunc i64 %53 to i32
  store volatile i32 %54, ptr %50, align 4, !tbaa !23
  br label %55

55:                                               ; preds = %42, %39
  br label %56

56:                                               ; preds = %55, %10
  %57 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %57
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 56}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 56}
!13 = !{!"", !14, i64 0, !14, i64 12, !15, i64 24, !15, i64 32, !10, i64 40, !10, i64 44}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!"", !10, i64 0, !10, i64 4}
!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 = !{!18, !10, i64 12}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!18, !10, i64 4}
!23 = !{!24, !10, i64 0}
!24 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}


; 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
declare hidden i32 @DFSDM_GetChannelFromInstance(ptr noundef) local_unnamed_addr #0

declare i32 @HAL_GetTick() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_DFSDM_ChannelCkabStart_IT(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 1
  br i1 %.not, label %4, label %.loopexit

4:                                                ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !14
  %6 = tail call i32 @DFSDM_GetChannelFromInstance(ptr noundef %5)
  %7 = tail call i32 @HAL_GetTick() #2
  %8 = add i32 %6, 16
  %9 = zext nneg i32 %8 to i64
  %10 = shl nuw i64 1, %9
  %11 = trunc i64 %10 to i32
  br label %12

12:                                               ; preds = %17, %4
  %13 = load volatile i32, ptr inttoptr (i64 1073836296 to ptr), align 8, !tbaa !15
  %14 = and i32 %13, 16711680
  %15 = zext nneg i32 %14 to i64
  %16 = and i64 %10, %15
  %.not7 = icmp eq i64 %16, 0
  br i1 %.not7, label %21, label %17

17:                                               ; preds = %12
  store volatile i32 %11, ptr inttoptr (i64 1073836300 to ptr), align 4, !tbaa !17
  %18 = tail call i32 @HAL_GetTick() #2
  %19 = sub i32 %18, %7
  %20 = icmp ugt i32 %19, 5000
  br i1 %20, label %.loopexit, label %12, !llvm.loop !18

21:                                               ; preds = %12
  %22 = load volatile i32, ptr inttoptr (i64 1073836292 to ptr), align 4, !tbaa !20
  %23 = or i32 %22, 64
  store volatile i32 %23, ptr inttoptr (i64 1073836292 to ptr), align 4, !tbaa !20
  %24 = load ptr, ptr %0, align 8, !tbaa !14
  %25 = load volatile i32, ptr %24, align 4, !tbaa !21
  %26 = or i32 %25, 64
  store volatile i32 %26, ptr %24, align 4, !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %17, %1, %21
  %.1 = phi i32 [ 0, %21 ], [ 1, %1 ], [ 3, %17 ]
  ret i32 %.1
}

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

!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 56}
!6 = !{!"", !7, i64 0, !10, i64 8, !12, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 12, !13, i64 24, !13, i64 32, !12, i64 40, !12, i64 44}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4}
!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 = !{!16, !12, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!16, !12, i64 4}
!21 = !{!22, !12, i64 0}
!22 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass