; LLVM IR from iqiyi/xgboost-serving :: tensorflow_serving/util/strings/string_piece.ll (ZNK11StringPiece5rfindERKS_m)

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

%class.StringPiece = type <{ ptr, i32, [4 x i8] }>

@_ZN11StringPiece4nposE = external dso_local constant i64, align 8

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK11StringPiece5rfindERKS_m(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(12) %1, i64 noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %class.StringPiece, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.StringPiece, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %3
  %21 = load i64, ptr @_ZN11StringPiece4nposE, align 8, !tbaa !9
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %4, align 4
  br label %83

23:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = getelementptr inbounds %class.StringPiece, ptr %13, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.StringPiece, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %23
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %82

35:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %36 = getelementptr inbounds %class.StringPiece, ptr %13, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.StringPiece, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = sub i64 %38, %42
  store i64 %43, ptr %11, align 8, !tbaa !9
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %37, i64 %45
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.StringPiece, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %46, i64 %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  store ptr %51, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %52 = getelementptr inbounds %class.StringPiece, ptr %13, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %class.StringPiece, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %class.StringPiece, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.StringPiece, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %60, i64 %64
  %66 = call noundef ptr @_ZSt8find_endIPKcS1_ET_S2_S2_T0_S3_(ptr noundef %53, ptr noundef %54, ptr noundef %57, ptr noundef %65)
  store ptr %66, ptr %12, align 8, !tbaa !5
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = icmp ne ptr %67, %68
  br i1 %69, label %70, label %77

70:                                               ; preds = %35
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.StringPiece, ptr %13, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !14
  %74 = ptrtoint ptr %71 to i64
  %75 = ptrtoint ptr %73 to i64
  %76 = sub i64 %74, %75
  br label %79

77:                                               ; preds = %35
  %78 = load i64, ptr @_ZN11StringPiece4nposE, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %77, %70
  %80 = phi i64 [ %76, %70 ], [ %78, %77 ]
  %81 = trunc i64 %80 to i32
  store i32 %81, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %82

82:                                               ; preds = %79, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %83

83:                                               ; preds = %82, %20
  %84 = load i32, ptr %4, align 4
  ret i32 %84
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt8find_endIPKcS1_ET_S2_S2_T0_S3_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS11StringPiece", !6, i64 0, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 0}


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

@_ZN11StringPiece4nposE = external dso_local local_unnamed_addr constant i64, align 8

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK11StringPiece5rfindERKS_m(ptr nocapture noundef nonnull readonly align 8 dereferenceable(12) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(12) %1, i64 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %2, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %12, label %14

12:                                               ; preds = %3
  %13 = load i64, ptr @_ZN11StringPiece4nposE, align 8, !tbaa !5
  br label %41

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %15 = sext i32 %8 to i64
  store i64 %15, ptr %5, align 8, !tbaa !5
  %16 = icmp eq i32 %10, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %19 = load i64, ptr %18, align 8, !tbaa !5
  br label %40

20:                                               ; preds = %14
  %21 = load ptr, ptr %0, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %22 = sext i32 %10 to i64
  %23 = sub nsw i64 %15, %22
  store i64 %23, ptr %6, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %21, i64 %25
  %27 = load i32, ptr %9, align 8, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %26, i64 %28
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  %31 = load ptr, ptr %1, align 8, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %31, i64 %28
  %33 = call noundef ptr @_ZSt8find_endIPKcS1_ET_S2_S2_T0_S3_(ptr noundef %30, ptr noundef %29, ptr noundef %31, ptr noundef %32)
  %.not = icmp eq ptr %33, %29
  %34 = load ptr, ptr %0, align 8
  %35 = ptrtoint ptr %33 to i64
  %36 = ptrtoint ptr %34 to i64
  %37 = sub i64 %35, %36
  %38 = load i64, ptr @_ZN11StringPiece4nposE, align 8
  %39 = select i1 %.not, i64 %38, i64 %37
  br label %40

40:                                               ; preds = %20, %17
  %.0.in = phi i64 [ %19, %17 ], [ %39, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %41

41:                                               ; preds = %40, %12
  %.1.in = phi i64 [ %13, %12 ], [ %.0.in, %40 ]
  %.1 = trunc i64 %.1.in to i32
  ret i32 %.1
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt8find_endIPKcS1_ET_S2_S2_T0_S3_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"_ZTS11StringPiece", !11, i64 0, !12, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass