; LLVM IR from CerebusOSS/CereLink :: Central/Instrument.ll (ZN10Instrument4SendEPv)

; 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.cbPKT_GENERIC = type { %struct.cbPKT_HEADER, [252 x i32] }
%struct.cbPKT_HEADER = type { i64, i16, i16, i16, i8, i8 }
%class.Instrument = type <{ ptr, %class.UDPSocket, [6 x %"class.Instrument::CachedPacket"], i32, i32, i32, [4 x i8], ptr, ptr, i32, [4 x i8] }>
%class.UDPSocket = type <{ ptr, i32, %struct.sockaddr_in, i32, i32, i8, i8, [2 x i8] }>
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%"class.Instrument::CachedPacket" = type { i32, i32, i32, i32, i32, [2048 x i8], i32 }

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN10Instrument4SendEPv(ptr noundef nonnull align 8 dereferenceable(12516) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %13, i32 0, i32 3
  %15 = load i16, ptr %14, align 1, !tbaa !9
  %16 = zext i16 %15 to i64
  %17 = add i64 %16, 4
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %19 = load i32, ptr %6, align 4, !tbaa !14
  %20 = shl i32 %19, 2
  store i32 %20, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %21 = getelementptr inbounds %class.Instrument, ptr %11, i32 0, i32 2
  %22 = getelementptr inbounds [6 x %"class.Instrument::CachedPacket"], ptr %21, i64 0, i64 0
  %23 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %22, i64 6
  store ptr %23, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %24 = getelementptr inbounds %class.Instrument, ptr %11, i32 0, i32 2
  %25 = getelementptr inbounds [6 x %"class.Instrument::CachedPacket"], ptr %24, i64 0, i64 0
  store ptr %25, ptr %9, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %35, %2
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %27, %28
  br i1 %29, label %30, label %38

30:                                               ; preds = %26
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %31)
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  br label %38

34:                                               ; preds = %30
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %36, i32 1
  store ptr %37, ptr %9, align 8, !tbaa !5
  br label %26, !llvm.loop !16

38:                                               ; preds = %33, %26
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp eq ptr %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

43:                                               ; preds = %38
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !14
  %47 = call noundef zeroext i1 @_ZN10Instrument12CachedPacket9AddPacketEPvi(ptr noundef nonnull align 4 dereferenceable(2072) %44, ptr noundef %45, i32 noundef %46)
  %48 = getelementptr inbounds %class.Instrument, ptr %11, i32 0, i32 3
  %49 = load i32, ptr %48, align 8, !tbaa !18
  %50 = icmp eq i32 0, %49
  br i1 %50, label %51, label %56

51:                                               ; preds = %43
  %52 = getelementptr inbounds %class.Instrument, ptr %11, i32 0, i32 1
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !14
  %55 = call noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %52, ptr noundef %53, i32 noundef %54)
  store i32 %55, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

56:                                               ; preds = %43
  %57 = getelementptr inbounds %class.Instrument, ptr %11, i32 0, i32 1
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !14
  %60 = call noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %57, ptr noundef %58, i32 noundef %59)
  store i32 %60, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

61:                                               ; preds = %56, %51, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %62 = load i32, ptr %3, align 4
  ret i32 %62
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket9AddPacketEPvi(ptr noundef nonnull align 4 dereferenceable(2072), ptr noundef, i32 noundef) #2 align 2

declare noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38), ptr noundef, i32 noundef) #3

declare noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38), ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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 = { "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++ TBAA"}
!9 = !{!10, !13, i64 12}
!10 = !{!"_ZTS13cbPKT_GENERIC", !11, i64 0, !7, i64 16}
!11 = !{!"_ZTS12cbPKT_HEADER", !12, i64 0, !13, i64 8, !13, i64 10, !13, i64 12, !7, i64 14, !7, i64 15}
!12 = !{!"long", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !15, i64 12480}
!19 = !{!"_ZTS10Instrument", !20, i64 8, !7, i64 48, !15, i64 12480, !15, i64 12484, !15, i64 12488, !6, i64 12496, !6, i64 12504, !15, i64 12512}
!20 = !{!"_ZTS9UDPSocket", !15, i64 8, !21, i64 12, !23, i64 28, !15, i64 32, !24, i64 36, !24, i64 37}
!21 = !{!"_ZTS11sockaddr_in", !13, i64 0, !13, i64 2, !22, i64 4, !7, i64 8}
!22 = !{!"_ZTS7in_addr", !15, i64 0}
!23 = !{!"_ZTS15STARTUP_OPTIONS", !7, i64 0}
!24 = !{!"bool", !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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10Instrument4SendEPv(ptr noundef nonnull align 8 dereferenceable(12516) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 12
  %4 = load i16, ptr %3, align 1, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = shl nuw nsw i32 %5, 2
  %7 = add nuw nsw i32 %6, 16
  %.0.ptr19 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr19)
  br i1 %8, label %19, label %9

9:                                                ; preds = %2
  %.0.ptr = getelementptr inbounds i8, ptr %0, i64 2120
  %10 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr)
  br i1 %10, label %19, label %11

