; LLVM IR from kala13x/libxutils :: src/sys (cli)

; 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.xcli_wind_ = type { i32, %struct.xcli_size_, %struct.XArray_, i8 }
%struct.xcli_size_ = type { i64, i64 }
%struct.XArray_ = type { ptr, ptr, i32, ptr, i8, i8, i8, i64, i64 }
%struct.XArrayData = type { ptr, ptr, i64, i32 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @XWindow_RenderLine(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 @XWindow_UpdateSize(ptr noundef %15)
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %106

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.xcli_wind_, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.xcli_size_, ptr %21, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !11
  store i64 %23, ptr %9, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XArrayData, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XArrayData, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !18
  %31 = call i32 @XByteBuffer_SetData(ptr noundef %24, ptr noundef %27, i64 noundef %30)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XArrayData, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !18
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XByteBuffer, ptr %35, i32 0, i32 1
  store i64 %34, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XArrayData, ptr %37, i32 0, i32 2
  store i64 0, ptr %38, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.XByteBuffer, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !22
  store ptr %41, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.XByteBuffer, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !23
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = call i64 @xstrextra(ptr noundef %42, i64 noundef %45, i64 noundef %46, ptr noundef %8, ptr noundef null)
  store i64 %47, ptr %11, align 8, !tbaa !9
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = icmp ult i64 %48, %49
  br i1 %50, label %51, label %80

51:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = sub i64 %52, %53
  store i64 %54, ptr %13, align 8, !tbaa !9
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = call i32 @XByteBuffer_Reserve(ptr noundef %55, i64 noundef %56)
  %58 = icmp sle i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %51
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XByteBuffer_Clear(ptr noundef %60)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %77

61:                                               ; preds = %51
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %73, %61
  %63 = load i64, ptr %12, align 8, !tbaa !9
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = icmp ult i64 %63, %64
  br i1 %65, label %66, label %76

66:                                               ; preds = %62
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call i32 @XByteBuffer_AddByte(ptr noundef %67, i8 noundef zeroext 32)
  %69 = icmp sle i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %66
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XByteBuffer_Clear(ptr noundef %71)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %77

72:                                               ; preds = %66
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %12, align 8, !tbaa !9
  br label %62, !llvm.loop !24

76:                                               ; preds = %62
  store i32 0, ptr %14, align 4
  br label %77

77:                                               ; preds = %76, %70, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %78 = load i32, ptr %14, align 4
  switch i32 %78, label %105 [
    i32 0, label %79
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %19
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load i64, ptr %9, align 8, !tbaa !9
  %83 = load i64, ptr %11, align 8, !tbaa !9
  %84 = add i64 %82, %83
  %85 = add i64 %84, 1
  %86 = call i32 @XByteBuffer_Resize(ptr noundef %81, i64 noundef %85)
  %87 = icmp sle i32 %86, 0
  br i1 %87, label %92, label %88

88:                                               ; preds = %80
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = call i32 (ptr, ptr, ...) @XByteBuffer_AddFmt(ptr noundef %89, ptr noundef @.str, ptr noundef @.str.3)
  %91 = icmp sle i32 %90, 0
  br i1 %91, label %92, label %94

92:                                               ; preds = %88, %80
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  call void @XByteBuffer_Clear(ptr noundef %93)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %105

94:                                               ; preds = %88
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.XByteBuffer, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !22
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.XArrayData, ptr %98, i32 0, i32 1
  store ptr %97, ptr %99, align 8, !tbaa !16
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.XByteBuffer, ptr %100, i32 0, i32 1
  %102 = load i64, ptr %101, align 8, !tbaa !19
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.XArrayData, ptr %103, i32 0, i32 2
  store i64 %102, ptr %104, align 8, !tbaa !18
  store i32 1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %105

105:                                              ; preds = %94, %92, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %106

106:                                              ; preds = %105, %18
  %107 = load i32, ptr %4, align 4
  ret i32 %107
}

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

declare i64 @xstrextra(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

declare void @XByteBuffer_Clear(ptr noundef) #2

declare i32 @XByteBuffer_AddByte(ptr noundef, i8 noundef zeroext) #2

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

declare i32 @XByteBuffer_AddFmt(ptr noundef, 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"xcli_wind_", !13, i64 0, !14, i64 8, !15, i64 24, !7, i64 80}
!13 = !{!"int", !7, i64 0}
!14 = !{!"xcli_size_", !10, i64 0, !10, i64 8}
!15 = !{!"XArray_", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !10, i64 40, !10, i64 48}
!16 = !{!17, !6, i64 8}
!17 = !{!"XArrayData", !6, i64 0, !6, i64 8, !10, i64 16, !13, i64 24}
!18 = !{!17, !10, i64 16}
!19 = !{!20, !10, i64 8}
!20 = !{!"XByteBuffer", !6, i64 0, !10, i64 8, !10, i64 16, !21, i64 24, !21, i64 26, !13, i64 28}
!21 = !{!"short", !7, i64 0}
!22 = !{!20, !6, i64 0}
!23 = !{!20, !10, i64 16}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @XWindow_RenderLine(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #1 {
  %4 = alloca i64, align 8
  %5 = tail call i32 @XWindow_UpdateSize(ptr noundef %0)
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %44, label %7

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !17
  %14 = tail call i32 @XByteBuffer_SetData(ptr noundef %1, ptr noundef %11, i64 noundef %13) #3
  %15 = load i64, ptr %12, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %15, ptr %16, align 8, !tbaa !18
  store i64 0, ptr %12, align 8, !tbaa !17
  %17 = load ptr, ptr %1, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !22
  %20 = call i64 @xstrextra(ptr noundef %17, i64 noundef %19, i64 noundef %9, ptr noundef nonnull %4, ptr noundef null) #3
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp ult i64 %21, %9
  br i1 %22, label %23, label %.loopexit

23:                                               ; preds = %7
  %24 = sub i64 %9, %21
  %25 = call i32 @XByteBuffer_Reserve(ptr noundef nonnull %1, i64 noundef %24) #3
  %26 = icmp slt i32 %25, 1
  br i1 %26, label %27, label %.lr.ph

27:                                               ; preds = %23
  call void @XByteBuffer_Clear(ptr noundef nonnull %1) #3
  br label %.critedge

28:                                               ; preds = %.lr.ph
  %29 = add nuw i64 %.03336, 1
  %exitcond.not = icmp eq i64 %29, %24
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !23

.lr.ph:                                           ; preds = %23, %28
  %.03336 = phi i64 [ %29, %28 ], [ 0, %23 ]
  %30 = call i32 @XByteBuffer_AddByte(ptr noundef nonnull %1, i8 noundef zeroext 32) #3
  %31 = icmp slt i32 %30, 1
  br i1 %31, label %32, label %28

32:                                               ; preds = %.lr.ph
  call void @XByteBuffer_Clear(ptr noundef nonnull %1) #3
  br label %.critedge

.loopexit:                                        ; preds = %28, %7
  %33 = add i64 %9, 1
  %34 = add i64 %33, %20
  %35 = call i32 @XByteBuffer_Resize(ptr noundef nonnull %1, i64 noundef %34) #3
  %36 = icmp slt i32 %35, 1
  br i1 %36, label %40, label %37

37:                                               ; preds = %.loopexit
  %38 = call i32 (ptr, ptr, ...) @XByteBuffer_AddFmt(ptr noundef nonnull %1, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3) #3
  %39 = icmp slt i32 %38, 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %37, %.loopexit
  call void @XByteBuffer_Clear(ptr noundef nonnull %1) #3
  br label %.critedge

41:                                               ; preds = %37
  %42 = load ptr, ptr %1, align 8, !tbaa !21
  store ptr %42, ptr %10, align 8, !tbaa !15
  %43 = load i64, ptr %16, align 8, !tbaa !18
  store i64 %43, ptr %12, align 8, !tbaa !17
  br label %.critedge

.critedge:                                        ; preds = %27, %32, %41, %40
  %.1 = phi i32 [ -1, %40 ], [ 1, %41 ], [ -1, %32 ], [ -1, %27 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %44

44:                                               ; preds = %3, %.critedge
  %.2 = phi i32 [ %.1, %.critedge ], [ -1, %3 ]
  ret i32 %.2
}

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

declare i64 @xstrextra(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @XByteBuffer_Clear(ptr noundef) local_unnamed_addr #2

declare i32 @XByteBuffer_AddByte(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

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

declare i32 @XByteBuffer_AddFmt(ptr noundef, 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"xcli_wind_", !11, i64 0, !12, i64 8, !13, i64 24, !7, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"xcli_size_", !6, i64 0, !6, i64 8}
!13 = !{!"XArray_", !14, i64 0, !14, i64 8, !11, i64 16, !14, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !6, i64 40, !6, i64 48}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !14, i64 8}
!16 = !{!"XArrayData", !14, i64 0, !14, i64 8, !6, i64 16, !11, i64 24}
!17 = !{!16, !6, i64 16}
!18 = !{!19, !6, i64 8}
!19 = !{!"XByteBuffer", !14, i64 0, !6, i64 8, !6, i64 16, !20, i64 24, !20, i64 26, !11, i64 28}
!20 = !{!"short", !7, i64 0}
!21 = !{!19, !14, i64 0}
!22 = !{!19, !6, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass