; LLVM IR from kala13x/libxutils :: tools (xtop)

; 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.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }
%struct.XNetIface = type { i64, i64, i64, i64, i16, i64, i64, i64, i64, i64, i32, i8, [256 x i8], [64 x i8], [64 x i8], [128 x [256 x i8]] }
%struct.XString = type { ptr, i64, i64, i16, i8, i8 }

@.str.175 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.176 = external hidden unnamed_addr constant [270 x i8], align 1
@.str.177 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.178 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.179 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.180 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 @XArray_GetData(ptr noundef, i64 noundef) #1

declare void @XArray_Destroy(ptr noundef) #1

declare i32 @XString_Append(ptr noundef, ptr noundef, ...) #1

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

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %15, ptr noundef @.str.175)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void @XArray_Destroy(ptr noundef %6)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %111

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = call i64 @XArray_Used(ptr noundef %6)
  store i64 %20, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %99, %19
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %25, label %102

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = call ptr @XArray_GetData(ptr noundef %6, i64 noundef %26)
  store ptr %27, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  store i32 4, ptr %7, align 4
  br label %96

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XNetIface, ptr %33, i32 0, i32 12
  %35 = getelementptr inbounds [256 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XNetIface, ptr %36, i32 0, i32 10
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XNetIface, ptr %39, i32 0, i32 14
  %41 = getelementptr inbounds [64 x i8], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XNetIface, ptr %42, i32 0, i32 13
  %44 = getelementptr inbounds [64 x i8], ptr %43, i64 0, i64 0
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XNetIface, ptr %45, i32 0, i32 9
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.XNetIface, ptr %48, i32 0, i32 8
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XNetIface, ptr %51, i32 0, i32 7
  %53 = load i64, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XNetIface, ptr %54, i32 0, i32 6
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.XNetIface, ptr %57, i32 0, i32 5
  %59 = load i64, ptr %58, align 8, !tbaa !19
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XNetIface, ptr %60, i32 0, i32 3
  %62 = load i64, ptr %61, align 8, !tbaa !20
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XNetIface, ptr %63, i32 0, i32 2
  %65 = load i64, ptr %64, align 8, !tbaa !21
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.XNetIface, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !22
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.XNetIface, ptr %69, i32 0, i32 0
  %71 = load i64, ptr %70, align 8, !tbaa !23
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.XNetIface, ptr %72, i32 0, i32 11
  %74 = load i8, ptr %73, align 4, !tbaa !24
  %75 = zext i8 %74 to i32
  %76 = icmp ne i32 %75, 0
  %77 = zext i1 %76 to i64
  %78 = select i1 %76, ptr @.str.177, ptr @.str.178
  %79 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %32, ptr noundef @.str.176, ptr noundef %35, i32 noundef %38, ptr noundef %41, ptr noundef %44, i64 noundef %47, i64 noundef %50, i64 noundef %53, i64 noundef %56, i64 noundef %59, i64 noundef %62, i64 noundef %65, i64 noundef %68, i64 noundef %71, ptr noundef %78)
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.XString, ptr %80, i32 0, i32 3
  %82 = load i16, ptr %81, align 8, !tbaa !25
  %83 = sext i16 %82 to i32
  %84 = icmp slt i32 %83, 0
  br i1 %84, label %94, label %85

85:                                               ; preds = %31
  %86 = load i64, ptr %8, align 8, !tbaa !9
  %87 = add i64 %86, 1
  %88 = load i64, ptr %9, align 8, !tbaa !9
  %89 = icmp ult i64 %87, %88
  br i1 %89, label %90, label %95

90:                                               ; preds = %85
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %91, ptr noundef @.str.179)
  %93 = icmp slt i32 %92, 0
  br i1 %93, label %94, label %95

94:                                               ; preds = %90, %31
  call void @XArray_Destroy(ptr noundef %6)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %96

95:                                               ; preds = %90, %85
  store i32 0, ptr %7, align 4
  br label %96

96:                                               ; preds = %95, %94, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %97 = load i32, ptr %7, align 4
  switch i32 %97, label %109 [
    i32 0, label %98
    i32 4, label %99
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98, %96
  %100 = load i64, ptr %8, align 8, !tbaa !9
  %101 = add i64 %100, 1
  store i64 %101, ptr %8, align 8, !tbaa !9
  br label %21, !llvm.loop !27

102:                                              ; preds = %21
  call void @XArray_Destroy(ptr noundef %6)
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %103, ptr noundef @.str.180)
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.XString, ptr %105, i32 0, i32 3
  %107 = load i16, ptr %106, align 8, !tbaa !25
  %108 = sext i16 %107 to i32
  store i32 %108, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %109

109:                                              ; preds = %102, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %111

110:                                              ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %111

111:                                              ; preds = %110, %109, %18
  call void @llvm.lifetime.end.p0(i64 56, ptr %6) #3
  %112 = load i32, ptr %3, align 4
  ret i32 %112
}

declare i32 @XMon_GetNetworkStats(ptr noundef, ptr noundef) #1

declare i64 @XArray_Used(ptr 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 80}
!12 = !{!"XNetIface", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !14, i64 80, !7, i64 84, !7, i64 85, !7, i64 341, !7, i64 405, !7, i64 469}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 72}
!16 = !{!12, !10, i64 64}
!17 = !{!12, !10, i64 56}
!18 = !{!12, !10, i64 48}
!19 = !{!12, !10, i64 40}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !10, i64 16}
!22 = !{!12, !10, i64 8}
!23 = !{!12, !10, i64 0}
!24 = !{!12, !7, i64 84}
!25 = !{!26, !13, i64 24}
!26 = !{!"XString", !6, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !7, i64 26, !7, i64 27}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; 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.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }

@.str.175 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.176 = external hidden unnamed_addr constant [270 x i8], align 1
@.str.177 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.178 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.179 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.180 = external hidden unnamed_addr constant [2 x i8], align 1

; 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

declare ptr @XArray_GetData(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @XArray_Destroy(ptr noundef) local_unnamed_addr #1

declare i32 @XString_Append(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XTOPApp_AppendNetworkJson(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.XArray_, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #3
  %4 = call i32 @XMon_GetNetworkStats(ptr noundef %0, ptr noundef nonnull %3) #3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %6, label %57

6:                                                ; preds = %2
  %7 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %1, ptr noundef nonnull @.str.175) #3
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  call void @XArray_Destroy(ptr noundef nonnull %3) #3
  br label %57

10:                                               ; preds = %6
  %11 = call i64 @XArray_Used(ptr noundef nonnull %3) #3
  %.not35 = icmp eq i64 %11, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  br label %13

13:                                               ; preds = %.lr.ph, %52
  %.03034 = phi i64 [ 0, %.lr.ph ], [ %.pre-phi, %52 ]
  %14 = call ptr @XArray_GetData(ptr noundef nonnull %3, i64 noundef %.03034) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %._crit_edge36, label %16

._crit_edge36:                                    ; preds = %13
  %.pre = add nuw i64 %.03034, 1
  br label %52

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %14, i64 85
  %18 = getelementptr inbounds i8, ptr %14, i64 80
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %14, i64 405
  %21 = getelementptr inbounds i8, ptr %14, i64 341
  %22 = getelementptr inbounds i8, ptr %14, i64 72
  %23 = load i64, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %14, i64 64
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %14, i64 56
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %14, i64 48
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %14, i64 40
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = getelementptr inbounds i8, ptr %14, i64 24
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %14, i64 16
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %14, i64 8
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = load i64, ptr %14, align 8, !tbaa !20
  %39 = getelementptr inbounds i8, ptr %14, i64 84
  %40 = load i8, ptr %39, align 4, !tbaa !21
  %.not = icmp eq i8 %40, 0
  %41 = select i1 %.not, ptr @.str.178, ptr @.str.177
  %42 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %1, ptr noundef nonnull @.str.176, ptr noundef nonnull %17, i32 noundef %19, ptr noundef nonnull %20, ptr noundef nonnull %21, i64 noundef %23, i64 noundef %25, i64 noundef %27, i64 noundef %29, i64 noundef %31, i64 noundef %33, i64 noundef %35, i64 noundef %37, i64 noundef %38, ptr noundef nonnull %41) #3
  %43 = load i16, ptr %12, align 8, !tbaa !22
  %44 = icmp slt i16 %43, 0
  br i1 %44, label %51, label %45

45:                                               ; preds = %16
  %46 = add nuw i64 %.03034, 1
  %47 = icmp ult i64 %46, %11
  br i1 %47, label %48, label %52

48:                                               ; preds = %45
  %49 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef nonnull %1, ptr noundef nonnull @.str.179) #3
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %16, %48
  call void @XArray_Destroy(ptr noundef nonnull %3) #3
  br label %57

52:                                               ; preds = %._crit_edge36, %48, %45
  %.pre-phi = phi i64 [ %.pre, %._crit_edge36 ], [ %46, %48 ], [ %46, %45 ]
  %exitcond.not = icmp eq i64 %.pre-phi, %11
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !25

._crit_edge:                                      ; preds = %52, %10
  call void @XArray_Destroy(ptr noundef nonnull %3) #3
  %53 = call i32 (ptr, ptr, ...) @XString_Append(ptr noundef %1, ptr noundef nonnull @.str.180) #3
  %54 = getelementptr inbounds i8, ptr %1, i64 24
  %55 = load i16, ptr %54, align 8, !tbaa !22
  %56 = sext i16 %55 to i32
  br label %57

57:                                               ; preds = %51, %2, %._crit_edge, %9
  %.3 = phi i32 [ -1, %9 ], [ -1, %51 ], [ %56, %._crit_edge ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #3
  ret i32 %.3
}

declare i32 @XMon_GetNetworkStats(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @XArray_Used(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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, !11, i64 80}
!6 = !{!"XNetIface", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !11, i64 80, !8, i64 84, !8, i64 85, !8, i64 341, !8, i64 405, !8, i64 469}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 72}
!13 = !{!6, !7, i64 64}
!14 = !{!6, !7, i64 56}
!15 = !{!6, !7, i64 48}
!16 = !{!6, !7, i64 40}
!17 = !{!6, !7, i64 24}
!18 = !{!6, !7, i64 16}
!19 = !{!6, !7, i64 8}
!20 = !{!6, !7, i64 0}
!21 = !{!6, !8, i64 84}
!22 = !{!23, !10, i64 24}
!23 = !{!"XString", !24, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !8, i64 26, !8, i64 27}
!24 = !{!"any pointer", !8, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass