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

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

14:                                               ; preds = %2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 2
  br i1 %16, label %17, label %93

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

26:                                               ; preds = %17
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %27, i32 0, i32 7
  %29 = load volatile i32, ptr %28, align 8, !tbaa !18
  %30 = or i32 %29, 16
  store volatile i32 %30, ptr %28, align 8, !tbaa !18
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %98

31:                                               ; preds = %17
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %34, i32 0, i32 11
  %36 = load volatile i32, ptr %35, align 4, !tbaa !19
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, 1073741824
  %39 = icmp eq i64 %38, 1073741824
  br i1 %39, label %40, label %45

40:                                               ; preds = %31
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %41, i32 0, i32 7
  %43 = load volatile i32, ptr %42, align 8, !tbaa !18
  %44 = or i32 %43, 64
  store volatile i32 %44, ptr %42, align 8, !tbaa !18
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %98

45:                                               ; preds = %31
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %48, i32 0, i32 4
  %50 = load volatile i32, ptr %49, align 4, !tbaa !20
  %51 = zext i32 %50 to i64
  %52 = and i64 %51, -65536
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sub i32 %53, 65536
  %55 = zext i32 %54 to i64
  %56 = or i64 %52, %55
  %57 = trunc i64 %56 to i32
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %60, i32 0, i32 4
  store volatile i32 %57, ptr %61, align 4, !tbaa !20
  br label %62

62:                                               ; preds = %81, %45
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %65, i32 0, i32 5
  %67 = load volatile i32, ptr %66, align 4, !tbaa !21
  %68 = zext i32 %67 to i64
  %69 = and i64 %68, 32768
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %71, label %84

71:                                               ; preds = %62
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = icmp ugt i32 %72, 10
  br i1 %73, label %74, label %81

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

81:                                               ; preds = %71
  %82 = load i32, ptr %6, align 4, !tbaa !9
  %83 = add i32 %82, 1
  store i32 %83, ptr %6, align 4, !tbaa !9
  br label %62, !llvm.loop !22

84:                                               ; preds = %62
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !15
  %88 = getelementptr inbounds %struct.TTCAN_TypeDef, ptr %87, i32 0, i32 5
  %89 = load volatile i32, ptr %88, align 4, !tbaa !21
  %90 = zext i32 %89 to i64
  %91 = or i64 %90, 2
  %92 = trunc i64 %91 to i32
  store volatile i32 %92, ptr %88, align 4, !tbaa !21
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %98

93:                                               ; preds = %14
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %94, i32 0, i32 7
  %96 = load volatile i32, ptr %95, align 8, !tbaa !18
  %97 = or i32 %96, 2
  store volatile i32 %97, ptr %95, align 8, !tbaa !18
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %98

