; 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.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }
%struct.us_internal_udp_packet_buffer = type { [1024 x %struct.mmsghdr], [1024 x %struct.iovec], [1024 x %struct.sockaddr_storage], [1024 x [256 x i8]] }
%struct.mmsghdr = type { %struct.msghdr, i32 }
%struct.iovec = type { ptr, i64 }
%struct.sockaddr_storage = type { i16, [118 x i8], i64 }

; 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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @bsd_create_udp_packet_buffer() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca %struct.msghdr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %4 = call noalias ptr @malloc(i64 noundef 67584000) #5
  store ptr %4, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %54, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 1024
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %57

9:                                                ; preds = %5
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %10, i64 1
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = mul nsw i32 %12, 65536
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %11, i64 %14
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1024 x %struct.iovec], ptr %17, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.iovec, ptr %20, i32 0, i32 0
  store ptr %15, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1024 x %struct.iovec], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.iovec, ptr %26, i32 0, i32 1
  store i64 65536, ptr %27, align 8, !tbaa !14
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %2, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1024 x %struct.mmsghdr], ptr %29, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.mmsghdr, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 0
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %35, i32 0, i32 2
  store ptr %36, ptr %34, align 8, !tbaa !15
  %37 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 1
  store i32 128, ptr %37, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 2
  %39 = load ptr, ptr %1, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1024 x %struct.iovec], ptr %40, i64 0, i64 %42
  store ptr %43, ptr %38, align 8, !tbaa !18
  %44 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 3
  store i64 1, ptr %44, align 8, !tbaa !19
  %45 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 4
  %46 = load ptr, ptr %1, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.us_internal_udp_packet_buffer, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %2, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1024 x [256 x i8]], ptr %47, i64 0, i64 %49
  %51 = getelementptr inbounds [256 x i8], ptr %50, i64 0, i64 0
  store ptr %51, ptr %45, align 8, !tbaa !20
  %52 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 5
  store i64 256, ptr %52, align 8, !tbaa !21
  %53 = getelementptr inbounds %struct.msghdr, ptr %3, i32 0, i32 6
  store i32 0, ptr %53, align 8, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %33, ptr align 8 %3, i64 56, i1 false), !tbaa.struct !23
  br label %54

54:                                               ; preds = %9
  %55 = load i32, ptr %2, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !25

57:                                               ; preds = %8
  %58 = load ptr, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret ptr %58
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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, !6, i64 0}
!12 = !{!"iovec", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"msghdr", !6, i64 0, !10, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !13, i64 40, !10, i64 48}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !6, i64 16}
!19 = !{!16, !13, i64 24}
!20 = !{!16, !6, i64 32}
!21 = !{!16, !13, i64 40}
!22 = !{!16, !10, i64 48}
!23 = !{i64 0, i64 8, !5, i64 8, i64 4, !9, i64 16, i64 8, !5, i64 24, i64 8, !24, i64 32, i64 8, !5, i64 40, i64 8, !24, i64 48, i64 4, !9}
!24 = !{!13, !13, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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.iovec = type { ptr, i64 }
%struct.mmsghdr = type { %struct.msghdr, i32 }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }

; Function Attrs: nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noundef ptr @bsd_create_udp_packet_buffer() local_unnamed_addr #0 {
  %1 = tail call noalias dereferenceable_or_null(67584000) ptr @malloc(i64 noundef 67584000) #2
  %2 = getelementptr inbounds i8, ptr %1, i64 475136
  %3 = getelementptr inbounds i8, ptr %1, i64 65536
  %4 = getelementptr inbounds i8, ptr %1, i64 81920
  %5 = getelementptr inbounds i8, ptr %1, i64 212992
  br label %7

6:                                                ; preds = %7
  ret ptr %1

7:                                                ; preds = %0, %7
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %7 ]
  %8 = shl nuw nsw i64 %indvars.iv, 16
  %9 = getelementptr inbounds i8, ptr %2, i64 %8
  %10 = getelementptr inbounds [1024 x %struct.iovec], ptr %3, i64 0, i64 %indvars.iv
  store ptr %9, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 65536, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds [1024 x %struct.mmsghdr], ptr %1, i64 0, i64 %indvars.iv
  %13 = getelementptr inbounds [1024 x [256 x i8]], ptr %5, i64 0, i64 %indvars.iv
  store ptr %4, ptr %12, align 8, !tbaa !12
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  store i32 128, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !13
  %.sroa.31.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %10, ptr %.sroa.31.0..sroa_idx, align 8, !tbaa !12
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 24
  store i64 1, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !15
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 32
  store ptr %13, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !12
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 40
  store i64 256, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !15
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 48
  store i32 0, ptr %.sroa.7.0..sroa_idx, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1024
  br i1 %exitcond.not, label %6, label %7, !llvm.loop !16
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

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


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