; 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 @xstrntokn(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

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

22:                                               ; preds = %19, %6
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = icmp uge i64 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 -1, ptr %7, align 4
  br label %84

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = call zeroext i8 @xstrused(ptr noundef %28)
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = call i64 @strlen(ptr noundef %33) #4
  br label %36

35:                                               ; preds = %27
  br label %36

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

45:                                               ; preds = %36
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = call i64 @xstrncpy(ptr noundef %46, i64 noundef %47, ptr noundef %50)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %83

52:                                               ; preds = %36
  %53 = load i32, ptr %15, align 4, !tbaa !12
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %66, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 0
  store i8 0, ptr %60, align 1, !tbaa !11
  br label %61

61:                                               ; preds = %58, %55
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = load i64, ptr %14, align 8, !tbaa !9
  %64 = add i64 %62, %63
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %83

66:                                               ; preds = %52
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load i64, ptr %12, align 8, !tbaa !9
  %72 = getelementptr inbounds i8, ptr %70, i64 %71
  %73 = load i32, ptr %15, align 4, !tbaa !12
  %74 = sext i32 %73 to i64
  %75 = call i64 @xstrncpys(ptr noundef %68, i64 noundef %69, ptr noundef %72, i64 noundef %74)
  %76 = load i64, ptr %12, align 8, !tbaa !9
  %77 = load i32, ptr %15, align 4, !tbaa !12
  %78 = sext i32 %77 to i64
  %79 = add i64 %76, %78
  %80 = load i64, ptr %14, align 8, !tbaa !9
  %81 = add i64 %79, %80
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %83

83:                                               ; preds = %67, %61, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %84

84:                                               ; preds = %83, %26
  %85 = load i32, ptr %7, align 4
  ret i32 %85
}

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 }
attributes #4 = { 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 = !{!"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 @xstrntokn(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %8, label %7

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

8:                                                ; preds = %7, %6
  %.not31 = icmp ult i64 %4, %3
  br i1 %.not31, label %9, label %32

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

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

13:                                               ; preds = %9, %11
  %14 = phi i64 [ %12, %11 ], [ 0, %9 ]
  %15 = getelementptr inbounds i8, ptr %2, i64 %4
  %16 = tail call i32 @xstrsrc(ptr noundef %15, ptr noundef %5)
  %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 %32

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

21:                                               ; preds = %20
  br i1 %.not, label %23, label %22

22:                                               ; preds = %21
  store i8 0, ptr %0, align 1, !tbaa !5
  br label %23

23:                                               ; preds = %22, %21
  %24 = add i64 %14, %4
  %25 = trunc i64 %24 to i32
  br label %32

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

32:                                               ; preds = %18, %23, %26, %8
  %.1 = phi i32 [ -1, %8 ], [ 0, %18 ], [ %31, %26 ], [ %25, %23 ]
  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