98:                                               ; preds = %93, %84, %74, %40, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %99 = load i32, ptr %3, align 4
  ret i32 %99
}

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 44}
!20 = !{!17, !10, i64 16}
!21 = !{!17, !10, i64 20}
!22 = distinct !{!22, !23}
!23 = !{!"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_SetClockSynchronization(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 168
  %4 = load volatile i32, ptr %3, align 8, !tbaa !5
  %5 = add i32 %4, -1
  %or.cond = icmp ult i32 %5, 2
  br i1 %or.cond, label %6, label %60

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load volatile i32, ptr %9, align 4, !tbaa !14
  %11 = and i32 %10, 32768
  %.not.not = icmp eq i32 %11, 0
  br i1 %.not.not, label %12, label %16

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

16:                                               ; preds = %6
  %17 = getelementptr inbounds i8, ptr %8, i64 44
  %18 = load volatile i32, ptr %17, align 4, !tbaa !17
  %19 = and i32 %18, 1073741824
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %24, label %20

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 176
  %22 = load volatile i32, ptr %21, align 8, !tbaa !16
  %23 = or i32 %22, 64
  store volatile i32 %23, ptr %21, align 8, !tbaa !16
  br label %64

24:                                               ; preds = %16
  %25 = getelementptr inbounds i8, ptr %8, i64 16
  %26 = load volatile i32, ptr %25, align 4, !tbaa !18
  %27 = and i32 %26, -65536
  %28 = add i32 %1, -65536
  %29 = or i32 %27, %28
  store volatile i32 %29, ptr %25, align 4, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %8, i64 20
  %31 = load volatile i32, ptr %30, align 4, !tbaa !19
  %32 = and i32 %31, 32768
  %.not1921 = icmp eq i32 %32, 0
  br i1 %.not1921, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %24
  %33 = load volatile i32, ptr %30, align 4, !tbaa !19
  %34 = and i32 %33, 32768
  %.not19 = icmp eq i32 %34, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph.1, !llvm.loop !20

.lr.ph.1:                                         ; preds = %.lr.ph.preheader
  %35 = load volatile i32, ptr %30, align 4, !tbaa !19
  %36 = and i32 %35, 32768
  %.not19.1 = icmp eq i32 %36, 0
  br i1 %.not19.1, label %._crit_edge, label %.lr.ph.2, !llvm.loop !20

.lr.ph.2:                                         ; preds = %.lr.ph.1
  %37 = load volatile i32, ptr %30, align 4, !tbaa !19
  %38 = and i32 %37, 32768
  %.not19.2 = icmp eq i32 %38, 0
  br i1 %.not19.2, label %._crit_edge, label %.lr.ph.3, !llvm.loop !20

.lr.ph.3:                                         ; preds = %.lr.ph.2
  %39 = load volatile i32, ptr %30, align 4, !tbaa !19
  %40 = and i32 %39, 32768
  %.not19.3 = icmp eq i32 %40, 0
  br i1 %.not19.3, label %._crit_edge, label %.lr.ph.4, !llvm.loop !20

.lr.ph.4:                                         ; preds = %.lr.ph.3
  %41 = load volatile i32, ptr %30, align 4, !tbaa !19
  %42 = and i32 %41, 32768
  %.not19.4 = icmp eq i32 %42, 0
  br i1 %.not19.4, label %._crit_edge, label %.lr.ph.5, !llvm.loop !20

.lr.ph.5:                                         ; preds = %.lr.ph.4
  %43 = load volatile i32, ptr %30, align 4, !tbaa !19
  %44 = and i32 %43, 32768
  %.not19.5 = icmp eq i32 %44, 0
  br i1 %.not19.5, label %._crit_edge, label %.lr.ph.6, !llvm.loop !20

.lr.ph.6:                                         ; preds = %.lr.ph.5
  %45 = load volatile i32, ptr %30, align 4, !tbaa !19
  %46 = and i32 %45, 32768
  %.not19.6 = icmp eq i32 %46, 0
  br i1 %.not19.6, label %._crit_edge, label %.lr.ph.7, !llvm.loop !20

.lr.ph.7:                                         ; preds = %.lr.ph.6
  %47 = load volatile i32, ptr %30, align 4, !tbaa !19
  %48 = and i32 %47, 32768
  %.not19.7 = icmp eq i32 %48, 0
  br i1 %.not19.7, label %._crit_edge, label %.lr.ph.8, !llvm.loop !20

.lr.ph.8:                                         ; preds = %.lr.ph.7
  %49 = load volatile i32, ptr %30, align 4, !tbaa !19
  %50 = and i32 %49, 32768
  %.not19.8 = icmp eq i32 %50, 0
  br i1 %.not19.8, label %._crit_edge, label %.lr.ph.9, !llvm.loop !20

.lr.ph.9:                                         ; preds = %.lr.ph.8
  %51 = load volatile i32, ptr %30, align 4, !tbaa !19
  %52 = and i32 %51, 32768
  %.not19.9 = icmp eq i32 %52, 0
  br i1 %.not19.9, label %._crit_edge, label %.lr.ph.10, !llvm.loop !20

.lr.ph.10:                                        ; preds = %.lr.ph.9
  %53 = load volatile i32, ptr %30, align 4, !tbaa !19
  %54 = and i32 %53, 32768
  %.not19.10 = icmp eq i32 %54, 0
  br i1 %.not19.10, label %._crit_edge, label %.lr.ph.11, !llvm.loop !20

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

._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, %24
  %58 = load volatile i32, ptr %30, align 4, !tbaa !19
  %59 = or i32 %58, 2
  store volatile i32 %59, ptr %30, align 4, !tbaa !19
  br label %64

60:                                               ; preds = %2
  %61 = getelementptr inbounds i8, ptr %0, i64 176
  %62 = load volatile i32, ptr %61, align 8, !tbaa !16
  %63 = or i32 %62, 2
  store volatile i32 %63, ptr %61, align 8, !tbaa !16
  br label %64

64:                                               ; preds = %60, %._crit_edge, %.lr.ph.11, %20, %12
  %.0 = phi i32 [ 1, %12 ], [ 1, %20 ], [ 1, %.lr.ph.11 ], [ 0, %._crit_edge ], [ 1, %60 ]
  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 44}
!18 = !{!15, !11, i64 16}
!19 = !{!15, !11, i64 20}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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