; LLVM IR from DroneBridge/DroneBridge :: video (video_main_air)

; 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.timespec = type { i64, i64 }
%struct.db_socket_t = type { i32, %struct.sockaddr_ll }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }
%struct.data_uni = type { [2048 x i8] }
%struct.db_video_packet_t = type { %struct.video_packet_header_t, %struct.video_packet_data_t }
%struct.video_packet_header_t = type { i32 }
%struct.video_packet_data_t = type <{ i32, ptr }>
%struct.db_uav_status_t = type <{ i32, i8, i8, i32, i32, i32, i32, i32, i16, i16, i8, i8, i32, [8 x %struct.db_adapter_status] }>
%struct.db_adapter_status = type <{ i32, i32, i8, [4 x i8], i8, i8, i8, i8, [16 x i8] }>

@db_vid_seqnum = external dso_local global i8, align 1
@num_interfaces = external dso_local global i32, align 4
@vid_adhere_80211 = external dso_local global i32, align 4
@db_uav_status = external dso_local global ptr, align 8
@start_time = external dso_local global %struct.timespec, align 8
@raw_sockets = external dso_local global [4 x %struct.db_socket_t], align 16
@end_time = external dso_local global %struct.timespec, align 8

; 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 void @transmit_packet(i32 noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %10 = load i32, ptr @vid_adhere_80211, align 4, !tbaa !5
  %11 = call ptr @get_hp_raw_buffer(i32 noundef %10)
  store ptr %11, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %12 = load ptr, ptr %7, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.data_uni, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds [2048 x i8], ptr %13, i64 0, i64 0
  store ptr %14, ptr %8, align 8, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.db_video_packet_t, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.video_packet_header_t, ptr %17, i32 0, i32 0
  store i32 %15, ptr %18, align 1, !tbaa !11
  %19 = load ptr, ptr @db_uav_status, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.db_uav_status_t, ptr %19, i32 0, i32 7
  %21 = load i32, ptr %20, align 1, !tbaa !15
  %22 = add i32 %21, 1
  store i32 %22, ptr %20, align 1, !tbaa !15
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.db_video_packet_t, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 %25, i64 %27, i1 false)
  %28 = call i32 @clock_gettime(i32 noundef 1, ptr noundef @start_time) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %44, %3
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr @num_interfaces, align 4, !tbaa !5
  %32 = icmp ult i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %47

34:                                               ; preds = %29
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [4 x %struct.db_socket_t], ptr @raw_sockets, i64 0, i64 %36
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = zext i32 %38 to i64
  %40 = add i64 4, %39
  %41 = trunc i64 %40 to i16
  %42 = call zeroext i8 @update_seq_num(ptr noundef @db_vid_seqnum)
  %43 = call i32 @db_send_hp_div(ptr noundef %37, i8 noundef zeroext 3, i16 noundef zeroext %41, i8 noundef zeroext %42)
  br label %44

44:                                               ; preds = %34
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !5
  br label %29, !llvm.loop !18

47:                                               ; preds = %33
  %48 = call i32 @clock_gettime(i32 noundef 1, ptr noundef @end_time) #6
  %49 = call i32 @TimeSpecToUSeconds(ptr noundef @end_time)
  %50 = call i32 @TimeSpecToUSeconds(ptr noundef @start_time)
  %51 = sub nsw i32 %49, %50
  %52 = load ptr, ptr @db_uav_status, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.db_uav_status_t, ptr %52, i32 0, i32 6
  store i32 %51, ptr %53, align 1, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret void
}

declare ptr @get_hp_raw_buffer(i32 noundef) #2

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

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #4

declare i32 @db_send_hp_div(ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) #2

declare zeroext i8 @update_seq_num(ptr noundef) #2

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

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !13, i64 0, !14, i64 4}
!13 = !{!"", !6, i64 0}
!14 = !{!"", !6, i64 0, !10, i64 4}
!15 = !{!16, !6, i64 22}
!16 = !{!"", !6, i64 0, !7, i64 4, !7, i64 5, !6, i64 6, !6, i64 10, !6, i64 14, !6, i64 18, !6, i64 22, !17, i64 26, !17, i64 28, !7, i64 30, !7, i64 31, !6, i64 32, !7, i64 36}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!16, !6, i64 18}


; 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.timespec = type { i64, i64 }
%struct.db_socket_t = type { i32, %struct.sockaddr_ll }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }

@db_vid_seqnum = external dso_local global i8, align 1
@num_interfaces = external dso_local local_unnamed_addr global i32, align 4
@vid_adhere_80211 = external dso_local local_unnamed_addr global i32, align 4
@db_uav_status = external dso_local local_unnamed_addr global ptr, align 8
@start_time = external dso_local global %struct.timespec, align 8
@raw_sockets = external dso_local global [4 x %struct.db_socket_t], align 16
@end_time = external dso_local global %struct.timespec, align 8

; Function Attrs: nounwind uwtable
define dso_local void @transmit_packet(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @vid_adhere_80211, align 4, !tbaa !5
  %5 = tail call ptr @get_hp_raw_buffer(i32 noundef %4) #5
  store i32 %0, ptr %5, align 1, !tbaa !9
  %6 = load ptr, ptr @db_uav_status, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %6, i64 22
  %8 = load i32, ptr %7, align 1, !tbaa !15
  %9 = add i32 %8, 1
  store i32 %9, ptr %7, align 1, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %5, i64 4
  %11 = zext i32 %2 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %10, ptr align 1 %1, i64 %11, i1 false)
  %12 = tail call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull @start_time) #5
  %13 = load i32, ptr @num_interfaces, align 4, !tbaa !5
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %14 = trunc i32 %2 to i16
  %15 = add i16 %14, 4
  br label %22

._crit_edge:                                      ; preds = %22, %3
  %16 = tail call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull @end_time) #5
  %17 = tail call i32 @TimeSpecToUSeconds(ptr noundef nonnull @end_time)
  %18 = tail call i32 @TimeSpecToUSeconds(ptr noundef nonnull @start_time)
  %19 = sub nsw i32 %17, %18
  %20 = load ptr, ptr @db_uav_status, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %20, i64 18
  store i32 %19, ptr %21, align 1, !tbaa !18
  ret void

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %23 = getelementptr inbounds [4 x %struct.db_socket_t], ptr @raw_sockets, i64 0, i64 %indvars.iv
  %24 = tail call zeroext i8 @update_seq_num(ptr noundef nonnull @db_vid_seqnum) #5
  %25 = tail call i32 @db_send_hp_div(ptr noundef nonnull %23, i8 noundef zeroext 3, i16 noundef zeroext %15, i8 noundef zeroext %24) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @num_interfaces, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = icmp ult i64 %indvars.iv.next, %27
  br i1 %28, label %22, label %._crit_edge, !llvm.loop !19
}

declare ptr @get_hp_raw_buffer(i32 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
declare i32 @clock_gettime(i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @db_send_hp_div(ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

declare zeroext i8 @update_seq_num(ptr noundef) local_unnamed_addr #1

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

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

!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 = !{!10, !6, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 4}
!11 = !{!"", !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 4}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !6, i64 22}
!16 = !{!"", !6, i64 0, !7, i64 4, !7, i64 5, !6, i64 6, !6, i64 10, !6, i64 14, !6, i64 18, !6, i64 22, !17, i64 26, !17, i64 28, !7, i64 30, !7, i64 31, !6, i64 32, !7, i64 36}
!17 = !{!"short", !7, i64 0}
!18 = !{!16, !6, i64 18}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass