; 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 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 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 uwtable
define dso_local i64 @xstrrand(ptr noundef %0, i64 noundef %1, i64 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca ptr, 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
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !11
  store i8 %4, ptr %11, align 1, !tbaa !11
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %27, label %21

21:                                               ; preds = %5
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24, %21, %5
  store i64 0, ptr %6, align 8
  br label %89

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr @.str, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr @.str.1, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = sub i64 %30, 1
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  %34 = load i64, ptr %9, align 8, !tbaa !9
  br label %38

35:                                               ; preds = %28
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = sub i64 %36, 1
  br label %38

38:                                               ; preds = %35, %33
  %39 = phi i64 [ %34, %33 ], [ %37, %35 ]
  store i64 %39, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %40 = load i8, ptr %10, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  %43 = zext i1 %42 to i64
  %44 = select i1 %42, i32 52, i32 26
  store i32 %44, ptr %16, align 4, !tbaa !12
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %81, %38
  %46 = load i64, ptr %14, align 8, !tbaa !9
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = icmp ult i64 %46, %47
  br i1 %48, label %49, label %84

49:                                               ; preds = %45
  %50 = load i8, ptr %11, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %68

53:                                               ; preds = %49
  %54 = call i32 @rand() #3
  %55 = srem i32 %54, 2
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %68

57:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %58 = call i32 @rand() #3
  %59 = srem i32 %58, 10
  store i32 %59, ptr %17, align 4, !tbaa !12
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i32, ptr %17, align 4, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i64, ptr %14, align 8, !tbaa !9
  %67 = getelementptr inbounds i8, ptr %65, i64 %66
  store i8 %64, ptr %67, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %80

68:                                               ; preds = %53, %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %69 = call i32 @rand() #3
  %70 = load i32, ptr %16, align 4, !tbaa !12
  %71 = srem i32 %69, %70
  store i32 %71, ptr %18, align 4, !tbaa !12
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = load i32, ptr %18, align 4, !tbaa !12
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !11
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %14, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  store i8 %76, ptr %79, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %80

80:                                               ; preds = %68, %57
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %14, align 8, !tbaa !9
  %83 = add i64 %82, 1
  store i64 %83, ptr %14, align 8, !tbaa !9
  br label %45, !llvm.loop !14

84:                                               ; preds = %45
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i64, ptr %15, align 8, !tbaa !9
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  store i8 0, ptr %87, align 1, !tbaa !11
  %88 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %88, ptr %6, align 8
  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 %89

89:                                               ; preds = %84, %27
  %90 = load i64, ptr %6, align 8
  ret i64 %90
}

; Function Attrs: nounwind
declare i32 @rand() #2

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

!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}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str = external hidden unnamed_addr constant [53 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @xstrrand(ptr noundef writeonly %0, i64 noundef %1, i64 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = icmp ne ptr %0, null
  %7 = icmp ne i64 %1, 0
  %or.cond = and i1 %6, %7
  %8 = icmp ne i64 %2, 0
  %or.cond3 = and i1 %or.cond, %8
  br i1 %or.cond3, label %9, label %29

9:                                                ; preds = %5
  %10 = add i64 %1, -1
  %11 = tail call i64 @llvm.umin.i64(i64 %10, i64 %2)
  %.not = icmp eq i8 %3, 0
  %12 = select i1 %.not, i32 26, i32 52
  %.not36 = icmp eq i64 %10, 0
  br i1 %.not36, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %.not32 = icmp eq i8 %4, 0
  %umax38 = tail call i64 @llvm.umax.i64(i64 %11, i64 1)
  br i1 %.not32, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.02734.us = phi i64 [ %19, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %13 = tail call i32 @rand() #3
  %14 = srem i32 %13, %12
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr @.str, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 %.02734.us
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = add nuw i64 %.02734.us, 1
  %exitcond39.not = icmp eq i64 %19, %umax38
  br i1 %exitcond39.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !8

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.02734 = phi i64 [ %27, %.lr.ph.split ], [ 0, %.lr.ph ]
  %20 = tail call i32 @rand() #3
  %21 = and i32 %20, 1
  %.not33 = icmp eq i32 %21, 0
  %22 = tail call i32 @rand() #3
  %. = select i1 %.not33, i32 %12, i32 10
  %.str..str.1 = select i1 %.not33, ptr @.str, ptr @.str.1
  %23 = srem i32 %22, %.
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %.str..str.1, i64 %24
  %.sink = load i8, ptr %25, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 %.02734
  store i8 %.sink, ptr %26, align 1
  %27 = add nuw i64 %.02734, 1
  %exitcond.not = icmp eq i64 %27, %umax38
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %9
  %28 = getelementptr inbounds i8, ptr %0, i64 %11
  store i8 0, ptr %28, align 1, !tbaa !5
  br label %29

29:                                               ; preds = %5, %._crit_edge
  %.0 = phi i64 [ %11, %._crit_edge ], [ 0, %5 ]
  ret i64 %.0
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

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 = { nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass