; LLVM IR from wrnlb666/yet-another-string-library-in-c :: yasli (str_removed)

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

%struct.string_t = type { i64, i64, [1 x i8] }

; 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 nounwind uwtable
declare hidden zeroext i1 @str_resize(ptr noundef, i64 noundef) #1

; 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) #2

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

12:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %65

13:                                               ; preds = %3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = add i64 %14, %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.string_t, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp ugt i64 %16, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %13
  store ptr null, ptr %4, align 8
  br label %65

22:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr null, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.string_t, ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = sub i64 %25, %26
  %28 = call zeroext i1 @str_resize(ptr noundef %8, i64 noundef %27)
  br i1 %28, label %29, label %63

29:                                               ; preds = %22
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.string_t, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds [1 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.string_t, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds [1 x i8], ptr %34, i64 0, i64 0
  %36 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %32, ptr align 8 %35, i64 %36, i1 false)
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.string_t, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds [1 x i8], ptr %38, i64 0, i64 0
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.string_t, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds [1 x i8], ptr %43, i64 0, i64 0
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.string_t, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = sub i64 %51, %52
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = sub i64 %53, %54
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %41, ptr align 1 %48, i64 %55, i1 false)
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.string_t, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.string_t, ptr %58, i32 0, i32 0
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds [1 x i8], ptr %57, i64 0, i64 %60
  store i8 0, ptr %61, align 1, !tbaa !13
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %64

63:                                               ; preds = %22
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %64

64:                                               ; preds = %63, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %65

65:                                               ; preds = %64, %21, %12
  %66 = load ptr, ptr %4, align 8
  ret ptr %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"string_t", !10, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!7, !7, 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"

; 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 nounwind uwtable
declare hidden zeroext i1 @str_resize(ptr noundef, i64 noundef) local_unnamed_addr #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) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @str_removed(ptr noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %28, label %6

6:                                                ; preds = %3
  %7 = add i64 %2, %1
  %8 = load i64, ptr %0, align 8, !tbaa !5
  %9 = icmp ugt i64 %7, %8
  br i1 %9, label %28, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !10
  %11 = sub i64 %8, %2
  %12 = call zeroext i1 @str_resize(ptr noundef nonnull %4, i64 noundef %11)
  br i1 %12, label %13, label %27

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %15, ptr nonnull align 8 %16, i64 %1, i1 false)
  %17 = getelementptr inbounds i8, ptr %15, i64 %1
  %18 = getelementptr inbounds i8, ptr %16, i64 %1
  %19 = getelementptr inbounds i8, ptr %18, i64 %2
  %20 = load i64, ptr %0, align 8, !tbaa !5
  %21 = sub i64 %20, %7
  call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %17, ptr nonnull align 1 %19, i64 %21, i1 false)
  %22 = load ptr, ptr %4, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = load i64, ptr %22, align 8, !tbaa !5
  %25 = getelementptr inbounds [1 x i8], ptr %23, i64 0, i64 %24
  store i8 0, ptr %25, align 1, !tbaa !12
  %26 = load ptr, ptr %4, align 8, !tbaa !10
  br label %27

27:                                               ; preds = %10, %13
  %.0 = phi ptr [ %26, %13 ], [ null, %10 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %28

28:                                               ; preds = %6, %3, %27
  %.1 = phi ptr [ %.0, %27 ], [ null, %3 ], [ null, %6 ]
  ret ptr %.1
}

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


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