; LLVM IR from facebook/redex :: libresource/String8.ll (ZN7android7String89removeAllEPKc)

; 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: 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7android7String89removeAllEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %14, i64 noundef 0)
  store i64 %15, ptr %6, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %70

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %20 = call noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %13)
  %21 = call noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %13, i64 noundef %20)
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %69

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i64 @strlen(ptr noundef %26) #6
  store i64 %27, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %28 = call noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %13)
  store i64 %28, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %29 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %29, ptr %11, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %44, %25
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %34, label %66

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = add i64 %36, %37
  %39 = call noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %35, i64 noundef %38)
  store i64 %39, ptr %12, align 8, !tbaa !9
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = icmp slt i64 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %34
  %43 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %43, ptr %12, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %42, %34
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i64, ptr %12, align 8, !tbaa !9
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = sub nsw i64 %53, %54
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = sub i64 %55, %56
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %47, ptr align 1 %52, i64 %57, i1 false)
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = sub nsw i64 %58, %59
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = add i64 %63, %62
  store i64 %64, ptr %11, align 8, !tbaa !9
  %65 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %65, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %30, !llvm.loop !11

66:                                               ; preds = %30
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = call noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %13, i64 noundef %67)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %69

69:                                               ; preds = %66, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %70

70:                                               ; preds = %69, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %71 = load i1, ptr %3, align 1
  ret i1 %71
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #4

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 = { mustprogress 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 = { inlinehint mustprogress 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7android7String89removeAllEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i64 noundef 0)
  %4 = icmp slt i64 %3, 0
  br i1 %4, label %20, label %5

5:                                                ; preds = %2
  %6 = tail call noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %7 = tail call noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %6)
  %.not.not = icmp eq ptr %7, null
  br i1 %.not.not, label %20, label %8

8:                                                ; preds = %5
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %10 = tail call noundef i64 @_ZNK7android7String84sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %invariant.gep = getelementptr i8, ptr %7, i64 %9
  %11 = icmp ult i64 %3, %10
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.02735 = phi i64 [ %17, %.lr.ph ], [ %3, %8 ]
  %.02934 = phi i64 [ %spec.select, %.lr.ph ], [ %3, %8 ]
  %12 = add i64 %.02934, %9
  %13 = tail call noundef i64 @_ZNK7android7String84findEPKcm(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i64 noundef %12)
  %14 = icmp slt i64 %13, 0
  %spec.select = select i1 %14, i64 %10, i64 %13
  %15 = getelementptr inbounds i8, ptr %7, i64 %.02735
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.02934
  %16 = sub i64 %spec.select, %12
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %15, ptr nonnull align 1 %gep, i64 %16, i1 false)
  %17 = add i64 %16, %.02735
  %18 = icmp ult i64 %spec.select, %10
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.027.lcssa = phi i64 [ %3, %8 ], [ %17, %.lr.ph ]
  %19 = tail call noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %.027.lcssa)
  br label %20

20:                                               ; preds = %._crit_edge, %5, %2
  %.1 = phi i1 [ false, %2 ], [ false, %5 ], [ true, %._crit_edge ]
  ret i1 %.1
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 = { mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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