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

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

12:                                               ; preds = %1
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %47

15:                                               ; preds = %12, %1
  br label %16

16:                                               ; preds = %35, %15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %19, i32 0, i32 5
  %21 = load volatile i32, ptr %20, align 4, !tbaa !16
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, 32768
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %38

25:                                               ; preds = %16
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp ugt i32 %26, 10
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %29, i32 0, i32 7
  %31 = load volatile i32, ptr %30, align 8, !tbaa !18
  %32 = or i32 %31, 1
  store volatile i32 %32, ptr %30, align 8, !tbaa !18
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %33, i32 0, i32 5
  store volatile i32 3, ptr %34, align 8, !tbaa !11
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %52

35:                                               ; preds = %25
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = add i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !9
  br label %16, !llvm.loop !19

38:                                               ; preds = %16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %41, i32 0, i32 5
  %43 = load volatile i32, ptr %42, align 4, !tbaa !16
  %44 = zext i32 %43 to i64
  %45 = and i64 %44, -8193
  %46 = trunc i64 %45 to i32
  store volatile i32 %46, ptr %42, align 4, !tbaa !16
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %52

47:                                               ; preds = %12
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %48, i32 0, i32 7
  %50 = load volatile i32, ptr %49, align 8, !tbaa !18
  %51 = or i32 %50, 2
  store volatile i32 %51, ptr %49, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %52

52:                                               ; preds = %47, %38, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %53 = load i32, ptr %2, align 4
  ret i32 %53
}

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_DisableExternalSynchronization(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 168
  %3 = load volatile i32, ptr %2, align 8, !tbaa !5
  %4 = add i32 %3, -1
  %or.cond = icmp ult i32 %4, 2
  br i1 %or.cond, label %.preheader, label %37

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

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

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

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

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

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

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

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

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

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

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

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

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

._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
  %35 = load volatile i32, ptr %7, align 4, !tbaa !14
  %36 = and i32 %35, -8193
  store volatile i32 %36, ptr %7, align 4, !tbaa !14
  br label %41

37:                                               ; preds = %1
  %38 = getelementptr inbounds i8, ptr %0, i64 176
  %39 = load volatile i32, ptr %38, align 8, !tbaa !18
  %40 = or i32 %39, 2
  store volatile i32 %40, ptr %38, align 8, !tbaa !18
  br label %41

41:                                               ; preds = %37, %._crit_edge, %.lr.ph.11
  %.0 = phi i32 [ 1, %.lr.ph.11 ], [ 0, %._crit_edge ], [ 1, %37 ]
  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,SCCPPass,SROAPass,SimplifyCFGPass