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

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

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  br label %16

16:                                               ; preds = %15, %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %17, i32 0, i32 5
  %19 = load volatile i32, ptr %18, align 8, !tbaa !12
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %21, label %74

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds %struct.FDCAN_GlobalTypeDef, ptr %24, i32 0, i32 38
  %26 = load volatile i32, ptr %25, align 4, !tbaa !17
  %27 = zext i32 %26 to i64
  %28 = and i64 %27, 1056964608
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %21
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %31, i32 0, i32 7
  %33 = load volatile i32, ptr %32, align 8, !tbaa !19
  %34 = or i32 %33, 32
  store volatile i32 %34, ptr %32, align 8, !tbaa !19
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %79

35:                                               ; preds = %21
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = getelementptr inbounds %struct.FDCAN_GlobalTypeDef, ptr %38, i32 0, i32 39
  %40 = load volatile i32, ptr %39, align 4, !tbaa !20
  %41 = zext i32 %40 to i64
  %42 = and i64 %41, 2097152
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %35
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %45, i32 0, i32 7
  %47 = load volatile i32, ptr %46, align 8, !tbaa !19
  %48 = or i32 %47, 512
  store volatile i32 %48, ptr %46, align 8, !tbaa !19
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %79

49:                                               ; preds = %35
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  %53 = getelementptr inbounds %struct.FDCAN_GlobalTypeDef, ptr %52, i32 0, i32 39
  %54 = load volatile i32, ptr %53, align 4, !tbaa !20
  %55 = zext i32 %54 to i64
  %56 = and i64 %55, 2031616
  %57 = lshr i64 %56, 16
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %8, align 4, !tbaa !21
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !21
  call void @FDCAN_CopyMessageToRAM(ptr noundef %59, ptr noundef %60, ptr noundef %61, i32 noundef %62)
  %63 = load i32, ptr %8, align 4, !tbaa !21
  %64 = shl i32 1, %63
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = getelementptr inbounds %struct.FDCAN_GlobalTypeDef, ptr %67, i32 0, i32 42
  store volatile i32 %64, ptr %68, align 4, !tbaa !22
  %69 = load i32, ptr %8, align 4, !tbaa !21
  %70 = shl i32 1, %69
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %71, i32 0, i32 4
  store i32 %70, ptr %72, align 4, !tbaa !23
  br label %73

73:                                               ; preds = %49
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %79

74:                                               ; preds = %16
  %75 = load ptr, ptr %5, 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 !19
  %78 = or i32 %77, 8
  store volatile i32 %78, ptr %76, align 8, !tbaa !19
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %79

79:                                               ; preds = %74, %73, %44, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %80 = load i32, ptr %4, align 4
  ret i32 %80
}

; Function Attrs: nounwind uwtable
declare hidden void @FDCAN_CopyMessageToRAM(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

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, !11, i64 4}
!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 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 168}
!13 = !{!"", !6, i64 0, !6, i64 8, !14, i64 16, !15, i64 124, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176}
!14 = !{!"", !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}
!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}
!16 = !{!13, !6, i64 0}
!17 = !{!18, !11, i64 192}
!18 = !{!"", !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, !7, i64 48, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !7, i64 96, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !7, i64 232, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252}
!19 = !{!13, !11, i64 176}
!20 = !{!18, !11, i64 196}
!21 = !{!11, !11, i64 0}
!22 = !{!18, !11, i64 208}
!23 = !{!13, !11, i64 164}


; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_FDCAN_AddMessageToTxFifoQ(ptr noundef %0, ptr noundef %1, ptr 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 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %33

7:                                                ; preds = %3
  %8 = load ptr, ptr %0, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 192
  %10 = load volatile i32, ptr %9, align 4, !tbaa !14
  %11 = and i32 %10, 1056964608
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %17

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

17:                                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %8, i64 196
  %19 = load volatile i32, ptr %18, align 4, !tbaa !17
  %20 = and i32 %19, 2097152
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %25, label %21

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

25:                                               ; preds = %17
  %26 = load volatile i32, ptr %18, align 4, !tbaa !17
  %27 = lshr i32 %26, 16
  %28 = and i32 %27, 31
  tail call void @FDCAN_CopyMessageToRAM(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i32 noundef %28)
  %29 = shl nuw i32 1, %28
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %30, i64 208
  store volatile i32 %29, ptr %31, align 4, !tbaa !18
  %32 = getelementptr inbounds i8, ptr %0, i64 164
  store i32 %29, ptr %32, align 4, !tbaa !19
  br label %37

33:                                               ; preds = %3
  %34 = getelementptr inbounds i8, ptr %0, i64 176
  %35 = load volatile i32, ptr %34, align 8, !tbaa !16
  %36 = or i32 %35, 8
  store volatile i32 %36, ptr %34, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %33, %25, %21, %13
  %.0 = phi i32 [ 1, %13 ], [ 1, %21 ], [ 0, %25 ], [ 1, %33 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @FDCAN_CopyMessageToRAM(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { 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 0}
!14 = !{!15, !11, i64 192}
!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, !8, i64 48, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !8, i64 96, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !11, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !8, i64 232, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252}
!16 = !{!6, !11, i64 176}
!17 = !{!15, !11, i64 196}
!18 = !{!15, !11, i64 208}
!19 = !{!6, !11, i64 164}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass