; LLVM IR from abobija/esp-discord :: src/helpers (estr)

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

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

24:                                               ; preds = %21, %18, %3
  store ptr null, ptr %4, align 8
  br label %106

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i64 @strlen(ptr noundef %26) #6
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %11, align 4, !tbaa !9
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  store ptr null, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %105

32:                                               ; preds = %25
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call i64 @strlen(ptr noundef %33) #6
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %12, align 4, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %36, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %47, %32
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call ptr @strstr(ptr noundef %38, ptr noundef %39) #6
  store ptr %40, ptr %10, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %50

42:                                               ; preds = %37
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  store ptr %46, ptr %9, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %42
  %48 = load i32, ptr %14, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %14, align 4, !tbaa !9
  br label %37, !llvm.loop !11

50:                                               ; preds = %37
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i64 @strlen(ptr noundef %51) #6
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sub nsw i32 %53, %54
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = mul nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = add i64 %52, %58
  %60 = add i64 %59, 1
  %61 = call noalias ptr @malloc(i64 noundef %60) #7
  store ptr %61, ptr %8, align 8, !tbaa !5
  store ptr %61, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %65, label %64

64:                                               ; preds = %50
  store ptr null, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %105

65:                                               ; preds = %50
  br label %66

66:                                               ; preds = %70, %65
  %67 = load i32, ptr %14, align 4, !tbaa !9
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %14, align 4, !tbaa !9
  %69 = icmp ne i32 %67, 0
  br i1 %69, label %70, label %100

70:                                               ; preds = %66
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = call ptr @strstr(ptr noundef %71, ptr noundef %72) #6
  store ptr %73, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = ptrtoint ptr %74 to i64
  %77 = ptrtoint ptr %75 to i64
  %78 = sub i64 %76, %77
  %79 = trunc i64 %78 to i32
  store i32 %79, ptr %13, align 4, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %13, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = call ptr @strncpy(ptr noundef %80, ptr noundef %81, i64 noundef %83) #5
  %85 = load i32, ptr %13, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %84, i64 %86
  store ptr %87, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = call ptr @strcpy(ptr noundef %88, ptr noundef %89) #5
  %91 = load i32, ptr %12, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %90, i64 %92
  store ptr %93, ptr %10, align 8, !tbaa !5
  %94 = load i32, ptr %13, align 4, !tbaa !9
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = add nsw i32 %94, %95
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = sext i32 %96 to i64
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  store ptr %99, ptr %5, align 8, !tbaa !5
  br label %66, !llvm.loop !13

100:                                              ; preds = %66
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = call ptr @strcpy(ptr noundef %101, ptr noundef %102) #5
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %104, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %105

105:                                              ; preds = %100, %64, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %106

106:                                              ; preds = %105, %24
  %107 = load ptr, ptr %4, align 8
  ret ptr %107
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #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 = { nounwind allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @estr_rep(ptr noundef %0, ptr noundef readonly %1, ptr noundef readonly %2) local_unnamed_addr #2 {
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %4, %5
  %6 = icmp ne ptr %2, null
  %or.cond3 = and i1 %or.cond, %6
  br i1 %or.cond3, label %7, label %44

7:                                                ; preds = %3
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %9 = trunc i64 %8 to i32
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %44, label %11

11:                                               ; preds = %7
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  %13 = trunc i64 %12 to i32
  %14 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %1) #4
  %.not54 = icmp eq ptr %14, null
  br i1 %.not54, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %sext53 = shl i64 %8, 32
  %15 = ashr exact i64 %sext53, 32
  br label %16

16:                                               ; preds = %.lr.ph, %16
  %17 = phi ptr [ %14, %.lr.ph ], [ %20, %16 ]
  %.055 = phi i32 [ 0, %.lr.ph ], [ %19, %16 ]
  %18 = getelementptr inbounds i8, ptr %17, i64 %15
  %19 = add nuw nsw i32 %.055, 1
  %20 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %18, ptr noundef nonnull dereferenceable(1) %1) #4
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %._crit_edge, label %16, !llvm.loop !5

._crit_edge:                                      ; preds = %16, %11
  %.0.lcssa = phi i32 [ 0, %11 ], [ %19, %16 ]
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %22 = sub nsw i32 %13, %9
  %23 = mul nsw i32 %.0.lcssa, %22
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %24, 1
  %26 = add i64 %25, %21
  %27 = tail call noalias ptr @malloc(i64 noundef %26) #5
  %.not49 = icmp eq ptr %27, null
  br i1 %.not49, label %44, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %.not5056 = icmp eq i32 %.0.lcssa, 0
  br i1 %.not5056, label %._crit_edge61, label %.lr.ph60

.lr.ph60:                                         ; preds = %.preheader
  %sext51 = shl i64 %12, 32
  %28 = ashr exact i64 %sext51, 32
  br label %29

29:                                               ; preds = %.lr.ph60, %29
  %.159 = phi i32 [ %.0.lcssa, %.lr.ph60 ], [ %30, %29 ]
  %.04058 = phi ptr [ %0, %.lr.ph60 ], [ %42, %29 ]
  %.04257 = phi ptr [ %27, %.lr.ph60 ], [ %39, %29 ]
  %30 = add nsw i32 %.159, -1
  %31 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %.04058, ptr noundef nonnull dereferenceable(1) %1) #4
  %32 = ptrtoint ptr %31 to i64
  %33 = ptrtoint ptr %.04058 to i64
  %34 = sub i64 %32, %33
  %sext = shl i64 %34, 32
  %35 = ashr exact i64 %sext, 32
  %36 = tail call ptr @strncpy(ptr noundef %.04257, ptr noundef %.04058, i64 noundef %35) #6
  %37 = getelementptr inbounds i8, ptr %.04257, i64 %35
  %38 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %37, ptr noundef nonnull dereferenceable(1) %2) #6
  %39 = getelementptr inbounds i8, ptr %37, i64 %28
  %40 = add i64 %34, %8
  %sext52 = shl i64 %40, 32
  %41 = ashr exact i64 %sext52, 32
  %42 = getelementptr inbounds i8, ptr %.04058, i64 %41
  %.not50 = icmp eq i32 %30, 0
  br i1 %.not50, label %._crit_edge61, label %29, !llvm.loop !7

._crit_edge61:                                    ; preds = %29, %.preheader
  %.042.lcssa = phi ptr [ %27, %.preheader ], [ %39, %29 ]
  %.040.lcssa = phi ptr [ %0, %.preheader ], [ %42, %29 ]
  %43 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %.042.lcssa, ptr noundef nonnull dereferenceable(1) %.040.lcssa) #6
  br label %44

44:                                               ; preds = %._crit_edge61, %7, %._crit_edge, %3
  %.139 = phi ptr [ null, %3 ], [ %27, %._crit_edge61 ], [ null, %7 ], [ null, %._crit_edge ]
  ret ptr %.139
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 willreturn memory(read) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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