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

; 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
declare dso_local i32 @XWindow_AddLine(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XWindow_AddEmptyLine(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [2048 x i8], align 16
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i32 @XWindow_UpdateSize(ptr noundef %8)
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %41

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xcli_wind_, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.xcli_size_, ptr %14, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %16, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 2048, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %17 = load i64, ptr %4, align 8, !tbaa !15
  %18 = icmp ult i64 %17, 2047
  br i1 %18, label %19, label %21

19:                                               ; preds = %12
  %20 = load i64, ptr %4, align 8, !tbaa !15
  br label %22

21:                                               ; preds = %12
  br label %22

22:                                               ; preds = %21, %19
  %23 = phi i64 [ %20, %19 ], [ 2047, %21 ]
  store i64 %23, ptr %7, align 8, !tbaa !15
  store i64 0, ptr %6, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %31, %22
  %25 = load i64, ptr %6, align 8, !tbaa !15
  %26 = load i64, ptr %7, align 8, !tbaa !15
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %24
  %29 = load i64, ptr %6, align 8, !tbaa !15
  %30 = getelementptr inbounds [2048 x i8], ptr %5, i64 0, i64 %29
  store i8 32, ptr %30, align 1, !tbaa !16
  br label %31

31:                                               ; preds = %28
  %32 = load i64, ptr %6, align 8, !tbaa !15
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !15
  br label %24, !llvm.loop !17

34:                                               ; preds = %24
  %35 = load i64, ptr %6, align 8, !tbaa !15
  %36 = getelementptr inbounds [2048 x i8], ptr %5, i64 0, i64 %35
  store i8 0, ptr %36, align 1, !tbaa !16
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds [2048 x i8], ptr %5, i64 0, i64 0
  %39 = load i64, ptr %6, align 8, !tbaa !15
  %40 = call i32 @XWindow_AddLine(ptr noundef %37, ptr noundef %38, i64 noundef %39)
  store i32 %40, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2048, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %41

41:                                               ; preds = %34, %11
  %42 = load i32, ptr %2, align 4
  ret i32 %42
}

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 = { 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 8}
!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 = !{!13, !13, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; 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
declare dso_local i32 @XWindow_AddLine(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XWindow_AddEmptyLine(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [2048 x i8], align 16
  %3 = tail call i32 @XWindow_UpdateSize(ptr noundef %0)
  %4 = icmp eq i32 %3, -1
  br i1 %4, label %11, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %2) #4
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %8 = tail call i64 @llvm.umin.i64(i64 %7, i64 2047)
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %2, i8 32, i64 %8, i1 false), !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %5
  %.011.lcssa = phi i64 [ 0, %5 ], [ %8, %.lr.ph.preheader ]
  %9 = getelementptr inbounds [2048 x i8], ptr %2, i64 0, i64 %.011.lcssa
  store i8 0, ptr %9, align 1, !tbaa !14
  %10 = call i32 @XWindow_AddLine(ptr noundef nonnull %0, ptr noundef nonnull %2, i64 noundef %.011.lcssa)
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %2) #4
  br label %11

11:                                               ; preds = %1, %._crit_edge
  %.0 = phi i32 [ %10, %._crit_edge ], [ -1, %1 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 8}
!6 = !{!"xcli_wind_", !7, i64 0, !10, i64 8, !12, i64 24, !8, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"xcli_size_", !11, i64 0, !11, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!"XArray_", !13, i64 0, !13, i64 8, !7, i64 16, !13, i64 24, !8, i64 32, !8, i64 33, !8, i64 34, !11, i64 40, !11, i64 48}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass