; 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.ifreq = type { %union.anon, %union.anon.0 }
%union.anon = type { [16 x i8] }
%union.anon.0 = type { %struct.ifmap }
%struct.ifmap = type { i64, i64, i16, i8, i8, i8 }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }
%struct.radiotap_header = type { [13 x i8] }
%struct.db_raw_v2_header_t = type { [4 x i8], i8, i8, i8, [2 x i8], i8 }

@radiotap_header_pre = external dso_local global [13 x i8], align 1
@frame_control_pre_rts = external dso_local constant [4 x i8], align 1
@frame_control_pre_data = external dso_local constant [4 x i8], align 1
@frame_control_pre_beacon = external dso_local constant [4 x i8], align 1
@monitor_framebuffer = external dso_local global [2071 x i8], align 16
@rth = external dso_local global ptr, align 8
@db_raw_header = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@interfaceName = external dso_local global [16 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [95 x i8], align 1
@raw_if_idx = external dso_local global %struct.ifreq, align 8
@socket_address = external dso_local global %struct.sockaddr_ll, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @set_bitrate(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @conf_monitor(i32 noundef %0, i8 noundef zeroext %1, i32 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4, i8 noundef zeroext %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i8 %1, ptr %9, align 1, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i8 %3, ptr %11, align 1, !tbaa !9
  store i8 %4, ptr %12, align 1, !tbaa !9
  store i8 %5, ptr %13, align 1, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @monitor_framebuffer, i8 0, i64 2071, i1 false)
  %15 = load ptr, ptr @rth, align 8, !tbaa !10
  %16 = getelementptr inbounds %struct.radiotap_header, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [13 x i8], ptr %16, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 1 @radiotap_header_pre, i64 13, i1 false)
  %18 = load i32, ptr %10, align 4, !tbaa !5
  call void @set_bitrate(i32 noundef %18)
  %19 = load i8, ptr %13, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  switch i32 %20, label %34 [
    i32 1, label %21
    i32 3, label %25
    i32 2, label %33
  ]

21:                                               ; preds = %6
  %22 = load ptr, ptr @db_raw_header, align 8, !tbaa !10
  %23 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds [4 x i8], ptr %23, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 @frame_control_pre_rts, i64 4, i1 false)
  br label %38

25:                                               ; preds = %6
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr @stderr, align 8, !tbaa !10
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.1) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 5, ptr noundef @.str.1)
  br label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr @db_raw_header, align 8, !tbaa !10
  %31 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [4 x i8], ptr %31, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 @frame_control_pre_beacon, i64 4, i1 false)
  br label %38

33:                                               ; preds = %6
  br label %34

34:                                               ; preds = %33, %6
  %35 = load ptr, ptr @db_raw_header, align 8, !tbaa !10
  %36 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [4 x i8], ptr %36, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %37, ptr align 1 @frame_control_pre_data, i64 4, i1 false)
  br label %38

38:                                               ; preds = %34, %29, %21
  %39 = load i8, ptr %11, align 1, !tbaa !9
  %40 = load ptr, ptr @db_raw_header, align 8, !tbaa !10
  %41 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %40, i32 0, i32 1
  store i8 %39, ptr %41, align 1, !tbaa !12
  %42 = load i8, ptr %9, align 1, !tbaa !9
  %43 = load ptr, ptr @db_raw_header, align 8, !tbaa !10
  %44 = getelementptr inbounds %struct.db_raw_v2_header_t, ptr %43, i32 0, i32 2
  store i8 %42, ptr %44, align 1, !tbaa !14
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = call i32 @setsockopt(i32 noundef %45, i32 noundef 1, i32 noundef 25, ptr noundef @interfaceName, i32 noundef 16) #6
  %47 = icmp slt i32 %46, 0
  br i1 %47, label %48, label %55

48:                                               ; preds = %38
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr @stderr, align 8, !tbaa !10
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.2) #6
  call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef @.str.2)
  br label %52

52:                                               ; preds = %49
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = call i32 @close(i32 noundef %53)
  store i32 -1, ptr %7, align 4
  br label %70

55:                                               ; preds = %38
  %56 = load i32, ptr getelementptr inbounds (%struct.ifreq, ptr @raw_if_idx, i32 0, i32 1), align 8, !tbaa !9
  store i32 %56, ptr getelementptr inbounds (%struct.sockaddr_ll, ptr @socket_address, i32 0, i32 2), align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #6
  %57 = load i8, ptr %11, align 1, !tbaa !9
  %58 = zext i8 %57 to i32
  %59 = icmp eq i32 %58, 1
  %60 = zext i1 %59 to i64
  %61 = select i1 %59, i32 3, i32 1
  %62 = trunc i32 %61 to i8
  store i8 %62, ptr %14, align 1, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i8, ptr %9, align 1, !tbaa !9
  %65 = load i8, ptr %14, align 1, !tbaa !9
  %66 = load i8, ptr %12, align 1, !tbaa !9
  %67 = call i32 @setBPF(i32 noundef %63, i8 noundef zeroext %64, i8 noundef zeroext %65, i8 noundef zeroext %66)
  store i32 %67, ptr %8, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  call void @clear_socket_buffer(i32 noundef %68)
  %69 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %69, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #6
  br label %70

70:                                               ; preds = %55, %52
  %71 = load i32, ptr %7, align 4
  ret i32 %71
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind
declare i32 @setsockopt(i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #1

declare i32 @close(i32 noundef) #2

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

declare i32 @setBPF(i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #2

declare void @clear_socket_buffer(i32 noundef) #2

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

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 = { 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 #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: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !7, i64 4}
!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 5}
!15 = !{!16, !6, i64 4}
!16 = !{!"sockaddr_ll", !17, i64 0, !17, i64 2, !6, i64 4, !17, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!17 = !{!"short", !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.ifreq = type { %union.anon, %union.anon.0 }
%union.anon = type { [16 x i8] }
%union.anon.0 = type { %struct.ifmap }
%struct.ifmap = type { i64, i64, i16, i8, i8, i8 }
%struct.sockaddr_ll = type { i16, i16, i32, i16, i8, i8, [8 x i8] }

@radiotap_header_pre = external dso_local local_unnamed_addr global [13 x i8], align 1
@frame_control_pre_rts = external dso_local local_unnamed_addr constant [4 x i8], align 1
@frame_control_pre_data = external dso_local local_unnamed_addr constant [4 x i8], align 1
@frame_control_pre_beacon = external dso_local local_unnamed_addr constant [4 x i8], align 1
@monitor_framebuffer = external dso_local local_unnamed_addr global [2071 x i8], align 16
@rth = external dso_local local_unnamed_addr global ptr, align 8
@db_raw_header = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@interfaceName = external dso_local global [16 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [95 x i8], align 1
@raw_if_idx = external dso_local local_unnamed_addr global %struct.ifreq, align 8
@socket_address = external dso_local local_unnamed_addr global %struct.sockaddr_ll, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @set_bitrate(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @conf_monitor(i32 noundef %0, i8 noundef zeroext %1, i32 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4, i8 noundef zeroext %5) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2071) @monitor_framebuffer, i8 0, i64 2071, i1 false)
  %7 = load ptr, ptr @rth, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(13) %7, ptr noundef nonnull align 1 dereferenceable(13) @radiotap_header_pre, i64 13, i1 false)
  tail call void @set_bitrate(i32 noundef %2)
  switch i8 %5, label %11 [
    i8 1, label %12
    i8 3, label %8
  ]

8:                                                ; preds = %6
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1) #6
  tail call void (i32, ptr, ...) @syslog(i32 noundef 5, ptr noundef nonnull @.str.1) #7
  br label %12

11:                                               ; preds = %6
  br label %12

12:                                               ; preds = %6, %11, %8
  %frame_control_pre_data.sink = phi ptr [ @frame_control_pre_data, %11 ], [ @frame_control_pre_beacon, %8 ], [ @frame_control_pre_rts, %6 ]
  %13 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %14 = load i32, ptr %frame_control_pre_data.sink, align 1
  store i32 %14, ptr %13, align 1
  %15 = load ptr, ptr @db_raw_header, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  store i8 %3, ptr %16, align 1, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %15, i64 5
  store i8 %1, ptr %17, align 1, !tbaa !11
  %18 = tail call i32 @setsockopt(i32 noundef %0, i32 noundef 1, i32 noundef 25, ptr noundef nonnull @interfaceName, i32 noundef 16) #7
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %12
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.2) #6
  tail call void (i32, ptr, ...) @syslog(i32 noundef 3, ptr noundef nonnull @.str.2) #7
  %23 = tail call i32 @close(i32 noundef %0) #7
  br label %29

24:                                               ; preds = %12
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @raw_if_idx, i64 16), align 8, !tbaa !12
  store i32 %25, ptr getelementptr inbounds (i8, ptr @socket_address, i64 4), align 4, !tbaa !13
  %26 = icmp eq i8 %3, 1
  %27 = select i1 %26, i8 3, i8 1
  %28 = tail call i32 @setBPF(i32 noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %27, i8 noundef zeroext %4) #7
  tail call void @clear_socket_buffer(i32 noundef %28) #7
  br label %29

29:                                               ; preds = %24, %20
  %.0 = phi i32 [ -1, %20 ], [ %28, %24 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

declare i32 @close(i32 noundef) local_unnamed_addr #2

declare i32 @setBPF(i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

declare void @clear_socket_buffer(i32 noundef) local_unnamed_addr #2

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 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { cold nounwind }
attributes #7 = { 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, !7, i64 4}
!10 = !{!"db_raw_v2_header_t", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 9}
!11 = !{!10, !7, i64 5}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !16, i64 4}
!14 = !{!"sockaddr_ll", !15, i64 0, !15, i64 2, !16, i64 4, !15, i64 8, !7, i64 10, !7, i64 11, !7, i64 12}
!15 = !{!"short", !7, i64 0}
!16 = !{!"int", !7, i64 0}


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