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

; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @xstrpcpyargs(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = call i64 @xstrarglen(ptr noundef %13, ptr noundef %14)
  store i64 %15, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %47

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = add i64 %21, 1
  store i64 %22, ptr %10, align 8, !tbaa !9
  %23 = call ptr @xalloc(ptr noundef %20, i64 noundef %22)
  store ptr %23, ptr %12, align 8, !tbaa !5
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %46

27:                                               ; preds = %19
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call i32 @xstrncpyarg(ptr noundef %28, i64 noundef %29, ptr noundef %30, ptr noundef %31)
  %33 = sext i32 %32 to i64
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %33, ptr %34, align 8, !tbaa !9
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = icmp ule i64 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %27
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  call void @xfree(ptr noundef %42, ptr noundef %43)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %46

44:                                               ; preds = %38, %27
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %45, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %46

46:                                               ; preds = %44, %41, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %47

47:                                               ; preds = %46, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %48 = load ptr, ptr %5, align 8
  ret ptr %48
}

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

declare void @xfree(ptr noundef, ptr noundef) #2

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 = { "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}


; 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: nounwind uwtable
declare dso_local i64 @xstrarglen(ptr noundef, 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: nounwind uwtable
define dso_local ptr @xstrpcpyargs(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call i64 @xstrarglen(ptr noundef %1, ptr noundef %2)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %15, label %6

6:                                                ; preds = %4
  %7 = add i64 %5, 1
  %8 = tail call ptr @xalloc(ptr noundef %0, i64 noundef %7) #2
  %9 = icmp eq ptr %8, null
  br i1 %9, label %15, label %10

10:                                               ; preds = %6
  %11 = tail call i32 @xstrncpyarg(ptr noundef nonnull %8, i64 noundef %7, ptr noundef %1, ptr noundef %2)
  %12 = sext i32 %11 to i64
  store i64 %12, ptr %3, align 8, !tbaa !5
  %13 = icmp eq i32 %11, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  tail call void @xfree(ptr noundef %0, ptr noundef nonnull %8) #2
  br label %15

15:                                               ; preds = %14, %6, %10, %4
  %.1 = phi ptr [ null, %4 ], [ null, %14 ], [ null, %6 ], [ %8, %10 ]
  ret ptr %.1
}

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

declare void @xfree(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass