; 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: 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 zeroext i8 @xstrused(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

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

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

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

17:                                               ; preds = %5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 0
  store i8 0, ptr %19, align 1, !tbaa !11
  br label %20

20:                                               ; preds = %17, %5
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #3
  %24 = icmp uge i64 %21, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 -1, ptr %6, align 4
  br label %79

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = call zeroext i8 @xstrused(ptr noundef %27)
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = call i64 @strlen(ptr noundef %32) #3
  br label %35

34:                                               ; preds = %26
  br label %35

35:                                               ; preds = %34, %31
  %36 = phi i64 [ %33, %31 ], [ 0, %34 ]
  store i64 %36, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = call i32 @xstrsrc(ptr noundef %39, ptr noundef %40)
  store i32 %41, ptr %13, align 4, !tbaa !12
  %42 = load i32, ptr %13, align 4, !tbaa !12
  %43 = icmp slt i32 %42, 0
  br i1 %43, label %44, label %51

44:                                               ; preds = %35
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  %50 = call i64 @xstrncpy(ptr noundef %45, i64 noundef %46, ptr noundef %49)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

51:                                               ; preds = %35
  %52 = load i32, ptr %13, align 4, !tbaa !12
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %61, label %54

54:                                               ; preds = %51
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 0
  store i8 0, ptr %56, align 1, !tbaa !11
  %57 = load i64, ptr %10, align 8, !tbaa !9
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = add i64 %57, %58
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

61:                                               ; preds = %51
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load i64, ptr %10, align 8, !tbaa !9
  %67 = getelementptr inbounds i8, ptr %65, i64 %66
  %68 = load i32, ptr %13, align 4, !tbaa !12
  %69 = sext i32 %68 to i64
  %70 = call i64 @xstrncpys(ptr noundef %63, i64 noundef %64, ptr noundef %67, i64 noundef %69)
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = load i32, ptr %13, align 4, !tbaa !12
  %73 = sext i32 %72 to i64
  %74 = add i64 %71, %73
  %75 = load i64, ptr %12, align 8, !tbaa !9
  %76 = add i64 %74, %75
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

78:                                               ; preds = %62, %54, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %79

79:                                               ; preds = %78, %25
  %80 = load i32, ptr %6, align 4
  ret i32 %80
}

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 willreturn memory(read) "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 willreturn memory(read) }
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, !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}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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 zeroext i8 @xstrused(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @xstrntok(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %5
  store i8 0, ptr %0, align 1, !tbaa !5
  br label %7

7:                                                ; preds = %6, %5
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #2
  %.not29 = icmp ugt i64 %8, %3
  br i1 %.not29, label %9, label %30

9:                                                ; preds = %7
  %10 = tail call zeroext i8 @xstrused(ptr noundef %4)
  %.not30 = icmp eq i8 %10, 0
  br i1 %.not30, label %13, label %11

11:                                               ; preds = %9
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #2
  br label %13

13:                                               ; preds = %9, %11
  %14 = phi i64 [ %12, %11 ], [ 0, %9 ]
  %15 = getelementptr inbounds i8, ptr %2, i64 %3
  %16 = tail call i32 @xstrsrc(ptr noundef %15, ptr noundef %4)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  %19 = tail call i64 @xstrncpy(ptr noundef %0, i64 noundef %1, ptr noundef %15)
  br label %30

20:                                               ; preds = %13
  %.not31 = icmp eq i32 %16, 0
  br i1 %.not31, label %21, label %24

21:                                               ; preds = %20
  store i8 0, ptr %0, align 1, !tbaa !5
  %22 = add i64 %14, %3
  %23 = trunc i64 %22 to i32
  br label %30

24:                                               ; preds = %20
  %25 = zext nneg i32 %16 to i64
  %26 = tail call i64 @xstrncpys(ptr noundef %0, i64 noundef %1, ptr noundef %15, i64 noundef %25)
  %27 = add i64 %14, %3
  %28 = trunc i64 %27 to i32
  %29 = add i32 %16, %28
  br label %30

30:                                               ; preds = %18, %21, %24, %7
  %.1 = phi i32 [ -1, %7 ], [ 0, %18 ], [ %29, %24 ], [ %23, %21 ]
  ret i32 %.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 nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass