; 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

declare ptr @XJSON_NewObject(ptr noundef, ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XPacket_Init(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XPacket, ptr %8, i32 0, i32 0
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 236, i1 false)
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XPacketHeader, ptr %11, i32 0, i32 0
  store i32 0, ptr %12, align 4, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.XPacketHeader, ptr %14, i32 0, i32 4
  store i32 %13, ptr %15, align 4, !tbaa !13
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XPacket, ptr %16, i32 0, i32 1
  %18 = call i32 @XByteBuffer_Init(ptr noundef %17, i64 noundef 0, i32 noundef 0)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XPacket, ptr %19, i32 0, i32 4
  store i32 0, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XPacket, ptr %21, i32 0, i32 5
  store i32 0, ptr %22, align 4, !tbaa !19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XPacket, ptr %23, i32 0, i32 6
  store i8 0, ptr %24, align 8, !tbaa !20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XPacket, ptr %26, i32 0, i32 7
  store ptr %25, ptr %27, align 8, !tbaa !21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XPacket, ptr %28, i32 0, i32 8
  store ptr null, ptr %29, align 8, !tbaa !22
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XPacket, ptr %30, i32 0, i32 3
  store ptr null, ptr %31, align 8, !tbaa !23
  %32 = call ptr @XJSON_NewObject(ptr noundef null, ptr noundef null, i8 noundef zeroext 1)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XPacket, ptr %33, i32 0, i32 2
  store ptr %32, ptr %34, align 8, !tbaa !24
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XPacket, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !24
  %38 = icmp eq ptr %37, null
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, i32 1, i32 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %40
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @XByteBuffer_Init(ptr noundef, i64 noundef, i32 noundef) #1

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


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

declare ptr @XJSON_NewObject(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @XPacket_Init(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(236) %0, i8 0, i64 236, i1 false)
  store i32 %2, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 240
  %6 = tail call i32 @XByteBuffer_Init(ptr noundef nonnull %5, i64 noundef 0, i32 noundef 0) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 288
  %8 = getelementptr inbounds i8, ptr %0, i64 304
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(9) %7, i8 0, i64 9, i1 false)
  store ptr %1, ptr %8, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %0, i64 312
  store ptr null, ptr %9, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %0, i64 280
  store ptr null, ptr %10, align 8, !tbaa !17
  %11 = tail call ptr @XJSON_NewObject(ptr noundef null, ptr noundef null, i8 noundef zeroext 1) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 272
  store ptr %11, ptr %12, align 8, !tbaa !18
  %13 = icmp eq ptr %11, null
  %14 = zext i1 %13 to i32
  ret i32 %14
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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


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