; LLVM IR from PX4/sapog :: bootloader/bootloader/src (uavcan)

; 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.uavcan_LogMessage_t = type { i8, [4 x i8], [2 x i8] }
%struct.uavcan_protocol_t = type <{ %union.anon, %union.anon.1 }>
%union.anon = type { %struct.can_id_t }
%struct.can_id_t = type { %union.anon.0 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { %struct.can_tail_t }
%struct.can_tail_t = type { %union.anon.2 }
%union.anon.2 = type { i8 }
%struct.dsdl_t = type <{ %struct.uavcan_protocol_t, i16, i8, i8, i8 }>

@uavcan_tx_log_message.transfer_id = external hidden global i8, align 1
@debug_log_source = external constant [4 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @load_dsdl_protocol(i32 noundef, i32 noundef, ptr noundef, i8 noundef zeroext) #1

; 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
declare hidden i32 @uavcan_tx(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @uavcan_tx_log_message(i32 noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca %struct.uavcan_LogMessage_t, align 1
  %8 = alloca %struct.uavcan_protocol_t, align 1
  %9 = alloca ptr, align 8
  %10 = alloca [8 x i8], align 1
  %11 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 7, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 5, ptr %8) #3
  %12 = load i8, ptr @uavcan_tx_log_message.transfer_id, align 1, !tbaa !9
  %13 = add i8 %12, 1
  store i8 %13, ptr @uavcan_tx_log_message.transfer_id, align 1, !tbaa !9
  %14 = getelementptr inbounds %struct.uavcan_protocol_t, ptr %8, i32 0, i32 1
  %15 = load i8, ptr %14, align 1
  %16 = and i8 %12, 31
  %17 = and i8 %15, -32
  %18 = or i8 %17, %16
  store i8 %18, ptr %14, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = call ptr @load_dsdl_protocol(i32 noundef 14, i32 noundef 0, ptr noundef %8, i8 noundef zeroext 0)
  store ptr %19, ptr %9, align 8, !tbaa !10
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds %struct.uavcan_LogMessage_t, ptr %7, i32 0, i32 0
  store i8 %21, ptr %22, align 1, !tbaa !12
  %23 = getelementptr inbounds %struct.uavcan_LogMessage_t, ptr %7, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 @debug_log_source, i64 4, i1 false)
  %24 = load i8, ptr %5, align 1, !tbaa !9
  %25 = getelementptr inbounds %struct.uavcan_LogMessage_t, ptr %7, i32 0, i32 2
  %26 = getelementptr inbounds [2 x i8], ptr %25, i64 0, i64 0
  store i8 %24, ptr %26, align 1, !tbaa !9
  %27 = load i8, ptr %6, align 1, !tbaa !9
  %28 = getelementptr inbounds %struct.uavcan_LogMessage_t, ptr %7, i32 0, i32 2
  %29 = getelementptr inbounds [2 x i8], ptr %28, i64 0, i64 1
  store i8 %27, ptr %29, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %30 = getelementptr inbounds [8 x i8], ptr %10, i64 0, i64 0
  %31 = call i64 @uavcan_pack_LogMessage(ptr noundef %30, ptr noundef %7)
  store i64 %31, ptr %11, align 8, !tbaa !14
  %32 = getelementptr inbounds [8 x i8], ptr %10, i64 0, i64 0
  %33 = load i64, ptr %11, align 8, !tbaa !14
  %34 = load ptr, ptr %9, align 8, !tbaa !10
  %35 = getelementptr inbounds %struct.dsdl_t, ptr %34, i32 0, i32 4
  %36 = load i8, ptr %35, align 1
  %37 = and i8 %36, 3
  %38 = call i32 @uavcan_tx(ptr noundef %8, ptr noundef %32, i64 noundef %33, i8 noundef zeroext %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 5, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 7, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @uavcan_pack_LogMessage(ptr noundef, ptr 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"uavcan_LogMessage_t", !7, i64 0, !7, i64 1, !7, i64 5}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}


; 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"

%struct.uavcan_LogMessage_t = type { i8, [4 x i8], [2 x i8] }
%struct.uavcan_protocol_t = type <{ %union.anon, %union.anon.1 }>
%union.anon = type { %struct.can_id_t }
%struct.can_id_t = type { %union.anon.0 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { %struct.can_tail_t }
%struct.can_tail_t = type { %union.anon.2 }
%union.anon.2 = type { i8 }

@uavcan_tx_log_message.transfer_id = external hidden local_unnamed_addr global i8, align 1
@debug_log_source = external local_unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @load_dsdl_protocol(i32 noundef, i32 noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @uavcan_tx(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @uavcan_tx_log_message(i32 noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = alloca %struct.uavcan_LogMessage_t, align 1
  %5 = alloca %struct.uavcan_protocol_t, align 1
  %6 = alloca [8 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %5) #2
  %7 = load i8, ptr @uavcan_tx_log_message.transfer_id, align 1, !tbaa !5
  %8 = add i8 %7, 1
  store i8 %8, ptr @uavcan_tx_log_message.transfer_id, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 4
  %10 = and i8 %7, 31
  store i8 %10, ptr %9, align 1
  %11 = call ptr @load_dsdl_protocol(i32 noundef 14, i32 noundef 0, ptr noundef nonnull %5, i8 noundef zeroext 0)
  %12 = trunc i32 %0 to i8
  store i8 %12, ptr %4, align 1, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %4, i64 1
  %14 = load i32, ptr @debug_log_source, align 1
  store i32 %14, ptr %13, align 1
  %15 = getelementptr inbounds i8, ptr %4, i64 5
  store i8 %1, ptr %15, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %4, i64 6
  store i8 %2, ptr %16, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  %17 = call i64 @uavcan_pack_LogMessage(ptr noundef nonnull %6, ptr noundef nonnull %4)
  %18 = getelementptr inbounds i8, ptr %11, i64 9
  %19 = load i8, ptr %18, align 1
  %20 = and i8 %19, 3
  %21 = call i32 @uavcan_tx(ptr noundef nonnull %5, ptr noundef nonnull %6, i64 noundef %17, i8 noundef zeroext %20)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %4) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @uavcan_pack_LogMessage(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 0}
!9 = !{!"uavcan_LogMessage_t", !6, i64 0, !6, i64 1, !6, i64 5}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass