; LLVM IR from openxrlab/xrsfm :: 3rdparty/apriltag/common (string_util)

; 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.1 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.str_replace = external hidden unnamed_addr constant [60 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare dso_local zeroext i1 @str_starts_with(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @string_buffer_to_string(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_append(ptr noundef, i8 noundef signext) #4

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_destroy(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local ptr @string_buffer_create() #4

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_append_string(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @str_replace(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 607, ptr noundef @__PRETTY_FUNCTION__.str_replace) #5
  unreachable

16:                                               ; preds = %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %21

20:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 608, ptr noundef @__PRETTY_FUNCTION__.str_replace) #5
  unreachable

21:                                               ; preds = %19
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %26

25:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.21, ptr noundef @.str.1, i32 noundef 609, ptr noundef @__PRETTY_FUNCTION__.str_replace) #5
  unreachable

26:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %27 = call ptr @string_buffer_create()
  store ptr %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i64 @strlen(ptr noundef %28) #7
  store i64 %29, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i64 @strlen(ptr noundef %30) #7
  store i64 %31, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %64, %26
  %33 = load i32, ptr %10, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %37, label %65

37:                                               ; preds = %32
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 0
  br i1 %39, label %40, label %55

40:                                               ; preds = %37
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call zeroext i1 @str_starts_with(ptr noundef %44, ptr noundef %45)
  br i1 %46, label %47, label %55

47:                                               ; preds = %40
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @string_buffer_append_string(ptr noundef %48, ptr noundef %49)
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = add i64 %52, %50
  %54 = trunc i64 %53 to i32
  store i32 %54, ptr %10, align 4, !tbaa !11
  br label %64

55:                                               ; preds = %40, %37
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !13
  call void @string_buffer_append(ptr noundef %56, i8 noundef signext %61)
  %62 = load i32, ptr %10, align 4, !tbaa !11
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !11
  br label %64

64:                                               ; preds = %55, %47
  br label %32, !llvm.loop !14

65:                                               ; preds = %32
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = icmp eq i64 %66, 0
  br i1 %67, label %68, label %74

68:                                               ; preds = %65
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = icmp eq i64 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  call void @string_buffer_append_string(ptr noundef %72, ptr noundef %73)
  br label %74

74:                                               ; preds = %71, %68, %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = call ptr @string_buffer_to_string(ptr noundef %75)
  store ptr %76, ptr %11, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  call void @string_buffer_destroy(ptr noundef %77)
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret ptr %78
}

attributes #0 = { noreturn 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 #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 = { inlinehint 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 #4 = { 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 #5 = { noreturn nounwind }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !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.1 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.str_replace = external hidden unnamed_addr constant [60 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint nounwind uwtable
declare dso_local zeroext i1 @str_starts_with(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @string_buffer_to_string(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_append(ptr noundef, i8 noundef signext) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_destroy(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @string_buffer_create() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @string_buffer_append_string(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @str_replace(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 607, ptr noundef nonnull @__PRETTY_FUNCTION__.str_replace) #4
  unreachable

5:                                                ; preds = %3
  %.not32 = icmp eq ptr %1, null
  br i1 %.not32, label %6, label %7

6:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 608, ptr noundef nonnull @__PRETTY_FUNCTION__.str_replace) #4
  unreachable

7:                                                ; preds = %5
  %.not33 = icmp eq ptr %2, null
  br i1 %.not33, label %8, label %9

8:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.1, i32 noundef 609, ptr noundef nonnull @__PRETTY_FUNCTION__.str_replace) #4
  unreachable

9:                                                ; preds = %7
  %10 = tail call ptr @string_buffer_create()
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %.not36 = icmp eq i64 %11, 0
  br i1 %.not36, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %.not34 = icmp eq i64 %12, 0
  %13 = trunc i64 %12 to i32
  br i1 %.not34, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %14 = phi i64 [ %17, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %.035.us = phi i32 [ %.1.us, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  tail call void @string_buffer_append(ptr noundef %10, i8 noundef signext %16)
  %.1.us = add i32 %.035.us, 1
  %17 = sext i32 %.1.us to i64
  %18 = icmp ugt i64 %11, %17
  br i1 %18, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !8

.lr.ph.split:                                     ; preds = %.lr.ph, %25
  %19 = phi i64 [ %26, %25 ], [ 0, %.lr.ph ]
  %.035 = phi i32 [ %.1, %25 ], [ 0, %.lr.ph ]
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  %21 = tail call zeroext i1 @str_starts_with(ptr noundef nonnull %20, ptr noundef nonnull %1)
  br i1 %21, label %22, label %23

22:                                               ; preds = %.lr.ph.split
  tail call void @string_buffer_append_string(ptr noundef %10, ptr noundef nonnull %2)
  br label %25

23:                                               ; preds = %.lr.ph.split
  %24 = load i8, ptr %20, align 1, !tbaa !5
  tail call void @string_buffer_append(ptr noundef %10, i8 noundef signext %24)
  br label %25

25:                                               ; preds = %23, %22
  %.pn = phi i32 [ %13, %22 ], [ 1, %23 ]
  %.1 = add i32 %.pn, %.035
  %26 = sext i32 %.1 to i64
  %27 = icmp ugt i64 %11, %26
  br i1 %27, label %.lr.ph.split, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %25, %.lr.ph.split.us, %9
  %28 = or i64 %12, %11
  %or.cond = icmp eq i64 %28, 0
  br i1 %or.cond, label %29, label %30

29:                                               ; preds = %._crit_edge
  tail call void @string_buffer_append_string(ptr noundef %10, ptr noundef nonnull %2)
  br label %30

30:                                               ; preds = %29, %._crit_edge
  %31 = tail call ptr @string_buffer_to_string(ptr noundef %10)
  tail call void @string_buffer_destroy(ptr noundef %10)
  ret ptr %31
}

attributes #0 = { noreturn 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 #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 = { inlinehint 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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"}


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