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

@g_keyMapEn = external hidden global [33 x ptr], align 16
@g_keyMapGe = external hidden global [33 x ptr], align 16

; 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 i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @xstrtoen(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [8192 x i8], align 16
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %47

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8192, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 0, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %42, %15
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = icmp ult i64 %17, 33
  br i1 %18, label %19, label %45

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = load i8, ptr %9, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = getelementptr inbounds [8192 x i8], ptr %8, i64 0, i64 0
  br label %27

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %25, %23
  %28 = phi ptr [ %24, %23 ], [ %26, %25 ]
  store ptr %28, ptr %11, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = getelementptr inbounds [33 x ptr], ptr @g_keyMapGe, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds [33 x ptr], ptr @g_keyMapEn, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = call i32 @xstrnrep(ptr noundef %29, i64 noundef %30, ptr noundef %31, ptr noundef %34, ptr noundef %37)
  %39 = getelementptr inbounds [8192 x i8], ptr %8, i64 0, i64 0
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i64 @xstrncpy(ptr noundef %39, i64 noundef 8192, ptr noundef %40)
  store i8 1, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %42

42:                                               ; preds = %27
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = add i64 %43, 1
  store i64 %44, ptr %10, align 8, !tbaa !9
  br label %16, !llvm.loop !12

45:                                               ; preds = %16
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %46, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8192, ptr %8) #2
  br label %47

47:                                               ; preds = %45, %14
  %48 = load ptr, ptr %4, align 8
  ret ptr %48
}

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 }

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


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

@g_keyMapEn = external hidden local_unnamed_addr global [33 x ptr], align 16
@g_keyMapGe = external hidden local_unnamed_addr global [33 x ptr], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 i64 @xstrncpy(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @xstrtoen(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [8192 x i8], align 16
  %5 = icmp eq ptr %2, null
  br i1 %5, label %18, label %.peel.next

.peel.next:                                       ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %4) #2
  %6 = load ptr, ptr @g_keyMapGe, align 16, !tbaa !5
  %7 = load ptr, ptr @g_keyMapEn, align 16, !tbaa !5
  %8 = tail call i32 @xstrnrep(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %2, ptr noundef %6, ptr noundef %7)
  %9 = call i64 @xstrncpy(ptr noundef nonnull %4, i64 noundef 8192, ptr noundef %0)
  br label %10

10:                                               ; preds = %.peel.next, %10
  %.01216 = phi i64 [ 1, %.peel.next ], [ %17, %10 ]
  %11 = getelementptr inbounds [33 x ptr], ptr @g_keyMapGe, i64 0, i64 %.01216
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds [33 x ptr], ptr @g_keyMapEn, i64 0, i64 %.01216
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = call i32 @xstrnrep(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %4, ptr noundef %12, ptr noundef %14)
  %16 = call i64 @xstrncpy(ptr noundef nonnull %4, i64 noundef 8192, ptr noundef %0)
  %17 = add nuw nsw i64 %.01216, 1
  %exitcond.not = icmp eq i64 %17, 33
  br i1 %exitcond.not, label %.loopexit, label %10, !llvm.loop !9

.loopexit:                                        ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %4) #2
  br label %18

18:                                               ; preds = %3, %.loopexit
  %.0 = phi ptr [ %0, %.loopexit ], [ null, %3 ]
  ret ptr %.0
}

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

!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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass