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

@.str.38 = external hidden unnamed_addr constant [3 x i8], align 1

; 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 uwtable
declare dso_local i64 @xstrncpys(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @xstrnrep(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %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 ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = 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
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %5
  store i32 -2, ptr %6, align 4
  br label %115

24:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %25, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = call i64 @strlen(ptr noundef %26) #4
  store i64 %27, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = call i64 @strlen(ptr noundef %28) #4
  store i64 %29, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = call i64 @strlen(ptr noundef %30) #4
  store i64 %31, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 0, ptr %18, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %42, %24
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i64, ptr %13, align 8, !tbaa !9
  %37 = load i32, ptr %17, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = call i32 @xstrntokn(ptr noundef null, i64 noundef 0, ptr noundef %35, i64 noundef %36, i64 noundef %38, ptr noundef %39)
  store i32 %40, ptr %17, align 4, !tbaa !11
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %34
  %43 = load i32, ptr %18, align 4, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %18, align 4, !tbaa !11
  br label %34, !llvm.loop !13

45:                                               ; preds = %34
  br label %46

46:                                               ; preds = %107, %45
  %47 = load i32, ptr %18, align 4, !tbaa !11
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %18, align 4, !tbaa !11
  %49 = icmp ne i32 %47, 0
  br i1 %49, label %50, label %108

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = call i32 @xstrsrc(ptr noundef %51, ptr noundef %52)
  store i32 %53, ptr %19, align 4, !tbaa !11
  %54 = load i32, ptr %19, align 4, !tbaa !11
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  store i32 5, ptr %20, align 4
  br label %105

57:                                               ; preds = %50
  %58 = load i32, ptr %19, align 4, !tbaa !11
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %79

60:                                               ; preds = %57
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = load i32, ptr %16, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i32, ptr %19, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = call i64 @xstrncpys(ptr noundef %61, i64 noundef %63, ptr noundef %64, i64 noundef %66)
  %68 = load i32, ptr %19, align 4, !tbaa !11
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  store ptr %71, ptr %12, align 8, !tbaa !5
  %72 = load i32, ptr %19, align 4, !tbaa !11
  %73 = load i32, ptr %16, align 4, !tbaa !11
  %74 = sub nsw i32 %73, %72
  store i32 %74, ptr %16, align 4, !tbaa !11
  %75 = load i32, ptr %16, align 4, !tbaa !11
  %76 = icmp sle i32 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %60
  store i32 0, ptr %6, align 4
  store i32 1, ptr %20, align 4
  br label %105

78:                                               ; preds = %60
  br label %79

79:                                               ; preds = %78, %57
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = load i32, ptr %16, align 4, !tbaa !11
  %82 = sext i32 %81 to i64
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = load i64, ptr %14, align 8, !tbaa !9
  %85 = call i64 @xstrncpys(ptr noundef %80, i64 noundef %82, ptr noundef %83, i64 noundef %84)
  %86 = load i32, ptr %19, align 4, !tbaa !11
  %87 = sext i32 %86 to i64
  %88 = load i64, ptr %15, align 8, !tbaa !9
  %89 = add i64 %87, %88
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i64 %89
  store ptr %91, ptr %9, align 8, !tbaa !5
  %92 = load i64, ptr %14, align 8, !tbaa !9
  %93 = trunc i64 %92 to i32
  %94 = load i32, ptr %16, align 4, !tbaa !11
  %95 = sub nsw i32 %94, %93
  store i32 %95, ptr %16, align 4, !tbaa !11
  %96 = load i64, ptr %14, align 8, !tbaa !9
  %97 = trunc i64 %96 to i32
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = sext i32 %97 to i64
  %100 = getelementptr inbounds i8, ptr %98, i64 %99
  store ptr %100, ptr %12, align 8, !tbaa !5
  %101 = load i32, ptr %16, align 4, !tbaa !11
  %102 = icmp sle i32 %101, 0
  br i1 %102, label %103, label %104

103:                                              ; preds = %79
  store i32 0, ptr %6, align 4
  store i32 1, ptr %20, align 4
  br label %105

104:                                              ; preds = %79
  store i32 0, ptr %20, align 4
  br label %105

105:                                              ; preds = %104, %103, %77, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  %106 = load i32, ptr %20, align 4
  switch i32 %106, label %114 [
    i32 0, label %107
    i32 5, label %108
  ]

107:                                              ; preds = %105
  br label %46, !llvm.loop !15

108:                                              ; preds = %105, %46
  %109 = load ptr, ptr %12, align 8, !tbaa !5
  %110 = load i32, ptr %16, align 4, !tbaa !11
  %111 = sext i32 %110 to i64
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %109, i64 noundef %111, ptr noundef @.str.38, ptr noundef %112)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %20, align 4
  br label %114

114:                                              ; preds = %108, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %115

115:                                              ; preds = %114, %23
  %116 = load i32, ptr %6, align 4
  ret i32 %116
}

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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@.str.38 = external hidden unnamed_addr constant [3 x i8], align 1

