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

; 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_SetEndOfGap(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 %75

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, 8
  %23 = icmp ne i64 %22, 8
  br i1 %23, label %24, label %29

24:                                               ; preds = %15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %25, i32 0, i32 7
  %27 = load volatile i32, ptr %26, align 8, !tbaa !18
  %28 = or i32 %27, 16
  store volatile i32 %28, ptr %26, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %80

29:                                               ; preds = %15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %32, i32 0, i32 2
  %34 = load volatile i32, ptr %33, align 4, !tbaa !16
  %35 = zext i32 %34 to i64
  %36 = and i64 %35, 3
  %37 = icmp ne i64 %36, 3
  br i1 %37, label %38, label %70

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %58, %38
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %42, i32 0, i32 5
  %44 = load volatile i32, ptr %43, align 4, !tbaa !19
  %45 = zext i32 %44 to i64
  %46 = and i64 %45, 32768
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %61

48:                                               ; preds = %39
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = icmp ugt i32 %49, 10
  br i1 %50, label %51, label %58

51:                                               ; preds = %48
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %52, i32 0, i32 7
  %54 = load volatile i32, ptr %53, align 8, !tbaa !18
  %55 = or i32 %54, 1
  store volatile i32 %55, ptr %53, align 8, !tbaa !18
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %56, i32 0, i32 5
  store volatile i32 3, ptr %57, align 8, !tbaa !11
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %80

58:                                               ; preds = %48
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !9
  br label %39, !llvm.loop !20

61:                                               ; preds = %39
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %64, i32 0, i32 5
  %66 = load volatile i32, ptr %65, align 4, !tbaa !19
  %67 = zext i32 %66 to i64
  %68 = or i64 %67, 1024
  %69 = trunc i64 %68 to i32
  store volatile i32 %69, ptr %65, align 4, !tbaa !19
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %80

70:                                               ; preds = %29
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %71, i32 0, i32 7
  %73 = load volatile i32, ptr %72, align 8, !tbaa !18
  %74 = or i32 %73, 16
  store volatile i32 %74, ptr %72, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %80

75:                                               ; preds = %12
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %76, i32 0, i32 7
  %78 = load volatile i32, ptr %77, align 8, !tbaa !18
  %79 = or i32 %78, 2
  store volatile i32 %79, ptr %77, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %80

80:                                               ; preds = %75, %70, %61, %51, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %81 = load i32, ptr %2, align 4
  ret i32 %81
}

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 = !{!12, !10, i64 176}
!19 = !{!17, !10, i64 20}
!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_SetEndOfGap(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 %52

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, 8
  %.not.not = icmp eq i32 %10, 0
  br i1 %.not.not, label %11, label %15

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %0, i64 176
  %13 = load volatile i32, ptr %12, align 8, !tbaa !16
  %14 = or i32 %13, 16
  store volatile i32 %14, ptr %12, align 8, !tbaa !16
  br label %56

15:                                               ; preds = %5
  %16 = load volatile i32, ptr %8, align 4, !tbaa !14
  %17 = and i32 %16, 3
  %.not = icmp eq i32 %17, 3
  br i1 %.not, label %48, label %.preheader

.preheader:                                       ; preds = %15
  %18 = getelementptr inbounds i8, ptr %7, i64 20
  %19 = load volatile i32, ptr %18, align 4, !tbaa !17
  %20 = and i32 %19, 32768
  %.not1618 = icmp eq i32 %20, 0
  br i1 %.not1618, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %21 = load volatile i32, ptr %18, align 4, !tbaa !17
  %22 = and i32 %21, 32768
  %.not16 = icmp eq i32 %22, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph.1, !llvm.loop !18

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

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

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

.lr.ph.4:                                         ; preds = %.lr.ph.3
  %29 = load volatile i32, ptr %18, align 4, !tbaa !17
  %30 = and i32 %29, 32768
  %.not16.4 = icmp eq i32 %30, 0
  br i1 %.not16.4, label %._crit_edge, label %.lr.ph.5, !llvm.loop !18

.lr.ph.5:                                         ; preds = %.lr.ph.4
  %31 = load volatile i32, ptr %18, align 4, !tbaa !17
  %32 = and i32 %31, 32768
  %.not16.5 = icmp eq i32 %32, 0
  br i1 %.not16.5, label %._crit_edge, label %.lr.ph.6, !llvm.loop !18

.lr.ph.6:                                         ; preds = %.lr.ph.5
  %33 = load volatile i32, ptr %18, align 4, !tbaa !17
  %34 = and i32 %33, 32768
  %.not16.6 = icmp eq i32 %34, 0
  br i1 %.not16.6, label %._crit_edge, label %.lr.ph.7, !llvm.loop !18

.lr.ph.7:                                         ; preds = %.lr.ph.6
  %35 = load volatile i32, ptr %18, align 4, !tbaa !17
  %36 = and i32 %35, 32768
  %.not16.7 = icmp eq i32 %36, 0
  br i1 %.not16.7, label %._crit_edge, label %.lr.ph.8, !llvm.loop !18

.lr.ph.8:                                         ; preds = %.lr.ph.7
  %37 = load volatile i32, ptr %18, align 4, !tbaa !17
  %38 = and i32 %37, 32768
  %.not16.8 = icmp eq i32 %38, 0
  br i1 %.not16.8, label %._crit_edge, label %.lr.ph.9, !llvm.loop !18

.lr.ph.9:                                         ; preds = %.lr.ph.8
  %39 = load volatile i32, ptr %18, align 4, !tbaa !17
  %40 = and i32 %39, 32768
  %.not16.9 = icmp eq i32 %40, 0
  br i1 %.not16.9, label %._crit_edge, label %.lr.ph.10, !llvm.loop !18

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

.lr.ph.11:                                        ; preds = %.lr.ph.10
  %43 = getelementptr inbounds i8, ptr %0, i64 176
  %44 = load volatile i32, ptr %43, align 8, !tbaa !16
  %45 = or i32 %44, 1
  store volatile i32 %45, ptr %43, align 8, !tbaa !16
  store volatile i32 3, ptr %2, align 8, !tbaa !5
  br label %56

._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
  %46 = load volatile i32, ptr %18, align 4, !tbaa !17
  %47 = or i32 %46, 1024
  store volatile i32 %47, ptr %18, align 4, !tbaa !17
  br label %56

48:                                               ; preds = %15
  %49 = getelementptr inbounds i8, ptr %0, i64 176
  %50 = load volatile i32, ptr %49, align 8, !tbaa !16
  %51 = or i32 %50, 16
  store volatile i32 %51, ptr %49, align 8, !tbaa !16
  br label %56

52:                                               ; preds = %1
  %53 = getelementptr inbounds i8, ptr %0, i64 176
  %54 = load volatile i32, ptr %53, align 8, !tbaa !16
  %55 = or i32 %54, 2
  store volatile i32 %55, ptr %53, align 8, !tbaa !16
  br label %56

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


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