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

; 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 @tokenize(ptr noundef %0, i32 noundef %1, ptr noundef %2, i8 noundef signext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %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 i8 %3, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  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 = %63, %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 %64

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %31, %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 = load i8, ptr %8, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %34

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

34:                                               ; preds = %24
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %34
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = add i32 %41, 1
  store i32 %42, ptr %10, align 4, !tbaa !9
  %43 = zext i32 %41 to i64
  %44 = getelementptr inbounds ptr, ptr %40, i64 %43
  store ptr %39, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %38, %34
  br label %46

46:                                               ; preds = %60, %45
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %58

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

58:                                               ; preds = %51, %46
  %59 = phi i1 [ false, %46 ], [ %57, %51 ]
  br i1 %59, label %60, label %63

60:                                               ; preds = %58
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %9, align 8, !tbaa !5
  br label %46, !llvm.loop !14

63:                                               ; preds = %58
  br label %12, !llvm.loop !15

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

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

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

!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 norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @tokenize(ptr nocapture noundef writeonly %0, i32 noundef %1, ptr noundef %2, i8 noundef signext %3) local_unnamed_addr #0 {
  %.not32 = icmp eq i32 %1, 0
  br i1 %.not32, label %.critedge, label %.lr.ph29.preheader

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

.critedge2.loopexit:                              ; preds = %14
  %5 = icmp ult i32 %.1, %1
  br i1 %5, label %.lr.ph29, label %.critedge, !llvm.loop !8

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.critedge2.loopexit
  %6 = phi i8 [ %15, %.critedge2.loopexit ], [ %.pre, %.lr.ph29.preheader ]
  %.027 = phi i32 [ %.1, %.critedge2.loopexit ], [ 0, %.lr.ph29.preheader ]
  %.01726 = phi ptr [ %.2, %.critedge2.loopexit ], [ %2, %.lr.ph29.preheader ]
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %.lr.ph29
  %7 = icmp eq i8 %6, %3
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.11824 = phi ptr [ %8, %.lr.ph ], [ %.01726, %.preheader ]
  %8 = getelementptr inbounds i8, ptr %.11824, i64 1
  store i8 0, ptr %.11824, align 1, !tbaa !5
  %.pr = load i8, ptr %8, align 1, !tbaa !5
  %9 = icmp eq i8 %.pr, %3
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph
  %.not21 = icmp eq i8 %.pr, 0
  br i1 %.not21, label %13, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %.118.lcssa37 = phi ptr [ %8, %._crit_edge ], [ %.01726, %.preheader ]
  %10 = add i32 %.027, 1
  %11 = zext i32 %.027 to i64
  %12 = getelementptr inbounds ptr, ptr %0, i64 %11
  store ptr %.118.lcssa37, ptr %12, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %.118.lcssa38 = phi ptr [ %.118.lcssa37, %._crit_edge.thread ], [ %8, %._crit_edge ]
  %.1 = phi i32 [ %10, %._crit_edge.thread ], [ %.027, %._crit_edge ]
  br label %14

14:                                               ; preds = %14, %13
  %.2 = phi ptr [ %.118.lcssa38, %13 ], [ %16, %14 ]
  %15 = load i8, ptr %.2, align 1, !tbaa !5
  %.not22 = icmp eq i8 %15, 0
  %.not23 = icmp eq i8 %15, %3
  %or.cond = or i1 %.not22, %.not23
  %16 = getelementptr inbounds i8, ptr %.2, i64 1
  br i1 %or.cond, label %.critedge2.loopexit, label %14, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph29, %.critedge2.loopexit, %4
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.1, %.critedge2.loopexit ], [ %.027, %.lr.ph29 ]
  ret i32 %.0.lcssa
}

attributes #0 = { nofree norecurse nosync 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" }

!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 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = distinct !{!13, !9}


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