; LLVM IR from uNetworking/uSockets :: src (bsd)

; 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.mmsghdr = type { %struct.msghdr, i32 }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }
%struct.cmsghdr = type { i64, i32, i32, [0 x i8] }

@.str.5 = external hidden unnamed_addr constant [16 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare ptr @__cmsg_nxthdr(ptr noundef, ptr noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @bsd_udp_packet_buffer_ecn(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds %struct.mmsghdr, ptr %11, i64 %13
  %15 = getelementptr inbounds %struct.mmsghdr, ptr %14, i32 0, i32 0
  store ptr %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.msghdr, ptr %16, i32 0, i32 5
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp uge i64 %18, 16
  br i1 %19, label %20, label %24

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.msghdr, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  br label %25

24:                                               ; preds = %2
  br label %25

25:                                               ; preds = %24, %20
  %26 = phi ptr [ %23, %20 ], [ null, %24 ]
  store ptr %26, ptr %7, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %70, %25
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 2, ptr %8, align 4
  br label %74

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cmsghdr, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %31
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cmsghdr, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %49

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.cmsghdr, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds [0 x i8], ptr %43, i64 0, i64 0
  %45 = load i8, ptr %44, align 8, !tbaa !15
  store i8 %45, ptr %9, align 1, !tbaa !15
  %46 = load i8, ptr %9, align 1, !tbaa !15
  %47 = zext i8 %46 to i32
  %48 = and i32 %47, 3
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  br label %74

49:                                               ; preds = %36
  br label %50

50:                                               ; preds = %49, %31
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.cmsghdr, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = icmp eq i32 %53, 41
  br i1 %54, label %55, label %69

55:                                               ; preds = %50
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.cmsghdr, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = icmp eq i32 %58, 67
  br i1 %59, label %60, label %68

60:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.cmsghdr, ptr %61, i32 0, i32 3
  %63 = getelementptr inbounds [0 x i8], ptr %62, i64 0, i64 0
  %64 = load i8, ptr %63, align 8, !tbaa !15
  store i8 %64, ptr %10, align 1, !tbaa !15
  %65 = load i8, ptr %10, align 1, !tbaa !15
  %66 = zext i8 %65 to i32
  %67 = and i32 %66, 3
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  br label %74

68:                                               ; preds = %55
  br label %69

69:                                               ; preds = %68, %50
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = call ptr @__cmsg_nxthdr(ptr noundef %71, ptr noundef %72) #4
  store ptr %73, ptr %7, align 8, !tbaa !5
  br label %27, !llvm.loop !16

74:                                               ; preds = %60, %41, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %75 = load i32, ptr %8, align 4
  switch i32 %75, label %78 [
    i32 2, label %76
  ]

76:                                               ; preds = %74
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

78:                                               ; preds = %76, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 40}
!12 = !{!"msghdr", !6, i64 0, !10, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !13, i64 40, !10, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.mmsghdr = type { %struct.msghdr, i32 }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }

@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare ptr @__cmsg_nxthdr(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @bsd_udp_packet_buffer_ecn(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds %struct.mmsghdr, ptr %0, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %6, 15
  br i1 %7, label %8, label %._crit_edge

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %4, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %.not22 = icmp eq ptr %10, null
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.thread
  %.01623 = phi ptr [ %29, %.thread ], [ %10, %8 ]
  %11 = getelementptr inbounds i8, ptr %.01623, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  switch i32 %12, label %.thread [
    i32 0, label %13
    i32 41, label %21
  ]

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.01623, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %.01623, i64 16
  %19 = load i8, ptr %18, align 8, !tbaa !14
  %20 = and i8 %19, 3
  br label %.thread18

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %.01623, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp eq i32 %23, 67
  br i1 %24, label %25, label %.thread

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %.01623, i64 16
  %27 = load i8, ptr %26, align 8, !tbaa !14
  %28 = and i8 %27, 3
  br label %.thread18

.thread:                                          ; preds = %.lr.ph, %13, %21
  %29 = tail call ptr @__cmsg_nxthdr(ptr noundef %4, ptr noundef nonnull %.01623) #3
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.thread, %2, %8
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %.thread18

.thread18:                                        ; preds = %17, %25, %._crit_edge
  %.1.shrunk = phi i8 [ 0, %._crit_edge ], [ %28, %25 ], [ %20, %17 ]
  %.1 = zext nneg i8 %.1.shrunk to i32
  ret i32 %.1
}

attributes #0 = { 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 #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 = { 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 }

!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, !11, i64 40}
!6 = !{!"msghdr", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !11, i64 40, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 32}
!13 = !{!10, !10, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass