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

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

%"class.Instrument::CachedPacket" = type { i32, i32, i32, i32, i32, [2048 x i8], i32 }
%struct.cbPKT_GENERIC = type { %struct.cbPKT_HEADER, [252 x i32] }
%struct.cbPKT_HEADER = type { i64, i16, i16, i16, i8, i8 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket4TickERK9UDPSocketi(ptr noundef nonnull align 4 dereferenceable(2072) %0, ptr noundef nonnull align 8 dereferenceable(38) %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %5, align 8
  %9 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %53

12:                                               ; preds = %3
  %13 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %13, align 4, !tbaa !14
  %16 = icmp sle i32 %15, 0
  br i1 %16, label %17, label %52

17:                                               ; preds = %12
  %18 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %18, align 4, !tbaa !15
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %50

22:                                               ; preds = %17
  %23 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 5
  %24 = getelementptr inbounds [2048 x i8], ptr %23, i64 0, i64 0
  %25 = getelementptr inbounds %struct.cbPKT_GENERIC, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.cbPKT_HEADER, ptr %25, i32 0, i32 2
  %27 = load i16, ptr %26, align 2, !tbaa !16
  %28 = zext i16 %27 to i32
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %28)
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp eq i32 0, %30
  br i1 %31, label %32, label %39

32:                                               ; preds = %22
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 5
  %35 = getelementptr inbounds [2048 x i8], ptr %34, i64 0, i64 0
  %36 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 6
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %38 = call noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %33, ptr noundef %35, i32 noundef %37)
  br label %46

39:                                               ; preds = %22
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 5
  %42 = getelementptr inbounds [2048 x i8], ptr %41, i64 0, i64 0
  %43 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 6
  %44 = load i32, ptr %43, align 4, !tbaa !21
  %45 = call noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %40, ptr noundef %42, i32 noundef %44)
  br label %46

46:                                               ; preds = %39, %32
  %47 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !22
  %49 = getelementptr inbounds %"class.Instrument::CachedPacket", ptr %8, i32 0, i32 1
  store i32 %48, ptr %49, align 4, !tbaa !14
  br label %51

50:                                               ; preds = %17
  store i1 true, ptr %4, align 1
  br label %54

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51, %12
  br label %53

53:                                               ; preds = %52, %3
  store i1 false, ptr %4, align 1
  br label %54

54:                                               ; preds = %53, %50
  %55 = load i1, ptr %4, align 1
  ret i1 %55
}

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

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

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN10Instrument12CachedPacketE", !13, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !10, i64 2068}
!13 = !{!"_ZTSN10Instrument8ModeTypeE", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!17, !20, i64 10}
!17 = !{!"_ZTS13cbPKT_GENERIC", !18, i64 0, !7, i64 16}
!18 = !{!"_ZTS12cbPKT_HEADER", !19, i64 0, !20, i64 8, !20, i64 10, !20, i64 12, !7, i64 14, !7, i64 15}
!19 = !{!"long", !7, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!12, !10, i64 2068}
!22 = !{!12, !10, i64 12}


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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10Instrument12CachedPacket4TickERK9UDPSocketi(ptr noundef nonnull align 4 dereferenceable(2072) %0, ptr noundef nonnull align 8 dereferenceable(38) %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %32

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr %7, align 4, !tbaa !11
  %10 = icmp slt i32 %8, 2
  br i1 %10, label %11, label %32

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %12, align 4, !tbaa !12
  %15 = icmp sgt i32 %13, 1
  br i1 %15, label %16, label %32

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = getelementptr inbounds i8, ptr %0, i64 30
  %19 = load i16, ptr %18, align 2, !tbaa !13
  %20 = zext i16 %19 to i32
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %20)
  %22 = icmp eq i32 %2, 0
  %23 = getelementptr inbounds i8, ptr %0, i64 2068
  %24 = load i32, ptr %23, align 4, !tbaa !18
  br i1 %22, label %25, label %27

25:                                               ; preds = %16
  %26 = tail call noundef i32 @_ZNK9UDPSocket7SendUDPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %1, ptr noundef nonnull %17, i32 noundef %24)
  br label %29

27:                                               ; preds = %16
  %28 = tail call noundef i32 @_ZNK9UDPSocket7SendTCPEPvi(ptr noundef nonnull align 8 dereferenceable(38) %1, ptr noundef nonnull %17, i32 noundef %24)
  br label %29

29:                                               ; preds = %27, %25
  %30 = getelementptr inbounds i8, ptr %0, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !19
  store i32 %31, ptr %7, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %3, %29, %6, %11
  %.0 = phi i1 [ true, %11 ], [ false, %6 ], [ false, %29 ], [ false, %3 ]
  ret i1 %.0
}

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

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

!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 = !{!"_ZTSN10Instrument12CachedPacketE", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !8, i64 20, !10, i64 2068}
!7 = !{!"_ZTSN10Instrument8ModeTypeE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !17, i64 10}
!14 = !{!"_ZTS13cbPKT_GENERIC", !15, i64 0, !8, i64 16}
!15 = !{!"_ZTS12cbPKT_HEADER", !16, i64 0, !17, i64 8, !17, i64 10, !17, i64 12, !8, i64 14, !8, i64 15}
!16 = !{!"long", !8, i64 0}
!17 = !{!"short", !8, i64 0}
!18 = !{!6, !10, i64 2068}
!19 = !{!6, !10, i64 12}


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