; LLVM IR from DroneBridge/DroneBridge :: common (db_raw_send_receive)

; 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.db_raw_v2_header_t = type { [4 x i8], i8, i8, i8, [2 x i8], i8 }
%struct.data_uni = type { [2048 x i8] }
%struct.db_socket_t = type { i32, %struct.sockaddr_ll }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }

@db_raw_offset = external dso_local global i32, align 4
@monitor_framebuffer = external dso_local global [2071 x i8], align 16
@db_raw_header = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

declare void @syslog(i32 noundef, ptr noundef, ...) #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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_hp_raw_buffer(i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @db_send_div(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i16 noundef zeroext %3, i8 noundef zeroext %4, i32 noundef %5) #4 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i16, align 2
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i8 %2, ptr %10, align 1, !tbaa !9
  store i16 %3, ptr %11, align 2, !tbaa !10
  store i8 %4, ptr %12, align 1, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !12
  call void @check_payload_length(ptr noundef %11)
  %16 = load i16, ptr %11, align 2, !tbaa !10
  %17 = zext i16 %16 to i32
  %18 = and i32 %17, 255
  %19 = trunc i32 %18 to i8
  %20 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %20, i32 0, i32 4
  %22 = getelementptr inbounds [2 x i8], ptr %21, i64 0, i64 0
  store i8 %19, ptr %22, align 1, !tbaa !9
  %23 = load i16, ptr %11, align 2, !tbaa !10
  %24 = zext i16 %23 to i32
  %25 = ashr i32 %24, 8
  %26 = and i32 %25, 255
  %27 = trunc i32 %26 to i8
  %28 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %28, i32 0, i32 4
  %30 = getelementptr inbounds [2 x i8], ptr %29, i64 0, i64 1
  store i8 %27, ptr %30, align 1, !tbaa !9
  %31 = load i8, ptr %10, align 1, !tbaa !9
  %32 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %32, i32 0, i32 3
  store i8 %31, ptr %33, align 1, !tbaa !14
  %34 = load i8, ptr %12, align 1, !tbaa !9
  %35 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %35, i32 0, i32 5
  store i8 %34, ptr %36, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %37 = load i32, ptr %13, align 4, !tbaa !12
  %38 = call ptr @get_hp_raw_buffer(i32 noundef %37)
  store ptr %38, ptr %14, align 8, !tbaa !5
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.data_uni, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [2048 x i8], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i16, ptr %11, align 2, !tbaa !10
  %44 = zext i16 %43 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %42, i64 %44, i1 false)
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.db_socket_t, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !17
  %48 = load i16, ptr %11, align 2, !tbaa !10
  %49 = zext i16 %48 to i32
  %50 = add nsw i32 23, %49
  %51 = load i32, ptr @db_raw_offset, align 4, !tbaa !12
  %52 = add nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.db_socket_t, ptr %54, i32 0, i32 1
  %56 = call i64 @sendto(i32 noundef %47, ptr noundef @monitor_framebuffer, i64 noundef %53, i32 noundef 0, ptr noundef %55, i32 noundef 20)
  %57 = icmp sle i64 %56, 0
  br i1 %57, label %58, label %70

58:                                               ; preds = %6
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call ptr @__errno_location() #8
  %62 = load i32, ptr %61, align 4, !tbaa !12
  %63 = call ptr @strerror(i32 noundef %62) #7
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.9, ptr noundef %63) #7
  %65 = call ptr @__errno_location() #8
  %66 = load i32, ptr %65, align 4, !tbaa !12
  %67 = call ptr @strerror(i32 noundef %66) #7
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef @.str.9, ptr noundef %67)
  br label %68

68:                                               ; preds = %59
  br label %69

69:                                               ; preds = %68
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %71

70:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %71

71:                                               ; preds = %70, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  %72 = load i32, ptr %7, align 4
  ret i32 %72
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @check_payload_length(ptr noundef) #5

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #0

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #6

attributes #0 = { nounwind "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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { inlinehint 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 #6 = { nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !7, i64 6}
!15 = !{!"db_raw_v2_header_t", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 9}
!16 = !{!15, !7, i64 9}
!17 = !{!18, !13, i64 0}
!18 = !{!"", !13, i64 0, !19, i64 4}
!19 = !{!"sockaddr_ll", !11, i64 0, !11, i64 2, !13, i64 4, !11, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}


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

@db_raw_offset = external dso_local local_unnamed_addr global i32, align 4
@monitor_framebuffer = external dso_local global [2071 x i8], align 16
@db_raw_header = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare void @syslog(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress 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
declare dso_local ptr @get_hp_raw_buffer(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @db_send_div(ptr noundef %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2, i16 noundef zeroext %3, i8 noundef zeroext %4, i32 noundef %5) local_unnamed_addr #3 {
  %7 = alloca i16, align 2
  store i16 %3, ptr %7, align 2, !tbaa !5
  call void @check_payload_length(ptr noundef nonnull %7)
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %9 = trunc i16 %8 to i8
  %10 = load ptr, ptr @db_raw_header, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 7
  store i8 %9, ptr %11, align 1, !tbaa !11
  %12 = lshr i16 %8, 8
  %13 = trunc nuw i16 %12 to i8
  %14 = load ptr, ptr @db_raw_header, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store i8 %13, ptr %15, align 1, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %14, i64 6
  store i8 %2, ptr %16, align 1, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %14, i64 9
  store i8 %4, ptr %17, align 1, !tbaa !14
  %18 = call ptr @get_hp_raw_buffer(i32 noundef %5)
  %19 = load i16, ptr %7, align 2, !tbaa !5
  %20 = zext i16 %19 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %1, i64 %20, i1 false)
  %21 = load i32, ptr %0, align 4, !tbaa !15
  %22 = load i16, ptr %7, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = add nuw nsw i32 %23, 23
  %25 = load i32, ptr @db_raw_offset, align 4, !tbaa !19
  %26 = add nsw i32 %24, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %0, i64 4
  %29 = call i64 @sendto(i32 noundef %21, ptr noundef nonnull @monitor_framebuffer, i64 noundef %27, i32 noundef 0, ptr noundef nonnull %28, i32 noundef 20) #7
  %30 = icmp slt i64 %29, 1
  br i1 %30, label %31, label %39

31:                                               ; preds = %6
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = tail call ptr @__errno_location() #8
  %34 = load i32, ptr %33, align 4, !tbaa !19
  %35 = call ptr @strerror(i32 noundef %34) #7
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.9, ptr noundef %35) #9
  %37 = load i32, ptr %33, align 4, !tbaa !19
  %38 = call ptr @strerror(i32 noundef %37) #7
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str.9, ptr noundef %38) #7
  br label %39

39:                                               ; preds = %6, %31
  %.0 = phi i32 [ -1, %31 ], [ 0, %6 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @check_payload_length(ptr noundef) local_unnamed_addr #4

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #6

attributes #0 = { nofree nounwind "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 #1 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint 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 #5 = { nounwind "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 #6 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { cold 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 6}
!13 = !{!"db_raw_v2_header_t", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 9}
!14 = !{!13, !7, i64 9}
!15 = !{!16, !17, i64 0}
!16 = !{!"", !17, i64 0, !18, i64 4}
!17 = !{!"int", !7, i64 0}
!18 = !{!"sockaddr_ll", !6, i64 0, !6, i64 2, !17, i64 4, !6, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!19 = !{!17, !17, i64 0}


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