; LLVM IR from kala13x/libxutils :: src/data (str)

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrarglen(ptr noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrnfill(ptr noundef, i64 noundef, i64 noundef, i8 noundef signext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @xstrnul(ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @xstrnlcpyf(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef signext %3, ptr noundef %4, ...) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca [1 x %struct.__va_list_tag], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %5
  store i64 0, ptr %6, align 8
  br label %81

21:                                               ; preds = %17
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp ugt i64 %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = sub i64 %26, 1
  store i64 %27, ptr %9, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %25, %21
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  call void @xstrnul(ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  %30 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %30)
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  %33 = call i64 @xstrarglen(ptr noundef %31, ptr noundef %32)
  store i64 %33, ptr %12, align 8, !tbaa !9
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %28
  %37 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %37)
  %38 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %38, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %80

39:                                               ; preds = %28
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = icmp uge i64 %40, %41
  br i1 %42, label %43, label %52

43:                                               ; preds = %39
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %12, align 8, !tbaa !9
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  %48 = call i32 @xstrncpyarg(ptr noundef %44, i64 noundef %45, ptr noundef %46, ptr noundef %47)
  %49 = sext i32 %48 to i64
  store i64 %49, ptr %12, align 8, !tbaa !9
  %50 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %50)
  %51 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %51, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %80

52:                                               ; preds = %39
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 0
  store i8 0, ptr %55, align 1, !tbaa !11
  %56 = load i64, ptr %12, align 8, !tbaa !9
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = sub i64 %57, %56
  store i64 %58, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %12, align 8, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !9
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = load i8, ptr %10, align 1, !tbaa !11
  %63 = call i64 @xstrnfill(ptr noundef %59, i64 noundef %60, i64 noundef %61, i8 noundef signext %62)
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = add i64 %64, %63
  store i64 %65, ptr %12, align 8, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = load i64, ptr %12, align 8, !tbaa !9
  %71 = sub i64 %69, %70
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  %74 = call i32 @xstrncpyarg(ptr noundef %68, i64 noundef %71, ptr noundef %72, ptr noundef %73)
  %75 = sext i32 %74 to i64
  store i64 %75, ptr %12, align 8, !tbaa !9
  %76 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %13, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %76)
  %77 = load i64, ptr %12, align 8, !tbaa !9
  %78 = load i64, ptr %9, align 8, !tbaa !9
  %79 = add i64 %77, %78
  store i64 %79, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %80

80:                                               ; preds = %53, %43, %36
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %81

81:                                               ; preds = %80, %20
  %82 = load i64, ptr %6, align 8
  ret i64 %82
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
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 = !{!7, !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrarglen(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @xstrnfill(ptr noundef, i64 noundef, i64 noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @xstrnul(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @xstrnlcpyf(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef signext %3, ptr noundef %4, ...) local_unnamed_addr #0 {
  %6 = alloca [1 x %struct.__va_list_tag], align 16
  %7 = icmp ne ptr %0, null
  %8 = icmp ne i64 %1, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %9, label %27

9:                                                ; preds = %5
  %10 = icmp ugt i64 %2, %1
  %11 = add i64 %1, -1
  %spec.select = select i1 %10, i64 %11, i64 %2
  tail call void @xstrnul(ptr noundef nonnull %0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #3
  call void @llvm.va_start.p0(ptr nonnull %6)
  %12 = call i64 @xstrarglen(ptr noundef %4, ptr noundef nonnull %6)
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %13, label %14

13:                                               ; preds = %9
  call void @llvm.va_end.p0(ptr nonnull %6)
  br label %26

14:                                               ; preds = %9
  %.not36 = icmp ult i64 %12, %spec.select
  br i1 %.not36, label %18, label %15

15:                                               ; preds = %14
  %16 = call i32 @xstrncpyarg(ptr noundef nonnull %0, i64 noundef %12, ptr noundef %4, ptr noundef nonnull %6)
  %17 = sext i32 %16 to i64
  call void @llvm.va_end.p0(ptr nonnull %6)
  br label %26

18:                                               ; preds = %14
  store i8 0, ptr %0, align 1, !tbaa !5
  %19 = sub i64 %spec.select, %12
  %20 = call i64 @xstrnfill(ptr noundef nonnull %0, i64 noundef %1, i64 noundef %19, i8 noundef signext %3)
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = sub i64 %1, %20
  %23 = call i32 @xstrncpyarg(ptr noundef nonnull %21, i64 noundef %22, ptr noundef %4, ptr noundef nonnull %6)
  %24 = sext i32 %23 to i64
  call void @llvm.va_end.p0(ptr nonnull %6)
  %25 = add i64 %19, %24
  br label %26

26:                                               ; preds = %18, %15, %13
  %.0 = phi i64 [ %17, %15 ], [ %25, %18 ], [ 0, %13 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #3
  br label %27

27:                                               ; preds = %5, %26
  %.1 = phi i64 [ %.0, %26 ], [ 0, %5 ]
  ret i64 %.1
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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