; 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.xjson_writer_ = type { %struct.xjson_format_, i8, i64, i64, i64, i64, i64, ptr, ptr, i8 }
%struct.xjson_format_ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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
declare dso_local void @XPacket_ParseHeader(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XPacket_UpdateHeader(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XPacket_Create(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @XPacket_Assemble(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.xjson_writer_, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @XPacket_UpdateHeader(ptr noundef %9)
  store i32 %10, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %61

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XPacket, ptr %15, i32 0, i32 0
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 168, ptr %7) #3
  %17 = call i32 @XJSON_InitWriter(ptr noundef %7, ptr noundef null, ptr noundef null, i64 noundef 256)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XPacket, ptr %18, i32 0, i32 1
  call void @XByteBuffer_Reset(ptr noundef %19)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XPacket, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = call i32 @XJSON_WriteObject(ptr noundef %22, ptr noundef %7)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %57

25:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XPacket, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.xjson_writer_, ptr %7, i32 0, i32 7
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds %struct.xjson_writer_, ptr %7, i32 0, i32 4
  %31 = load i64, ptr %30, align 8, !tbaa !20
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XPacket, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XPacketHeader, ptr %35, i32 0, i32 4
  %37 = load i32, ptr %36, align 4, !tbaa !22
  %38 = zext i32 %37 to i64
  %39 = call i32 @XPacket_Create(ptr noundef %27, ptr noundef %29, i64 noundef %31, ptr noundef %34, i64 noundef %38)
  store i32 %39, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %25
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %54

43:                                               ; preds = %25
  %44 = getelementptr inbounds %struct.xjson_writer_, ptr %7, i32 0, i32 4
  %45 = load i64, ptr %44, align 8, !tbaa !20
  %46 = trunc i64 %45 to i32
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XPacket, ptr %47, i32 0, i32 4
  store i32 %46, ptr %48, align 8, !tbaa !23
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XPacket, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XPacket, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  call void @XPacket_ParseHeader(ptr noundef %50, ptr noundef %53)
  store i32 0, ptr %5, align 4
  br label %54

54:                                               ; preds = %43, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %55 = load i32, ptr %5, align 4
  switch i32 %55, label %60 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %14
  call void @XJSON_DestroyWriter(ptr noundef %7)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.XPacket, ptr %58, i32 0, i32 1
  store ptr %59, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %60

60:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 168, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %61

61:                                               ; preds = %60, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %62 = load ptr, ptr %2, align 8
  ret ptr %62
}

declare i32 @XJSON_InitWriter(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #2

declare void @XByteBuffer_Reset(ptr noundef) #2

declare i32 @XJSON_WriteObject(ptr noundef, ptr noundef) #2

declare void @XJSON_DestroyWriter(ptr noundef) #2

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

!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 272}
!12 = !{!"XPacket", !13, i64 0, !14, i64 240, !6, i64 272, !6, i64 280, !10, i64 288, !10, i64 292, !7, i64 296, !6, i64 304, !6, i64 312}
!13 = !{!"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}
!14 = !{!"XByteBuffer", !6, i64 0, !15, i64 8, !15, i64 16, !16, i64 24, !16, i64 26, !10, i64 28}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!18, !6, i64 144}
!18 = !{!"xjson_writer_", !19, i64 0, !7, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !15, i64 128, !15, i64 136, !6, i64 144, !6, i64 152, !7, i64 160}
!19 = !{!"xjson_format_", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!20 = !{!18, !15, i64 120}
!21 = !{!12, !6, i64 304}
!22 = !{!13, !10, i64 16}
!23 = !{!12, !10, i64 288}


; 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.xjson_writer_ = type { %struct.xjson_format_, i8, i64, i64, i64, i64, i64, ptr, ptr, i8 }
%struct.xjson_format_ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @XPacket_ParseHeader(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XPacket_UpdateHeader(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XPacket_Create(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @XPacket_Assemble(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.xjson_writer_, align 8
  %3 = tail call i32 @XPacket_UpdateHeader(ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %28, label %4

4:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 168, ptr nonnull %2) #3
  %5 = call i32 @XJSON_InitWriter(ptr noundef nonnull %2, ptr noundef null, ptr noundef null, i64 noundef 256) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 240
  call void @XByteBuffer_Reset(ptr noundef nonnull %6) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 272
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = call i32 @XJSON_WriteObject(ptr noundef %8, ptr noundef nonnull %2) #3
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %27, label %10

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %2, i64 144
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %2, i64 120
  %14 = load i64, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %0, i64 304
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i32, ptr %17, align 4, !tbaa !20
  %19 = zext i32 %18 to i64
  %20 = call i32 @XPacket_Create(ptr noundef nonnull %6, ptr noundef %12, i64 noundef %14, ptr noundef %16, i64 noundef %19)
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %.critedge

22:                                               ; preds = %10
  %23 = load i64, ptr %13, align 8, !tbaa !18
  %24 = trunc i64 %23 to i32
  %25 = getelementptr inbounds i8, ptr %0, i64 288
  store i32 %24, ptr %25, align 8, !tbaa !21
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XPacket_ParseHeader(ptr noundef nonnull %0, ptr noundef %26)
  br label %27

27:                                               ; preds = %22, %4
  call void @XJSON_DestroyWriter(ptr noundef nonnull %2) #3
  br label %.critedge

.critedge:                                        ; preds = %10, %27
  %.1 = phi ptr [ %6, %27 ], [ null, %10 ]
  call void @llvm.lifetime.end.p0(i64 168, ptr nonnull %2) #3
  br label %28

28:                                               ; preds = %1, %.critedge
  %.2 = phi ptr [ %.1, %.critedge ], [ null, %1 ]
  ret ptr %.2
}

declare i32 @XJSON_InitWriter(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @XByteBuffer_Reset(ptr noundef) local_unnamed_addr #2

declare i32 @XJSON_WriteObject(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @XJSON_DestroyWriter(ptr noundef) local_unnamed_addr #2

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

!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, !12, i64 272}
!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 = !{!16, !12, i64 144}
!16 = !{!"xjson_writer_", !17, i64 0, !9, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136, !12, i64 144, !12, i64 152, !9, i64 160}
!17 = !{!"xjson_format_", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88}
!18 = !{!16, !13, i64 120}
!19 = !{!6, !12, i64 304}
!20 = !{!7, !8, i64 16}
!21 = !{!6, !8, i64 288}


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