; LLVM IR from nde-jesu/Doom_Nukem :: libft/srcs/string (ft_strsub)

; 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: nounwind uwtable
define dso_local ptr @ft_strsub(ptr noundef %0, i32 noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !11
  %15 = add i64 %14, 1
  %16 = mul i64 1, %15
  %17 = call noalias ptr @malloc(i64 noundef %16) #4
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %13, %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %43

20:                                               ; preds = %13
  br label %21

21:                                               ; preds = %25, %20
  %22 = load i64, ptr %7, align 8, !tbaa !11
  %23 = add i64 %22, -1
  store i64 %23, ptr %7, align 8, !tbaa !11
  %24 = icmp ugt i64 %22, 0
  br i1 %24, label %25, label %37

25:                                               ; preds = %21
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !9
  %29 = zext i32 %27 to i64
  %30 = getelementptr inbounds i8, ptr %26, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !9
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds i8, ptr %32, i64 %35
  store i8 %31, ptr %36, align 1, !tbaa !13
  br label %21, !llvm.loop !14

37:                                               ; preds = %21
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  store i8 0, ptr %41, align 1, !tbaa !13
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %42, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %43

43:                                               ; preds = %37, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %44 = load ptr, ptr %4, align 8
  ret ptr %44
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @ft_strsub(ptr noundef readonly %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %61, label %4

4:                                                ; preds = %3
  %5 = add i64 %2, 1
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #2
  %.not14 = icmp eq ptr %6, null
  br i1 %.not14, label %61, label %.preheader

.preheader:                                       ; preds = %4
  %.not1516 = icmp eq i64 %2, 0
  br i1 %.not1516, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %min.iters.check = icmp ult i64 %2, 32
  br i1 %min.iters.check, label %.lr.ph.preheader28, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %7 = add i64 %2, -1
  %8 = trunc i64 %7 to i32
  %9 = xor i32 %1, -1
  %10 = icmp ult i32 %9, %8
  %11 = icmp ugt i64 %7, 4294967295
  %12 = or i1 %10, %11
  br i1 %12, label %.lr.ph.preheader28, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %2, 8589934560
  %ind.end = trunc i64 %n.vec to i32
  %ind.end20 = and i64 %2, 31
  %.cast = trunc i64 %n.vec to i32
  %ind.end22 = add i32 %.cast, %1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %.cast25 = trunc i64 %index to i32
  %offset.idx26 = add i32 %.cast25, %1
  %13 = zext i32 %offset.idx26 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %wide.load27 = load <16 x i8>, ptr %15, align 1, !tbaa !5
  %16 = and i64 %index, 4294967264
  %17 = getelementptr inbounds i8, ptr %6, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <16 x i8> %wide.load, ptr %17, align 1, !tbaa !5
  store <16 x i8> %wide.load27, ptr %18, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %2
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph.preheader28

.lr.ph.preheader28:                               ; preds = %middle.block, %vector.scevcheck, %.lr.ph.preheader
  %.019.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01118.ph = phi i64 [ %2, %vector.scevcheck ], [ %2, %.lr.ph.preheader ], [ %ind.end20, %middle.block ]
  %.01217.ph = phi i32 [ %1, %vector.scevcheck ], [ %1, %.lr.ph.preheader ], [ %ind.end22, %middle.block ]
  %20 = add i64 %.01118.ph, -1
  %xtraiter = and i64 %.01118.ph, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader28, %.lr.ph.prol
  %.019.prol = phi i32 [ %26, %.lr.ph.prol ], [ %.019.ph, %.lr.ph.preheader28 ]
  %.01118.prol = phi i64 [ %21, %.lr.ph.prol ], [ %.01118.ph, %.lr.ph.preheader28 ]
  %.01217.prol = phi i32 [ %22, %.lr.ph.prol ], [ %.01217.ph, %.lr.ph.preheader28 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader28 ]
  %21 = add i64 %.01118.prol, -1
  %22 = add i32 %.01217.prol, 1
  %23 = zext i32 %.01217.prol to i64
  %24 = getelementptr inbounds i8, ptr %0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = add i32 %.019.prol, 1
  %27 = zext i32 %.019.prol to i64
  %28 = getelementptr inbounds i8, ptr %6, i64 %27
  store i8 %25, ptr %28, align 1, !tbaa !5
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !12

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader28
  %.lcssa29.unr = phi i32 [ poison, %.lr.ph.preheader28 ], [ %26, %.lr.ph.prol ]
  %.019.unr = phi i32 [ %.019.ph, %.lr.ph.preheader28 ], [ %26, %.lr.ph.prol ]
  %.01118.unr = phi i64 [ %.01118.ph, %.lr.ph.preheader28 ], [ %21, %.lr.ph.prol ]
  %.01217.unr = phi i32 [ %.01217.ph, %.lr.ph.preheader28 ], [ %22, %.lr.ph.prol ]
  %29 = icmp ult i64 %20, 3
  br i1 %29, label %._crit_edge.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.019 = phi i32 [ %56, %.lr.ph ], [ %.019.unr, %.lr.ph.prol.loopexit ]
  %.01118 = phi i64 [ %51, %.lr.ph ], [ %.01118.unr, %.lr.ph.prol.loopexit ]
  %.01217 = phi i32 [ %52, %.lr.ph ], [ %.01217.unr, %.lr.ph.prol.loopexit ]
  %30 = add i32 %.01217, 1
  %31 = zext i32 %.01217 to i64
  %32 = getelementptr inbounds i8, ptr %0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = add i32 %.019, 1
  %35 = zext i32 %.019 to i64
  %36 = getelementptr inbounds i8, ptr %6, i64 %35
  store i8 %33, ptr %36, align 1, !tbaa !5
  %37 = add i32 %.01217, 2
  %38 = zext i32 %30 to i64
  %39 = getelementptr inbounds i8, ptr %0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %41 = add i32 %.019, 2
  %42 = zext i32 %34 to i64
  %43 = getelementptr inbounds i8, ptr %6, i64 %42
  store i8 %40, ptr %43, align 1, !tbaa !5
  %44 = add i32 %.01217, 3
  %45 = zext i32 %37 to i64
  %46 = getelementptr inbounds i8, ptr %0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = add i32 %.019, 3
  %49 = zext i32 %41 to i64
  %50 = getelementptr inbounds i8, ptr %6, i64 %49
  store i8 %47, ptr %50, align 1, !tbaa !5
  %51 = add i64 %.01118, -4
  %52 = add i32 %.01217, 4
  %53 = zext i32 %44 to i64
  %54 = getelementptr inbounds i8, ptr %0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = add i32 %.019, 4
  %57 = zext i32 %48 to i64
  %58 = getelementptr inbounds i8, ptr %6, i64 %57
  store i8 %55, ptr %58, align 1, !tbaa !5
  %.not15.3 = icmp eq i64 %51, 0
  br i1 %.not15.3, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %ind.end, %middle.block ], [ %.lcssa29.unr, %.lr.ph.prol.loopexit ], [ %56, %.lr.ph ]
  %59 = zext i32 %.lcssa to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %59, %._crit_edge.loopexit ]
  %60 = getelementptr inbounds i8, ptr %6, i64 %.0.lcssa
  store i8 0, ptr %60, align 1, !tbaa !5
  br label %61

61:                                               ; preds = %3, %4, %._crit_edge
  %.010 = phi ptr [ %6, %._crit_edge ], [ null, %4 ], [ null, %3 ]
  ret ptr %.010
}

; 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

attributes #0 = { nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) 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 #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !9, !10}


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