; LLVM IR from simon-zerisenay/42_Push_Swap :: libft (ft_strjoin)

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

12:                                               ; preds = %2
  %13 = call noalias ptr @malloc(i64 noundef 1) #6
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  store i8 0, ptr %15, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %12, %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 @ft_strlen(ptr noundef %17)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @ft_strlen(ptr noundef %19)
  %21 = add i64 %18, %20
  %22 = add i64 %21, 1
  %23 = call noalias ptr @malloc(i64 noundef %22) #6
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %16
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

27:                                               ; preds = %16
  store i64 0, ptr %7, align 8, !tbaa !10
  br label %28

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

35:                                               ; preds = %28
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %7, align 8, !tbaa !10
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !10
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store i8 %39, ptr %42, align 1, !tbaa !9
  %43 = load i64, ptr %7, align 8, !tbaa !10
  %44 = add i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !10
  br label %28, !llvm.loop !12

45:                                               ; preds = %28
  store i64 0, ptr %8, align 8, !tbaa !10
  br label %46

46:                                               ; preds = %53, %45
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %8, align 8, !tbaa !10
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = sext i8 %50 to i32
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %63

53:                                               ; preds = %46
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !10
  %56 = add i64 %55, 1
  store i64 %56, ptr %8, align 8, !tbaa !10
  %57 = getelementptr inbounds i8, ptr %54, i64 %55
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %7, align 8, !tbaa !10
  %61 = add i64 %60, 1
  store i64 %61, ptr %7, align 8, !tbaa !10
  %62 = getelementptr inbounds i8, ptr %59, i64 %60
  store i8 %58, ptr %62, align 1, !tbaa !9
  br label %46, !llvm.loop !14

63:                                               ; preds = %46
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i64, ptr %7, align 8, !tbaa !10
  %66 = getelementptr inbounds i8, ptr %64, i64 %65
  store i8 0, ptr %66, align 1, !tbaa !9
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %67) #5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %68, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %63, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %70 = load ptr, ptr %3, align 8
  ret ptr %70
}

; 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

declare i64 @ft_strlen(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

; 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 "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 #5 = { nounwind }
attributes #6 = { 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 = 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 noalias noundef ptr @ft_strjoin(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %5

3:                                                ; preds = %2
  %4 = tail call noalias dereferenceable_or_null(1) ptr @malloc(i64 noundef 1) #4
  store i8 0, ptr %4, align 1, !tbaa !5
  br label %5

5:                                                ; preds = %3, %2
  %.024 = phi ptr [ %0, %2 ], [ %4, %3 ]
  %6 = tail call i64 @ft_strlen(ptr noundef nonnull %.024) #5
  %7 = tail call i64 @ft_strlen(ptr noundef %1) #5
  %8 = add i64 %6, 1
  %9 = add i64 %8, %7
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #4
  %.not27 = icmp eq ptr %10, null
  br i1 %.not27, label %25, label %.preheader30

.preheader30:                                     ; preds = %5
  %11 = load i8, ptr %.024, align 1, !tbaa !5
  %.not2831 = icmp eq i8 %11, 0
  br i1 %.not2831, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.preheader30
  %.022.lcssa = phi i64 [ 0, %.preheader30 ], [ %15, %.lr.ph ]
  %12 = load i8, ptr %1, align 1, !tbaa !5
  %.not2933 = icmp eq i8 %12, 0
  br i1 %.not2933, label %._crit_edge, label %.lr.ph36

.lr.ph:                                           ; preds = %.preheader30, %.lr.ph
  %13 = phi i8 [ %17, %.lr.ph ], [ %11, %.preheader30 ]
  %.02232 = phi i64 [ %15, %.lr.ph ], [ 0, %.preheader30 ]
  %14 = getelementptr inbounds i8, ptr %10, i64 %.02232
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = add i64 %.02232, 1
  %16 = getelementptr inbounds i8, ptr %.024, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not28 = icmp eq i8 %17, 0
  br i1 %.not28, label %.preheader, label %.lr.ph, !llvm.loop !8

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %18 = phi i8 [ %23, %.lr.ph36 ], [ %12, %.preheader ]
  %.035 = phi i64 [ %19, %.lr.ph36 ], [ 0, %.preheader ]
  %.134 = phi i64 [ %20, %.lr.ph36 ], [ %.022.lcssa, %.preheader ]
  %19 = add i64 %.035, 1
  %20 = add i64 %.134, 1
  %21 = getelementptr inbounds i8, ptr %10, i64 %.134
  store i8 %18, ptr %21, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 %19
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %.not29 = icmp eq i8 %23, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph36, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph36, %.preheader
  %.1.lcssa = phi i64 [ %.022.lcssa, %.preheader ], [ %20, %.lr.ph36 ]
  %24 = getelementptr inbounds i8, ptr %10, i64 %.1.lcssa
  store i8 0, ptr %24, align 1, !tbaa !5
  tail call void @free(ptr noundef %.024) #5
  br label %25

25:                                               ; preds = %5, %._crit_edge
  ret ptr %10
}

; 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

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass