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

; 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.FDCAN_HandleTypeDef = type { ptr, ptr, %struct.FDCAN_InitTypeDef, %struct.FDCAN_MsgRamAddressTypeDef, i32, i32, i32, i32 }
%struct.FDCAN_InitTypeDef = 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 }
%struct.FDCAN_MsgRamAddressTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.TTCAN_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [111 x 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_FDCAN_TT_ConfigStopWatch(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %11, i32 0, i32 5
  %13 = load volatile i32, ptr %12, align 8, !tbaa !11
  store i32 %13, ptr %9, align 4, !tbaa !9
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %19, label %16

16:                                               ; preds = %3
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %60

19:                                               ; preds = %16, %3
  br label %20

20:                                               ; preds = %39, %19
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %23, i32 0, i32 5
  %25 = load volatile i32, ptr %24, align 4, !tbaa !16
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, 32768
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %42

29:                                               ; preds = %20
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp ugt i32 %30, 10
  br i1 %31, label %32, label %39

32:                                               ; preds = %29
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %33, i32 0, i32 7
  %35 = load volatile i32, ptr %34, align 8, !tbaa !18
  %36 = or i32 %35, 1
  store volatile i32 %36, ptr %34, align 8, !tbaa !18
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %37, i32 0, i32 5
  store volatile i32 3, ptr %38, align 8, !tbaa !11
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

39:                                               ; preds = %29
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !9
  br label %20, !llvm.loop !19

42:                                               ; preds = %20
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %45, i32 0, i32 5
  %47 = load volatile i32, ptr %46, align 4, !tbaa !16
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, -29
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = or i32 %50, %51
  %53 = zext i32 %52 to i64
  %54 = or i64 %49, %53
  %55 = trunc i64 %54 to i32
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %58, i32 0, i32 5
  store volatile i32 %55, ptr %59, align 4, !tbaa !16
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

60:                                               ; preds = %16
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %61, i32 0, i32 7
  %63 = load volatile i32, ptr %62, align 8, !tbaa !18
  %64 = or i32 %63, 2
  store volatile i32 %64, ptr %62, align 8, !tbaa !18
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %65

65:                                               ; preds = %60, %42, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

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 168}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !14, i64 124, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176}
!13 = !{!"", !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}
!14 = !{!"", !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}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !10, i64 20}
!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, !7, i64 68, !10, i64 512}
!18 = !{!12, !10, i64 176}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_FDCAN_TT_ConfigStopWatch(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 168
  %5 = load volatile i32, ptr %4, align 8, !tbaa !5
  %6 = add i32 %5, -1
  %or.cond = icmp ult i32 %6, 2
  br i1 %or.cond, label %.preheader, label %41

.preheader:                                       ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 20
  %10 = load volatile i32, ptr %9, align 4, !tbaa !14
  %11 = and i32 %10, 32768
  %.not17 = icmp eq i32 %11, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %12 = load volatile i32, ptr %9, align 4, !tbaa !14
  %13 = and i32 %12, 32768
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.1, !llvm.loop !16

.lr.ph.1:                                         ; preds = %.lr.ph.preheader
  %14 = load volatile i32, ptr %9, align 4, !tbaa !14
  %15 = and i32 %14, 32768
  %.not.1 = icmp eq i32 %15, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph.2, !llvm.loop !16

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %16 = load volatile i32, ptr %9, align 4, !tbaa !14
  %17 = and i32 %16, 32768
  %.not.2 = icmp eq i32 %17, 0
  br i1 %.not.2, label %._crit_edge, label %.lr.ph.3, !llvm.loop !16

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %18 = load volatile i32, ptr %9, align 4, !tbaa !14
  %19 = and i32 %18, 32768
  %.not.3 = icmp eq i32 %19, 0
  br i1 %.not.3, label %._crit_edge, label %.lr.ph.4, !llvm.loop !16

.lr.ph.4:                                         ; preds = %.lr.ph.3
  %20 = load volatile i32, ptr %9, align 4, !tbaa !14
  %21 = and i32 %20, 32768
  %.not.4 = icmp eq i32 %21, 0
  br i1 %.not.4, label %._crit_edge, label %.lr.ph.5, !llvm.loop !16

.lr.ph.5:                                         ; preds = %.lr.ph.4
  %22 = load volatile i32, ptr %9, align 4, !tbaa !14
  %23 = and i32 %22, 32768
  %.not.5 = icmp eq i32 %23, 0
  br i1 %.not.5, label %._crit_edge, label %.lr.ph.6, !llvm.loop !16

.lr.ph.6:                                         ; preds = %.lr.ph.5
  %24 = load volatile i32, ptr %9, align 4, !tbaa !14
  %25 = and i32 %24, 32768
  %.not.6 = icmp eq i32 %25, 0
  br i1 %.not.6, label %._crit_edge, label %.lr.ph.7, !llvm.loop !16

.lr.ph.7:                                         ; preds = %.lr.ph.6
  %26 = load volatile i32, ptr %9, align 4, !tbaa !14
  %27 = and i32 %26, 32768
  %.not.7 = icmp eq i32 %27, 0
  br i1 %.not.7, label %._crit_edge, label %.lr.ph.8, !llvm.loop !16

.lr.ph.8:                                         ; preds = %.lr.ph.7
  %28 = load volatile i32, ptr %9, align 4, !tbaa !14
  %29 = and i32 %28, 32768
  %.not.8 = icmp eq i32 %29, 0
  br i1 %.not.8, label %._crit_edge, label %.lr.ph.9, !llvm.loop !16

.lr.ph.9:                                         ; preds = %.lr.ph.8
  %30 = load volatile i32, ptr %9, align 4, !tbaa !14
  %31 = and i32 %30, 32768
  %.not.9 = icmp eq i32 %31, 0
  br i1 %.not.9, label %._crit_edge, label %.lr.ph.10, !llvm.loop !16

.lr.ph.10:                                        ; preds = %.lr.ph.9
  %32 = load volatile i32, ptr %9, align 4, !tbaa !14
  %33 = and i32 %32, 32768
  %.not.10 = icmp eq i32 %33, 0
  br i1 %.not.10, label %._crit_edge, label %.lr.ph.11, !llvm.loop !16

.lr.ph.11:                                        ; preds = %.lr.ph.10
  %34 = getelementptr inbounds i8, ptr %0, i64 176
  %35 = load volatile i32, ptr %34, align 8, !tbaa !18
  %36 = or i32 %35, 1
  store volatile i32 %36, ptr %34, align 8, !tbaa !18
  store volatile i32 3, ptr %4, align 8, !tbaa !5
  br label %45

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.lr.ph.1, %.lr.ph.2, %.lr.ph.3, %.lr.ph.4, %.lr.ph.5, %.lr.ph.6, %.lr.ph.7, %.lr.ph.8, %.lr.ph.9, %.lr.ph.10, %.preheader
  %37 = load volatile i32, ptr %9, align 4, !tbaa !14
  %38 = and i32 %37, -29
  %39 = or i32 %2, %1
  %40 = or i32 %39, %38
  store volatile i32 %40, ptr %9, align 4, !tbaa !14
  br label %45

41:                                               ; preds = %3
  %42 = getelementptr inbounds i8, ptr %0, i64 176
  %43 = load volatile i32, ptr %42, align 8, !tbaa !18
  %44 = or i32 %43, 2
  store volatile i32 %44, ptr %42, align 8, !tbaa !18
  br label %45

45:                                               ; preds = %41, %._crit_edge, %.lr.ph.11
  %.0 = phi i32 [ 1, %.lr.ph.11 ], [ 0, %._crit_edge ], [ 1, %41 ]
  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 168}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 124, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176}
!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, 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}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !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}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !11, i64 20}
!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, !8, i64 68, !11, i64 512}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !11, i64 176}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass