; 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.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%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 }

; 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 void @XArray_Clear(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XWindow_AddEmptyLine(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @XWindow_RenderLine(ptr noundef, ptr noundef, ptr noundef) #2

declare void @XByteBuffer_Clear(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XWindow_GetFrame(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %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 i32, align 4
  %12 = alloca %struct.XByteBuffer, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %18, label %15

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

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

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @XByteBuffer_Init(ptr noundef %20, i64 noundef 0, i32 noundef 0)
  br label %22

22:                                               ; preds = %37, %19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.xcli_wind_, ptr %23, i32 0, i32 2
  %25 = getelementptr inbounds %struct.XArray_, ptr %24, i32 0, i32 8
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xcli_wind_, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.xcli_size_, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = icmp ult i64 %26, %30
  br i1 %31, label %32, label %38

32:                                               ; preds = %22
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call i32 @XWindow_AddEmptyLine(ptr noundef %33)
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i32 -1, ptr %3, align 4
  br label %97

37:                                               ; preds = %32
  br label %22, !llvm.loop !16

38:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xcli_wind_, ptr %39, i32 0, i32 1
  store ptr %40, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.xcli_wind_, ptr %41, i32 0, i32 2
  store ptr %42, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.xcli_size_, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.XArray_, ptr %46, i32 0, i32 8
  %48 = load i64, ptr %47, align 8, !tbaa !19
  %49 = icmp ult i64 %45, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %38
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.xcli_size_, ptr %51, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !18
  br label %58

54:                                               ; preds = %38
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XArray_, ptr %55, i32 0, i32 8
  %57 = load i64, ptr %56, align 8, !tbaa !19
  br label %58

58:                                               ; preds = %54, %50
  %59 = phi i64 [ %53, %50 ], [ %57, %54 ]
  store i64 %59, ptr %9, align 8, !tbaa !20
  store i64 0, ptr %8, align 8, !tbaa !20
  br label %60

60:                                               ; preds = %92, %58
  %61 = load i64, ptr %8, align 8, !tbaa !20
  %62 = load i64, ptr %9, align 8, !tbaa !20
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %95

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i64, ptr %8, align 8, !tbaa !20
  %67 = call ptr @XArray_Get(ptr noundef %65, i64 noundef %66)
  store ptr %67, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  store i32 6, ptr %11, align 4
  br label %89

71:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #3
  %72 = call i32 @XByteBuffer_Init(ptr noundef %12, i64 noundef 0, i32 noundef 0)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = call i32 @XWindow_RenderLine(ptr noundef %73, ptr noundef %12, ptr noundef %74)
  %76 = icmp slt i32 %75, 0
  br i1 %76, label %77, label %80

77:                                               ; preds = %71
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  call void @XByteBuffer_Clear(ptr noundef %78)
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XArray_Clear(ptr noundef %79)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %88

80:                                               ; preds = %71
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = call i32 @XByteBuffer_AddBuff(ptr noundef %81, ptr noundef %12)
  %83 = icmp slt i32 %82, 0
  br i1 %83, label %84, label %87

84:                                               ; preds = %80
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  call void @XByteBuffer_Clear(ptr noundef %85)
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XArray_Clear(ptr noundef %86)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %88

87:                                               ; preds = %80
  store i32 0, ptr %11, align 4
  br label %88

88:                                               ; preds = %87, %84, %77
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #3
  br label %89

89:                                               ; preds = %88, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %90 = load i32, ptr %11, align 4
  switch i32 %90, label %96 [
    i32 0, label %91
    i32 6, label %92
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91, %89
  %93 = load i64, ptr %8, align 8, !tbaa !20
  %94 = add i64 %93, 1
  store i64 %94, ptr %8, align 8, !tbaa !20
  br label %60, !llvm.loop !21

95:                                               ; preds = %60
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %96

96:                                               ; preds = %95, %89
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %97

97:                                               ; preds = %96, %36, %18
  %98 = load i32, ptr %3, align 4
  ret i32 %98
}

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

declare ptr @XArray_Get(ptr noundef, i64 noundef) #1

declare i32 @XByteBuffer_AddBuff(ptr noundef, 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, !13, i64 72}
!10 = !{!"xcli_wind_", !11, i64 0, !12, i64 8, !14, i64 24, !7, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"xcli_size_", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!"XArray_", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !7, i64 32, !7, i64 33, !7, i64 34, !13, i64 40, !13, i64 48}
!15 = !{!10, !13, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !13, i64 8}
!19 = !{!14, !13, i64 48}
!20 = !{!13, !13, i64 0}
!21 = distinct !{!21, !17}


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

; 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 void @XArray_Clear(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @XWindow_RenderLine(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @XByteBuffer_Clear(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @XWindow_GetFrame(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.XByteBuffer, align 8
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = tail call i32 @XByteBuffer_Init(ptr noundef nonnull %1, i64 noundef 0, i32 noundef 0) #3
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  br label %10

10:                                               ; preds = %15, %6
  %11 = load i64, ptr %8, align 8, !tbaa !5
  %12 = load i64, ptr %9, align 8, !tbaa !12
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %15, label %.preheader

.preheader:                                       ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

15:                                               ; preds = %10
  %16 = tail call i32 @XWindow_AddEmptyLine(ptr noundef nonnull %0)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %.loopexit, label %10, !llvm.loop !14

.lr.ph:                                           ; preds = %.preheader, %.thread
  %.02942 = phi i64 [ %28, %.thread ], [ 0, %.preheader ]
  %18 = call ptr @XArray_Get(ptr noundef nonnull %14, i64 noundef %.02942) #3
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.thread, label %20

20:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %21 = call i32 @XByteBuffer_Init(ptr noundef nonnull %3, i64 noundef 0, i32 noundef 0) #3
  %22 = call i32 @XWindow_RenderLine(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %18)
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %.thread36, label %24

24:                                               ; preds = %20
  %25 = call i32 @XByteBuffer_AddBuff(ptr noundef %1, ptr noundef nonnull %3) #3
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %.thread36, label %27

.thread36:                                        ; preds = %24, %20
  call void @XByteBuffer_Clear(ptr noundef %1) #3
  call void @XArray_Clear(ptr noundef nonnull %14) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  br label %.loopexit

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %27
  %28 = add nuw i64 %.02942, 1
  %exitcond.not = icmp eq i64 %28, %12
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %15, %.thread, %.preheader, %.thread36, %2
  %.4 = phi i32 [ -1, %2 ], [ -1, %.thread36 ], [ 1, %.preheader ], [ 1, %.thread ], [ -1, %15 ]
  ret i32 %.4
}

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

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

declare i32 @XByteBuffer_AddBuff(ptr noundef, 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 48}
!6 = !{!"XArray_", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !11, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"xcli_size_", !11, i64 0, !11, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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