; 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: nounwind uwtable
declare dso_local i64 @xstrncpys(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

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

6:                                                ; preds = %5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #2
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #2
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #2
  br label %10

10:                                               ; preds = %10, %6
  %.044 = phi i32 [ 0, %6 ], [ %12, %10 ]
  %.042 = phi i32 [ 0, %6 ], [ %14, %10 ]
  %11 = zext nneg i32 %.044 to i64
  %12 = tail call i32 @xstrntokn(ptr noundef null, i64 noundef 0, ptr noundef %2, i64 noundef %7, i64 noundef %11, ptr noundef %3)
  %13 = icmp sgt i32 %12, 0
  %14 = add nuw nsw i32 %.042, 1
  br i1 %13, label %10, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %10
  %15 = trunc i64 %1 to i32
  %16 = trunc i64 %8 to i32
  %sext = shl i64 %8, 32
  %17 = ashr exact i64 %sext, 32
  br label %18

18:                                               ; preds = %.preheader, %._crit_edge
  %.052 = phi ptr [ %36, %._crit_edge ], [ %0, %.preheader ]
  %.049 = phi ptr [ %34, %._crit_edge ], [ %2, %.preheader ]
  %.045 = phi i32 [ %35, %._crit_edge ], [ %15, %.preheader ]
  %.143 = phi i32 [ %19, %._crit_edge ], [ %.042, %.preheader ]
  %19 = add nsw i32 %.143, -1
  %.not63 = icmp eq i32 %.143, 0
  br i1 %.not63, label %.thread69, label %20

20:                                               ; preds = %18
  %21 = tail call i32 @xstrsrc(ptr noundef %.049, ptr noundef %3)
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %.thread69, label %23

23:                                               ; preds = %20
  %.not64 = icmp eq i32 %21, 0
  br i1 %.not64, label %._crit_edge, label %24

24:                                               ; preds = %23
  %25 = sext i32 %.045 to i64
  %26 = zext nneg i32 %21 to i64
  %27 = tail call i64 @xstrncpys(ptr noundef %.052, i64 noundef %25, ptr noundef %.049, i64 noundef %26)
  %28 = getelementptr inbounds i8, ptr %.052, i64 %26
  %29 = sub nsw i32 %.045, %21
  %30 = icmp slt i32 %29, 1
  br i1 %30, label %.thread, label %._crit_edge

._crit_edge:                                      ; preds = %23, %24
  %.pre-phi = phi i64 [ %26, %24 ], [ 0, %23 ]
  %.153 = phi ptr [ %28, %24 ], [ %.052, %23 ]
  %.146 = phi i32 [ %29, %24 ], [ %.045, %23 ]
  %31 = sext i32 %.146 to i64
  %32 = tail call i64 @xstrncpys(ptr noundef %.153, i64 noundef %31, ptr noundef %4, i64 noundef %8)
  %33 = add i64 %9, %.pre-phi
  %34 = getelementptr inbounds i8, ptr %.049, i64 %33
  %35 = sub nsw i32 %.146, %16
  %36 = getelementptr inbounds i8, ptr %.153, i64 %17
  %37 = icmp slt i32 %35, 1
  br i1 %37, label %.thread, label %18

.thread69:                                        ; preds = %20, %18
  %38 = sext i32 %.045 to i64
  %39 = tail call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %.052, i64 noundef %38, ptr noundef nonnull @.str.38, ptr noundef %.049)
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %24, %.thread69, %5
  %.3 = phi i32 [ -2, %5 ], [ 1, %.thread69 ], [ 0, %24 ], [ 0, %._crit_edge ]
  ret i32 %.3
}

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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass