; LLVM IR from kala13x/libxutils :: src/net (mdtp)

; 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.XPacket = type { %struct.XPacketHeader, %struct.XByteBuffer, ptr, ptr, i32, i32, i8, ptr, ptr }
%struct.XPacketHeader = type { i32, i32, i32, i32, i32, i32, i8, [128 x i8], [8 x i8], [64 x i8], [8 x i8] }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, 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: nounwind uwtable
define dso_local ptr @XPacket_GetPayload(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %15, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.XPacket, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.XPacketHeader, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %9, %1
  store ptr null, ptr %2, align 8
  br label %44

16:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XPacket, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = add i32 4, %19
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %4, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %22 = load i64, ptr %4, align 8, !tbaa !17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XPacket, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.XPacketHeader, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = add i64 %22, %27
  store i64 %28, ptr %5, align 8, !tbaa !17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XPacket, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.XByteBuffer, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !18
  %33 = load i64, ptr %5, align 8, !tbaa !17
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %16
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %43

36:                                               ; preds = %16
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XPacket, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.XByteBuffer, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = load i64, ptr %4, align 8, !tbaa !17
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store ptr %42, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %43

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

44:                                               ; preds = %43, %15
  %45 = load ptr, ptr %2, align 8
  ret ptr %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !12, i64 16}
!10 = !{!"XPacket", !11, i64 0, !13, i64 240, !6, i64 272, !6, i64 280, !12, i64 288, !12, i64 292, !7, i64 296, !6, i64 304, !6, i64 312}
!11 = !{!"XPacketHeader", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 153, !7, i64 161, !7, i64 225}
!12 = !{!"int", !7, i64 0}
!13 = !{!"XByteBuffer", !6, i64 0, !14, i64 8, !14, i64 16, !15, i64 24, !15, i64 26, !12, i64 28}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!10, !12, i64 288}
!17 = !{!14, !14, i64 0}
!18 = !{!10, !14, i64 256}
!19 = !{!10, !6, i64 240}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local ptr @XPacket_GetPayload(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %20, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %20, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 288
  %8 = load i32, ptr %7, align 8, !tbaa !15
  %9 = add i32 %8, 4
  %10 = zext i32 %9 to i64
  %11 = zext i32 %5 to i64
  %12 = add nuw nsw i64 %10, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 256
  %14 = load i64, ptr %13, align 8, !tbaa !16
  %15 = icmp ult i64 %14, %12
  br i1 %15, label %20, label %16

16:                                               ; preds = %6
  %17 = getelementptr inbounds i8, ptr %0, i64 240
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %18, i64 %10
  br label %20

20:                                               ; preds = %16, %6, %1, %3
  %.1 = phi ptr [ null, %3 ], [ null, %1 ], [ %19, %16 ], [ null, %6 ]
  ret ptr %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !8, i64 16}
!6 = !{!"XPacket", !7, i64 0, !11, i64 240, !12, i64 272, !12, i64 280, !8, i64 288, !8, i64 292, !9, i64 296, !12, i64 304, !12, i64 312}
!7 = !{!"XPacketHeader", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !8, i64 20, !9, i64 24, !9, i64 25, !9, i64 153, !9, i64 161, !9, i64 225}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"XByteBuffer", !12, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 26, !8, i64 28}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!"short", !9, i64 0}
!15 = !{!6, !8, i64 288}
!16 = !{!6, !13, i64 256}
!17 = !{!6, !12, i64 240}


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