; LLVM IR from bnidia/push_swap :: libraries/libft (ft_substr)

; 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_substr(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 i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = 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 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i64 @ft_strlen(ptr noundef %13)
  store i64 %14, ptr %10, align 8, !tbaa !11
  %15 = load i64, ptr %10, align 8, !tbaa !11
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = icmp ult i64 %15, %17
  br i1 %18, label %22, label %19

19:                                               ; preds = %3
  %20 = load i64, ptr %7, align 8, !tbaa !11
  %21 = icmp ule i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %19, %3
  %23 = call ptr @ft_calloc(i64 noundef 1, i64 noundef 1)
  store ptr %23, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %74

24:                                               ; preds = %19
  %25 = load i64, ptr %7, align 8, !tbaa !11
  %26 = load i64, ptr %10, align 8, !tbaa !11
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = sub i64 %26, %28
  %30 = icmp ult i64 %25, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %24
  %32 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %32, ptr %11, align 8, !tbaa !11
  br label %38

33:                                               ; preds = %24
  %34 = load i64, ptr %10, align 8, !tbaa !11
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = sub i64 %34, %36
  store i64 %37, ptr %11, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %33, %31
  %39 = load i64, ptr %11, align 8, !tbaa !11
  %40 = add i64 %39, 1
  %41 = call ptr @ft_calloc(i64 noundef 1, i64 noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %56, %38
  %43 = load i64, ptr %7, align 8, !tbaa !11
  %44 = add i64 %43, -1
  store i64 %44, ptr %7, align 8, !tbaa !11
  %45 = icmp ne i64 %43, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %42
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  %53 = icmp ne i32 %52, 0
  br label %54

54:                                               ; preds = %46, %42
  %55 = phi i1 [ false, %42 ], [ %53, %46 ]
  br i1 %55, label %56, label %68

56:                                               ; preds = %54
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = add i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !9
  %60 = zext i32 %58 to i64
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !9
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds i8, ptr %63, i64 %66
  store i8 %62, ptr %67, align 1, !tbaa !13
  br label %42, !llvm.loop !14

68:                                               ; preds = %54
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  store i8 0, ptr %72, align 1, !tbaa !13
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %73, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %74

74:                                               ; preds = %68, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %75 = load ptr, ptr %4, align 8
  ret ptr %75
}

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

declare i64 @ft_strlen(ptr noundef) #2

declare ptr @ft_calloc(i64 noundef, 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 = { "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 }

!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: nounwind uwtable
define dso_local ptr @ft_substr(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @ft_strlen(ptr noundef %0) #3
  %5 = zext i32 %1 to i64
  %6 = icmp ult i64 %4, %5
  %7 = icmp eq i64 %2, 0
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %8, label %10

8:                                                ; preds = %3
  %9 = tail call ptr @ft_calloc(i64 noundef 1, i64 noundef 1) #3
  br label %24

10:                                               ; preds = %3
  %11 = sub i64 %4, %5
  %. = tail call i64 @llvm.umin.i64(i64 %11, i64 %2)
  %12 = add i64 %., 1
  %13 = tail call ptr @ft_calloc(i64 noundef 1, i64 noundef %12) #3
  br label %14

14:                                               ; preds = %10, %18
  %indvars.iv = phi i64 [ 0, %10 ], [ %indvars.iv.next, %18 ]
  %.in = phi i64 [ %2, %10 ], [ %19, %18 ]
  %.02332 = phi i32 [ %1, %10 ], [ %20, %18 ]
  %15 = zext i32 %.02332 to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not30 = icmp eq i8 %17, 0
  br i1 %.not30, label %.critedge, label %18

18:                                               ; preds = %14
  %19 = add i64 %.in, -1
  %20 = add i32 %.02332, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv
  store i8 %17, ptr %21, align 1, !tbaa !5
  %.not = icmp eq i64 %19, 0
  br i1 %.not, label %.critedge, label %14, !llvm.loop !8

.critedge:                                        ; preds = %18, %14
  %.024.lcssa.in = phi i64 [ %2, %18 ], [ %indvars.iv, %14 ]
  %22 = and i64 %.024.lcssa.in, 4294967295
  %23 = getelementptr inbounds i8, ptr %13, i64 %22
  store i8 0, ptr %23, align 1, !tbaa !5
  br label %24

24:                                               ; preds = %.critedge, %8
  %.022 = phi ptr [ %9, %8 ], [ %13, %.critedge ]
  ret ptr %.022
}

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #1

declare ptr @ft_calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

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 = { "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 nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass