; LLVM IR from 48d31kh413k/1337-push_swap-42 :: libft (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 i64, align 8
  %7 = alloca ptr, align 8
  %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 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %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
  br label %16

16:                                               ; preds = %29, %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %30

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @ft_check_set(i8 noundef signext %21, ptr noundef %22)
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %28

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %4, align 8, !tbaa !5
  br label %29

28:                                               ; preds = %19
  br label %30

29:                                               ; preds = %25
  br label %16, !llvm.loop !10

30:                                               ; preds = %28, %16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i64 @ft_strlen(ptr noundef %31)
  store i64 %32, ptr %6, align 8, !tbaa !12
  br label %33

33:                                               ; preds = %49, %30
  %34 = load i64, ptr %6, align 8, !tbaa !12
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %33
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i64, ptr %6, align 8, !tbaa !12
  %39 = sub i64 %38, 1
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @ft_check_set(i8 noundef signext %41, ptr noundef %42)
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %48

45:                                               ; preds = %36
  %46 = load i64, ptr %6, align 8, !tbaa !12
  %47 = add i64 %46, -1
  store i64 %47, ptr %6, align 8, !tbaa !12
  br label %49

48:                                               ; preds = %36
  br label %50

49:                                               ; preds = %45
  br label %33, !llvm.loop !14

50:                                               ; preds = %48, %33
  %51 = load i64, ptr %6, align 8, !tbaa !12
  %52 = mul i64 %51, 1
  %53 = add i64 %52, 1
  %54 = call noalias ptr @malloc(i64 noundef %53) #5
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %58, label %57

57:                                               ; preds = %50
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

58:                                               ; preds = %50
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i64, ptr %6, align 8, !tbaa !12
  %62 = add i64 %61, 1
  %63 = call i64 @ft_strlcpy(ptr noundef %59, ptr noundef %60, i64 noundef %62)
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %64, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %65

65:                                               ; preds = %58, %57, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %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

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

declare i64 @ft_strlen(ptr noundef) #2

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

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


; 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 noundef 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 %.preheader, label %23

.preheader:                                       ; preds = %2, %.preheader
  %.020 = phi ptr [ %8, %.preheader ], [ %0, %2 ]
  %5 = load i8, ptr %.020, align 1, !tbaa !5
  %6 = tail call i32 @ft_check_set(i8 noundef signext %5, ptr noundef nonnull %1)
  %7 = icmp eq i32 %6, 1
  %8 = getelementptr inbounds i8, ptr %.020, i64 1
  br i1 %7, label %.preheader, label %9, !llvm.loop !8

9:                                                ; preds = %.preheader
  %10 = tail call i64 @ft_strlen(ptr noundef nonnull %.020) #3
  br label %11

11:                                               ; preds = %12, %9
  %.019 = phi i64 [ %10, %9 ], [ %13, %12 ]
  %.not23 = icmp eq i64 %.019, 0
  br i1 %.not23, label %18, label %12

12:                                               ; preds = %11
  %13 = add i64 %.019, -1
  %14 = getelementptr inbounds i8, ptr %.020, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = tail call i32 @ft_check_set(i8 noundef signext %15, ptr noundef nonnull %1)
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %11, label %18, !llvm.loop !10

18:                                               ; preds = %12, %11
  %19 = add i64 %.019, 1
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #4
  %.not24 = icmp eq ptr %20, null
  br i1 %.not24, label %23, label %21

21:                                               ; preds = %18
  %22 = tail call i64 @ft_strlcpy(ptr noundef nonnull %20, ptr noundef nonnull %.020, i64 noundef %19) #3
  br label %23

23:                                               ; preds = %18, %2, %21
  %.0 = phi ptr [ %20, %21 ], [ null, %2 ], [ null, %18 ]
  ret ptr %.0
}

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

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare i64 @ft_strlcpy(ptr noundef, ptr 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 = { 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 #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 = !{!"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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass