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

; 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_DisableTimeMarkGapControl(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 %61

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

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %44, %24
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %28, i32 0, i32 5
  %30 = load volatile i32, ptr %29, align 4, !tbaa !18
  %31 = zext i32 %30 to i64
  %32 = and i64 %31, 32768
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %25
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp ugt i32 %35, 10
  br i1 %36, label %37, label %44

37:                                               ; preds = %34
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %38, i32 0, i32 7
  %40 = load volatile i32, ptr %39, align 8, !tbaa !19
  %41 = or i32 %40, 1
  store volatile i32 %41, ptr %39, align 8, !tbaa !19
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %42, i32 0, i32 5
  store volatile i32 3, ptr %43, align 8, !tbaa !11
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %66

44:                                               ; preds = %34
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store i32 %46, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !20

47:                                               ; preds = %25
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %50, i32 0, i32 5
  %52 = load volatile i32, ptr %51, align 4, !tbaa !18
  %53 = zext i32 %52 to i64
  %54 = and i64 %53, -2049
  %55 = trunc i64 %54 to i32
  store volatile i32 %55, ptr %51, align 4, !tbaa !18
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %66

56:                                               ; preds = %15
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %57, i32 0, i32 7
  %59 = load volatile i32, ptr %58, align 8, !tbaa !19
  %60 = or i32 %59, 16
  store volatile i32 %60, ptr %58, align 8, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %66

61:                                               ; preds = %12
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %62, i32 0, i32 7
  %64 = load volatile i32, ptr %63, align 8, !tbaa !19
  %65 = or i32 %64, 2
  store volatile i32 %65, ptr %63, align 8, !tbaa !19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %66

66:                                               ; preds = %61, %56, %47, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %67 = load i32, ptr %2, align 4
  ret i32 %67
}

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 8}
!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 = !{!17, !10, i64 20}
!19 = !{!12, !10, i64 176}
!20 = distinct !{!20, !21}
!21 = !{!"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_DisableTimeMarkGapControl(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 %5, label %45

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load volatile i32, ptr %8, align 4, !tbaa !14
  %10 = and i32 %9, 3
  %.not = icmp eq i32 %10, 3
  br i1 %.not, label %41, label %.preheader

.preheader:                                       ; preds = %5
  %11 = getelementptr inbounds i8, ptr %7, i64 20
  %12 = load volatile i32, ptr %11, align 4, !tbaa !16
  %13 = and i32 %12, 32768
  %.not1416 = icmp eq i32 %13, 0
  br i1 %.not1416, label %._crit_edge, label %.lr.ph.preheader

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

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

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

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

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

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

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

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

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

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

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

.lr.ph.11:                                        ; preds = %.lr.ph.10
  %36 = getelementptr inbounds i8, ptr %0, i64 176
  %37 = load volatile i32, ptr %36, align 8, !tbaa !19
  %38 = or i32 %37, 1
  store volatile i32 %38, ptr %36, align 8, !tbaa !19
  store volatile i32 3, ptr %2, align 8, !tbaa !5
  br label %49

._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
  %39 = load volatile i32, ptr %11, align 4, !tbaa !16
  %40 = and i32 %39, -2049
  store volatile i32 %40, ptr %11, align 4, !tbaa !16
  br label %49

41:                                               ; preds = %5
  %42 = getelementptr inbounds i8, ptr %0, i64 176
  %43 = load volatile i32, ptr %42, align 8, !tbaa !19
  %44 = or i32 %43, 16
  store volatile i32 %44, ptr %42, align 8, !tbaa !19
  br label %49

45:                                               ; preds = %1
  %46 = getelementptr inbounds i8, ptr %0, i64 176
  %47 = load volatile i32, ptr %46, align 8, !tbaa !19
  %48 = or i32 %47, 2
  store volatile i32 %48, ptr %46, align 8, !tbaa !19
  br label %49

49:                                               ; preds = %45, %41, %._crit_edge, %.lr.ph.11
  %.0 = phi i32 [ 1, %.lr.ph.11 ], [ 0, %._crit_edge ], [ 1, %41 ], [ 1, %45 ]
  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 8}
!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 = !{!15, !11, i64 20}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !11, i64 176}


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