11:                                               ; preds = %9
  %.0.ptr.1 = getelementptr inbounds i8, ptr %0, i64 4192
  %12 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr.1)
  br i1 %12, label %19, label %13

13:                                               ; preds = %11
  %.0.ptr.2 = getelementptr inbounds i8, ptr %0, i64 6264
  %14 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr.2)
  br i1 %14, label %19, label %15

15:                                               ; preds = %13
  %.0.ptr.3 = getelementptr inbounds i8, ptr %0, i64 8336
  %16 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr.3)
  br i1 %16, label %19, label %17

17:                                               ; preds = %15
  %.0.ptr.4 = getelementptr inbounds i8, ptr %0, i64 10408
  %18 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr.4)
  br i1 %18, label %19, label %.loopexit

19:                                               ; preds = %17, %15, %13, %11, %9, %2
  %.0.ptr21.lcssa = phi ptr [ %.0.ptr19, %2 ], [ %.0.ptr, %9 ], [ %.0.ptr.1, %11 ], [ %.0.ptr.2, %13 ], [ %.0.ptr.3, %15 ], [ %.0.ptr.4, %17 ]
  %20 = tail call noundef zeroext i1 @_ZN10Instrument12CachedPacket9AddPacketEPvi(ptr noundef nonnull align 4 dereferenceable(2072) %.0.ptr21.lcssa, ptr noundef nonnull %1, i32 noundef %7)
  %21 = getelementptr inbounds i8, ptr %0, i64 12480
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = icmp eq i32 %22, 0
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %23, label %25, label %27

25:                                               ; preds = %19
  %26 = tail call noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %24, ptr noundef nonnull %1, i32 noundef %7)
  br label %.loopexit

27:                                               ; preds = %19
  %28 = tail call noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %24, ptr noundef nonnull %1, i32 noundef %7)
  br label %.loopexit

.loopexit:                                        ; preds = %17, %27, %25
  %.016 = phi i32 [ %26, %25 ], [ %28, %27 ], [ -1, %17 ]
  ret i32 %.016
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket8OkToSendEv(ptr noundef nonnull align 4 dereferenceable(2072)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket9AddPacketEPvi(ptr noundef nonnull align 4 dereferenceable(2072), ptr noundef, i32 noundef) local_unnamed_addr #1 align 2

declare noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38), ptr noundef, i32 noundef) local_unnamed_addr #2

declare noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38), ptr noundef, i32 noundef) local_unnamed_addr #2

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

!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 12}
!6 = !{!"_ZTS13cbPKT_GENERIC", !7, i64 0, !9, i64 16}
!7 = !{!"_ZTS12cbPKT_HEADER", !8, i64 0, !11, i64 8, !11, i64 10, !11, i64 12, !9, i64 14, !9, i64 15}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!13, !15, i64 12480}
!13 = !{!"_ZTS10Instrument", !14, i64 8, !9, i64 48, !15, i64 12480, !15, i64 12484, !15, i64 12488, !20, i64 12496, !20, i64 12504, !15, i64 12512}
!14 = !{!"_ZTS9UDPSocket", !15, i64 8, !16, i64 12, !18, i64 28, !15, i64 32, !19, i64 36, !19, i64 37}
!15 = !{!"int", !9, i64 0}
!16 = !{!"_ZTS11sockaddr_in", !11, i64 0, !11, i64 2, !17, i64 4, !9, i64 8}
!17 = !{!"_ZTS7in_addr", !15, i64 0}
!18 = !{!"_ZTS15STARTUP_OPTIONS", !9, i64 0}
!19 = !{!"bool", !9, i64 0}
!20 = !{!"any pointer", !9, i64 0}


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