; 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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strnlen(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @xstrncuts(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = 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 ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 0
  store i8 0, ptr %17, align 1, !tbaa !11
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %40

20:                                               ; preds = %5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i64 0, ptr %6, align 8
  br label %71

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = call i32 @xstrntok(ptr noundef %25, i64 noundef %26, ptr noundef %27, i64 noundef 0, ptr noundef %28)
  store i32 %29, ptr %12, align 4, !tbaa !12
  %30 = load i32, ptr %12, align 4, !tbaa !12
  %31 = icmp sge i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %24
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = sub i64 %34, 1
  %36 = call i64 @strnlen(ptr noundef %33, i64 noundef %35) #4
  br label %38

37:                                               ; preds = %24
  br label %38

38:                                               ; preds = %37, %32
  %39 = phi i64 [ %36, %32 ], [ 0, %37 ]
  store i64 %39, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %71

40:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = call i32 @xstrsrc(ptr noundef %41, ptr noundef %42)
  store i32 %43, ptr %13, align 4, !tbaa !12
  %44 = load i32, ptr %13, align 4, !tbaa !12
  %45 = icmp slt i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i64 0, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %70

47:                                               ; preds = %40
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = call i64 @strlen(ptr noundef %48) #4
  %50 = trunc i64 %49 to i32
  %51 = load i32, ptr %13, align 4, !tbaa !12
  %52 = add nsw i32 %51, %50
  store i32 %52, ptr %13, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i32, ptr %13, align 4, !tbaa !12
  %57 = sext i32 %56 to i64
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = call i32 @xstrntok(ptr noundef %53, i64 noundef %54, ptr noundef %55, i64 noundef %57, ptr noundef %58)
  store i32 %59, ptr %15, align 4, !tbaa !12
  %60 = load i32, ptr %15, align 4, !tbaa !12
  %61 = icmp sge i32 %60, 0
  br i1 %61, label %62, label %67

62:                                               ; preds = %47
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = sub i64 %64, 1
  %66 = call i64 @strnlen(ptr noundef %63, i64 noundef %65) #4
  br label %68

67:                                               ; preds = %47
  br label %68

68:                                               ; preds = %67, %62
  %69 = phi i64 [ %66, %62 ], [ 0, %67 ]
  store i64 %69, ptr %6, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %70

70:                                               ; preds = %68, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %71

71:                                               ; preds = %70, %38, %23
  %72 = load i64, ptr %6, align 8
  ret i64 %72
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @xstrncuts(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  store i8 0, ptr %0, align 1, !tbaa !5
  %6 = icmp eq ptr %3, null
  br i1 %6, label %7, label %12

7:                                                ; preds = %5
  %8 = icmp eq ptr %4, null
  br i1 %8, label %24, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @xstrntok(ptr noundef nonnull %0, i64 noundef %1, ptr noundef %2, i64 noundef 0, ptr noundef nonnull %4)
  %11 = icmp sgt i32 %10, -1
  br i1 %11, label %.sink.split, label %24

12:                                               ; preds = %5
  %13 = tail call i32 @xstrsrc(ptr noundef %2, ptr noundef nonnull %3)
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %24, label %15

15:                                               ; preds = %12
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #2
  %17 = trunc i64 %16 to i32
  %18 = add nsw i32 %13, %17
  %19 = sext i32 %18 to i64
  %20 = tail call i32 @xstrntok(ptr noundef nonnull %0, i64 noundef %1, ptr noundef %2, i64 noundef %19, ptr noundef %4)
  %21 = icmp sgt i32 %20, -1
  br i1 %21, label %.sink.split, label %24

.sink.split:                                      ; preds = %15, %9
  %22 = add i64 %1, -1
  %23 = tail call i64 @strnlen(ptr noundef nonnull %0, i64 noundef %22) #2
  br label %24

24:                                               ; preds = %.sink.split, %12, %15, %9, %7
  %.1 = phi i64 [ 0, %7 ], [ 0, %9 ], [ 0, %12 ], [ 0, %15 ], [ %23, %.sink.split ]
  ret i64 %.1
}

attributes #0 = { 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 #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) }

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