; LLVM IR from yettabaa/FdF :: libft_fdf (ft_strtrim)

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

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

15:                                               ; preds = %11
  store i32 -1, ptr %6, align 4, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i64 @ft_strlen(ptr noundef %16)
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %38, %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %39

27:                                               ; preds = %19
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = call ptr @ft_strchr(ptr noundef %28, i32 noundef %34)
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %27
  br label %39

38:                                               ; preds = %27
  br label %19, !llvm.loop !12

39:                                               ; preds = %37, %19
  br label %40

40:                                               ; preds = %55, %39
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %7, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %56

44:                                               ; preds = %40
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = sext i8 %50 to i32
  %52 = call ptr @ft_strchr(ptr noundef %45, i32 noundef %51)
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %44
  br label %56

55:                                               ; preds = %44
  br label %40, !llvm.loop !14

56:                                               ; preds = %54, %40
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = sub nsw i32 %60, %61
  %63 = sext i32 %62 to i64
  %64 = call ptr @ft_substr(ptr noundef %57, i32 noundef %58, i64 noundef %63)
  store ptr %64, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

65:                                               ; preds = %56, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %66 = load ptr, ptr %3, align 8
  ret ptr %66
}

; 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_strchr(ptr noundef, i32 noundef) #2

declare ptr @ft_substr(ptr noundef, i32 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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_strtrim(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %26

5:                                                ; preds = %2
  %6 = tail call i64 @ft_strlen(ptr noundef nonnull %0) #2
  br label %7

7:                                                ; preds = %10, %5
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ -1, %5 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %13, label %10

10:                                               ; preds = %7
  %11 = sext i8 %9 to i32
  %12 = tail call ptr @ft_strchr(ptr noundef nonnull %1, i32 noundef %11) #2
  %.not23 = icmp eq ptr %12, null
  br i1 %.not23, label %13, label %7, !llvm.loop !8

13:                                               ; preds = %10, %7
  %14 = trunc nuw nsw i64 %indvars.iv.next to i32
  %sext = shl i64 %6, 32
  %15 = ashr exact i64 %sext, 32
  br label %16

16:                                               ; preds = %17, %13
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %17 ], [ %15, %13 ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %.not24 = icmp eq i64 %indvars.iv.next28, 0
  br i1 %.not24, label %22, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next28
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = sext i8 %19 to i32
  %21 = tail call ptr @ft_strchr(ptr noundef nonnull %1, i32 noundef %20) #2
  %.not25 = icmp eq ptr %21, null
  br i1 %.not25, label %22, label %16, !llvm.loop !10

22:                                               ; preds = %17, %16
  %23 = sub i64 %indvars.iv27, %indvars.iv.next
  %sext30 = shl i64 %23, 32
  %24 = ashr exact i64 %sext30, 32
  %25 = tail call ptr @ft_substr(ptr noundef nonnull %0, i32 noundef %14, i64 noundef %24) #2
  br label %26

26:                                               ; preds = %2, %22
  %.018 = phi ptr [ %25, %22 ], [ null, %2 ]
  ret ptr %.018
}

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #1

declare ptr @ft_strchr(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @ft_substr(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #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 = { "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 }

!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"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass