; LLVM IR from AdrianWR/push_swap :: libft/src (ft_split)

; 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_split(ptr noundef %0, i8 noundef signext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %6, align 8, !tbaa !10
  store i64 0, ptr %7, align 8, !tbaa !10
  store i32 -1, ptr %8, align 4, !tbaa !12
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = call i32 @word_count(ptr noundef %11, i8 noundef signext %12)
  %14 = add nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = mul i64 %15, 8
  %17 = call noalias ptr @malloc(i64 noundef %16) #5
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %78

21:                                               ; preds = %2
  br label %22

22:                                               ; preds = %70, %21
  %23 = load i64, ptr %6, align 8, !tbaa !10
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i64 @ft_strlen(ptr noundef %24)
  %26 = icmp ule i64 %23, %25
  br i1 %26, label %27, label %73

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %6, align 8, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = load i8, ptr %5, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp ne i32 %32, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %27
  %37 = load i32, ptr %8, align 4, !tbaa !12
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load i64, ptr %6, align 8, !tbaa !10
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %8, align 4, !tbaa !12
  br label %70

42:                                               ; preds = %36, %27
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %6, align 8, !tbaa !10
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = load i8, ptr %5, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %47, %49
  br i1 %50, label %56, label %51

51:                                               ; preds = %42
  %52 = load i64, ptr %6, align 8, !tbaa !10
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = call i64 @ft_strlen(ptr noundef %53)
  %55 = icmp eq i64 %52, %54
  br i1 %55, label %56, label %69

56:                                               ; preds = %51, %42
  %57 = load i32, ptr %8, align 4, !tbaa !12
  %58 = icmp sge i32 %57, 0
  br i1 %58, label %59, label %69

59:                                               ; preds = %56
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !12
  %62 = load i64, ptr %6, align 8, !tbaa !10
  %63 = trunc i64 %62 to i32
  %64 = call ptr @word_dup(ptr noundef %60, i32 noundef %61, i32 noundef %63)
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load i64, ptr %7, align 8, !tbaa !10
  %67 = add i64 %66, 1
  store i64 %67, ptr %7, align 8, !tbaa !10
  %68 = getelementptr inbounds ptr, ptr %65, i64 %66
  store ptr %64, ptr %68, align 8, !tbaa !5
  store i32 -1, ptr %8, align 4, !tbaa !12
  br label %69

69:                                               ; preds = %59, %56, %51
  br label %70

70:                                               ; preds = %69, %39
  %71 = load i64, ptr %6, align 8, !tbaa !10
  %72 = add i64 %71, 1
  store i64 %72, ptr %6, align 8, !tbaa !10
  br label %22, !llvm.loop !14

73:                                               ; preds = %22
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load i64, ptr %7, align 8, !tbaa !10
  %76 = getelementptr inbounds ptr, ptr %74, i64 %75
  store ptr null, ptr %76, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %77, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %78

78:                                               ; preds = %73, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %79 = load ptr, ptr %3, align 8
  ret ptr %79
}

; 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: nounwind uwtable
declare hidden i32 @word_count(ptr noundef, i8 noundef signext) #0

declare i64 @ft_strlen(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @word_dup(ptr noundef, i32 noundef, i32 noundef) #0

; 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 = { "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 }
attributes #5 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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 noalias noundef ptr @ft_split(ptr noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  %3 = tail call i32 @word_count(ptr noundef %0, i8 noundef signext %1)
  %4 = add nsw i32 %3, 1
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %33, label %.preheader

.preheader:                                       ; preds = %2
  %8 = tail call i64 @ft_strlen(ptr noundef %0) #4
  br label %9

9:                                                ; preds = %.preheader, %28
  %.02936 = phi i32 [ -1, %.preheader ], [ %.1, %28 ]
  %.03035 = phi i64 [ 0, %.preheader ], [ %.131, %28 ]
  %.03234 = phi i64 [ 0, %.preheader ], [ %29, %28 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 %.03234
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp ne i8 %11, %1
  %13 = icmp slt i32 %.02936, 0
  %or.cond = select i1 %12, i1 %13, i1 false
  br i1 %or.cond, label %14, label %16

14:                                               ; preds = %9
  %15 = trunc i64 %.03234 to i32
  br label %28

16:                                               ; preds = %9
  %17 = icmp eq i8 %11, %1
  br i1 %17, label %22, label %18

18:                                               ; preds = %16
  %19 = tail call i64 @ft_strlen(ptr noundef nonnull %0) #4
  %20 = icmp eq i64 %.03234, %19
  %21 = icmp sgt i32 %.02936, -1
  %or.cond3 = select i1 %20, i1 %21, i1 false
  br i1 %or.cond3, label %23, label %28

22:                                               ; preds = %16
  %.old2 = icmp sgt i32 %.02936, -1
  br i1 %.old2, label %23, label %28

23:                                               ; preds = %18, %22
  %24 = trunc i64 %.03234 to i32
  %25 = tail call ptr @word_dup(ptr noundef nonnull %0, i32 noundef %.02936, i32 noundef %24)
  %26 = add i64 %.03035, 1
  %27 = getelementptr inbounds ptr, ptr %7, i64 %.03035
  store ptr %25, ptr %27, align 8, !tbaa !8
  br label %28

28:                                               ; preds = %18, %22, %23, %14
  %.131 = phi i64 [ %.03035, %14 ], [ %26, %23 ], [ %.03035, %22 ], [ %.03035, %18 ]
  %.1 = phi i32 [ %15, %14 ], [ -1, %23 ], [ %.02936, %22 ], [ %.02936, %18 ]
  %29 = add i64 %.03234, 1
  %30 = tail call i64 @ft_strlen(ptr noundef nonnull %0) #4
  %.not33 = icmp ugt i64 %29, %30
  br i1 %.not33, label %31, label %9, !llvm.loop !10

31:                                               ; preds = %28
  %32 = getelementptr inbounds ptr, ptr %7, i64 %.131
  store ptr null, ptr %32, align 8, !tbaa !8
  br label %33

33:                                               ; preds = %2, %31
  ret ptr %7
}

; 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: nounwind uwtable
declare hidden i32 @word_count(ptr noundef, i8 noundef signext) local_unnamed_addr #0

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @word_dup(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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 = { 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 = { "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 allocsize(0) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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