; 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.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: inlinehint nounwind uwtable
declare hidden void @check_payload_length(ptr noundef) #2

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() #3

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

44:                                               ; preds = %4
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call ptr @__errno_location() #5
  %48 = load i32, ptr %47, align 4, !tbaa !19
  %49 = call ptr @strerror(i32 noundef %48) #6
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.9, ptr noundef %49) #6
  %51 = call ptr @__errno_location() #5
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = call ptr @strerror(i32 noundef %52) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef @.str.9, ptr noundef %53)
  br label %54

54:                                               ; preds = %45
  store i32 -1, ptr %5, align 4
  br label %56

55:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %56

56:                                               ; preds = %55, %54
  %57 = load i32, ptr %5, align 4
  ret i32 %57
}

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 = { 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 #3 = { 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 #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 = { nounwind willreturn memory(none) }
attributes #6 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !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", !11, i64 0, !11, i64 2, !17, i64 4, !11, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!19 = !{!17, !17, 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"

@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: inlinehint nounwind uwtable
declare hidden void @check_payload_length(ptr noundef) local_unnamed_addr #2

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 #3

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

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

25:                                               ; preds = %4
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = tail call ptr @__errno_location() #7
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %29 = call ptr @strerror(i32 noundef %28) #6
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.9, ptr noundef %29) #8
  %31 = load i32, ptr %27, align 4, !tbaa !19
  %32 = call ptr @strerror(i32 noundef %31) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str.9, ptr noundef %32) #6
  br label %33

33:                                               ; preds = %4, %25
  %.0 = phi i32 [ -1, %25 ], [ 0, %4 ]
  ret i32 %.0
}

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 = { 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 #3 = { 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 #4 = { 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 #5 = { 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 }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { 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,SROAPass,SimplifyCFGPass,TailCallElimPass