; LLVM IR from 0intro/wmii :: lib/libstuff/util (stokenize)

; 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: nounwind uwtable
define dso_local i32 @stokenize(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %11, ptr %9, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %71, %4
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 0
  br label %21

21:                                               ; preds = %16, %12
  %22 = phi i1 [ false, %12 ], [ %20, %16 ]
  br i1 %22, label %23, label %72

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %38, %23
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = call ptr @strchr(ptr noundef %30, i32 noundef %33) #4
  %35 = icmp ne ptr %34, null
  br label %36

36:                                               ; preds = %29, %24
  %37 = phi i1 [ false, %24 ], [ %35, %29 ]
  br i1 %37, label %38, label %41

38:                                               ; preds = %36
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %39, align 1, !tbaa !11
  br label %24, !llvm.loop !12

41:                                               ; preds = %36
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %41
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !9
  %50 = zext i32 %48 to i64
  %51 = getelementptr inbounds ptr, ptr %47, i64 %50
  store ptr %46, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %45, %41
  br label %53

53:                                               ; preds = %68, %52
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %66

58:                                               ; preds = %53
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = call ptr @strchr(ptr noundef %59, i32 noundef %62) #4
  %64 = icmp ne ptr %63, null
  %65 = xor i1 %64, true
  br label %66

66:                                               ; preds = %58, %53
  %67 = phi i1 [ false, %53 ], [ %65, %58 ]
  br i1 %67, label %68, label %71

68:                                               ; preds = %66
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i32 1
  store ptr %70, ptr %9, align 8, !tbaa !5
  br label %53, !llvm.loop !14

71:                                               ; preds = %66
  br label %12, !llvm.loop !15

72:                                               ; preds = %21
  %73 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 %73
}

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @stokenize(ptr nocapture noundef writeonly %0, i32 noundef %1, ptr noundef %2, ptr noundef readonly %3) local_unnamed_addr #0 {
  %.not42 = icmp eq i32 %1, 0
  br i1 %.not42, label %.critedge, label %.lr.ph38.preheader

.lr.ph38.preheader:                               ; preds = %4
  %.pre = load i8, ptr %2, align 1, !tbaa !5
  br label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.critedge4
  %5 = phi i8 [ %20, %.critedge4 ], [ %.pre, %.lr.ph38.preheader ]
  %.037 = phi i32 [ %.148, %.critedge4 ], [ 0, %.lr.ph38.preheader ]
  %.02036 = phi ptr [ %.2.lcssa, %.critedge4 ], [ %2, %.lr.ph38.preheader ]
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %.lr.ph38, %9
  %.12131 = phi ptr [ %10, %9 ], [ %.02036, %.lr.ph38 ]
  %6 = phi i8 [ %.pr, %9 ], [ %5, %.lr.ph38 ]
  %7 = sext i8 %6 to i32
  %8 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %3, i32 noundef %7) #2
  %.not25 = icmp eq ptr %8, null
  br i1 %.not25, label %.critedge2.thread, label %9

9:                                                ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %.12131, i64 1
  store i8 0, ptr %.12131, align 1, !tbaa !5
  %.pr = load i8, ptr %10, align 1, !tbaa !5
  %.not24 = icmp eq i8 %.pr, 0
  br i1 %.not24, label %.critedge4, label %.preheader, !llvm.loop !8

.critedge2.thread:                                ; preds = %.preheader
  %11 = add i32 %.037, 1
  %12 = zext i32 %.037 to i64
  %13 = getelementptr inbounds ptr, ptr %0, i64 %12
  store ptr %.12131, ptr %13, align 8, !tbaa !10
  %.pre44 = load i8, ptr %.12131, align 1, !tbaa !5
  %.not2732 = icmp eq i8 %.pre44, 0
  br i1 %.not2732, label %.critedge4, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge2.thread, %17
  %14 = phi i8 [ %19, %17 ], [ %.pre44, %.critedge2.thread ]
  %.233 = phi ptr [ %18, %17 ], [ %.12131, %.critedge2.thread ]
  %15 = sext i8 %14 to i32
  %16 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %3, i32 noundef %15) #2
  %.not28 = icmp eq ptr %16, null
  br i1 %.not28, label %17, label %.critedge4

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.233, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %.not27 = icmp eq i8 %19, 0
  br i1 %.not27, label %.critedge4, label %.lr.ph, !llvm.loop !12

.critedge4:                                       ; preds = %9, %.lr.ph, %17, %.critedge2.thread
  %.148 = phi i32 [ %11, %.critedge2.thread ], [ %11, %17 ], [ %11, %.lr.ph ], [ %.037, %9 ]
  %20 = phi i8 [ 0, %.critedge2.thread ], [ %14, %.lr.ph ], [ 0, %17 ], [ 0, %9 ]
  %.2.lcssa = phi ptr [ %.12131, %.critedge2.thread ], [ %.233, %.lr.ph ], [ %18, %17 ], [ %10, %9 ]
  %21 = icmp ult i32 %.148, %1
  br i1 %21, label %.lr.ph38, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph38, %.critedge4, %4
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.148, %.critedge4 ], [ %.037, %.lr.ph38 ]
  ret i32 %.0.lcssa
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: none) 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = distinct !{!12, !9}
!13 = distinct !{!13, !9}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass