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

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

11:                                               ; preds = %21, %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %11
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = icmp ne i64 %17, 0
  br label %19

19:                                               ; preds = %16, %11
  %20 = phi i1 [ false, %11 ], [ %18, %16 ]
  br i1 %20, label %21, label %28

21:                                               ; preds = %19
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = add i64 %24, -1
  store i64 %25, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !9
  br label %11, !llvm.loop !12

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %39, %28
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp ugt i64 %35, 1
  br label %37

37:                                               ; preds = %34, %29
  %38 = phi i1 [ false, %29 ], [ %36, %34 ]
  br i1 %38, label %39, label %47

39:                                               ; preds = %37
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %5, align 8, !tbaa !5
  %42 = load i8, ptr %40, align 1, !tbaa !11
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %4, align 8, !tbaa !5
  store i8 %42, ptr %43, align 1, !tbaa !11
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = add i64 %45, -1
  store i64 %46, ptr %6, align 8, !tbaa !9
  br label %29, !llvm.loop !14

47:                                               ; preds = %37
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %51, align 1, !tbaa !11
  br label %53

53:                                               ; preds = %50, %47
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = add i64 %54, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %56
}

; 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

; 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 = !{!"long", !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 i64 @ft_strlcat(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @ft_strlen(ptr noundef %1) #2
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %6 = icmp ne i8 %5, 0
  %7 = icmp ne i64 %2, 0
  %8 = and i1 %6, %7
  br i1 %8, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %3
  %.015.lcssa = phi i64 [ %2, %3 ], [ %14, %.lr.ph ]
  %.014.lcssa = phi ptr [ %0, %3 ], [ %13, %.lr.ph ]
  %.0.lcssa = phi i64 [ 0, %3 ], [ %15, %.lr.ph ]
  %9 = load i8, ptr %1, align 1, !tbaa !5
  %10 = icmp ne i8 %9, 0
  %11 = icmp ugt i64 %.015.lcssa, 1
  %12 = select i1 %10, i1 %11, i1 false
  br i1 %12, label %.lr.ph26, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.020 = phi i64 [ %15, %.lr.ph ], [ 0, %3 ]
  %.01419 = phi ptr [ %13, %.lr.ph ], [ %0, %3 ]
  %.01518 = phi i64 [ %14, %.lr.ph ], [ %2, %3 ]
  %13 = getelementptr inbounds i8, ptr %.01419, i64 1
  %14 = add i64 %.01518, -1
  %15 = add nuw i64 %.020, 1
  %16 = load i8, ptr %13, align 1, !tbaa !5
  %17 = icmp ne i8 %16, 0
  %18 = icmp ne i64 %14, 0
  %19 = select i1 %17, i1 %18, i1 false
  br i1 %19, label %.lr.ph, label %.preheader, !llvm.loop !8

.lr.ph26:                                         ; preds = %.preheader, %.lr.ph26
  %20 = phi i8 [ %24, %.lr.ph26 ], [ %9, %.preheader ]
  %.125 = phi ptr [ %22, %.lr.ph26 ], [ %.014.lcssa, %.preheader ]
  %.11624 = phi i64 [ %23, %.lr.ph26 ], [ %.015.lcssa, %.preheader ]
  %.01723 = phi ptr [ %21, %.lr.ph26 ], [ %1, %.preheader ]
  %21 = getelementptr inbounds i8, ptr %.01723, i64 1
  %22 = getelementptr inbounds i8, ptr %.125, i64 1
  store i8 %20, ptr %.125, align 1, !tbaa !5
  %23 = add i64 %.11624, -1
  %24 = load i8, ptr %21, align 1, !tbaa !5
  %25 = icmp ne i8 %24, 0
  %26 = icmp ugt i64 %23, 1
  %27 = select i1 %25, i1 %26, i1 false
  br i1 %27, label %.lr.ph26, label %._crit_edge.thread, !llvm.loop !10

._crit_edge:                                      ; preds = %.preheader
  %.not = icmp eq i64 %.015.lcssa, 0
  br i1 %.not, label %28, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph26, %._crit_edge
  %.1.lcssa36 = phi ptr [ %.014.lcssa, %._crit_edge ], [ %22, %.lr.ph26 ]
  store i8 0, ptr %.1.lcssa36, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %29 = add i64 %.0.lcssa, %4
  ret i64 %29
}

declare i64 @ft_strlen(ptr 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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass