; LLVM IR from AdrianWR/push_swap :: libft/src (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 i32, align 4
  %7 = alloca i32, align 4
  %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 ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, 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
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %16

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

16:                                               ; preds = %13, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %79

17:                                               ; preds = %13
  store i32 -1, ptr %6, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call i64 @ft_strlen(ptr noundef %18)
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %7, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i64 @ft_strlen(ptr noundef %21)
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = add nsw i32 %24, %25
  %27 = add nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = mul i64 %28, 1
  %30 = call noalias ptr @malloc(i64 noundef %29) #5
  store ptr %30, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %17
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %79

34:                                               ; preds = %17
  br label %35

35:                                               ; preds = %43, %34
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %36, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %35
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  store i8 %48, ptr %52, align 1, !tbaa !11
  br label %35, !llvm.loop !12

53:                                               ; preds = %35
  store i32 -1, ptr %6, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %62, %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %55, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %62, label %73

62:                                               ; preds = %54
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !11
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %7, align 4, !tbaa !9
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds i8, ptr %68, i64 %71
  store i8 %67, ptr %72, align 1, !tbaa !11
  br label %54, !llvm.loop !14

73:                                               ; preds = %54
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %74, i64 %76
  store i8 0, ptr %77, align 1, !tbaa !11
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %78, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %79

79:                                               ; preds = %73, %33, %16
  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 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %80 = load ptr, ptr %3, align 8
  ret ptr %80
}

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; 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 = !{!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 noalias noundef ptr @ft_strjoin(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 %25

5:                                                ; preds = %2
  %6 = tail call i64 @ft_strlen(ptr noundef nonnull %0) #3
  %7 = tail call i64 @ft_strlen(ptr noundef nonnull %1) #3
  %8 = add i64 %7, %6
  %9 = shl i64 %8, 32
  %sext = add i64 %9, 4294967296
  %10 = ashr exact i64 %sext, 32
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #4
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %25, label %.preheader31

.preheader31:                                     ; preds = %5
  %12 = load i8, ptr %0, align 1, !tbaa !5
  %.not2932 = icmp eq i8 %12, 0
  br i1 %.not2932, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.preheader31
  %13 = load i8, ptr %1, align 1, !tbaa !5
  %.not3033 = icmp eq i8 %13, 0
  br i1 %.not3033, label %._crit_edge, label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %.preheader
  %sext40 = shl i64 %6, 32
  %14 = ashr exact i64 %sext40, 32
  br label %.lr.ph35

.lr.ph:                                           ; preds = %.preheader31, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader31 ]
  %15 = phi i8 [ %18, %.lr.ph ], [ %12, %.preheader31 ]
  %16 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv
  store i8 %15, ptr %16, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not29 = icmp eq i8 %18, 0
  br i1 %.not29, label %.preheader, label %.lr.ph, !llvm.loop !8

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %.lr.ph35
  %indvars.iv38 = phi i64 [ %14, %.lr.ph35.preheader ], [ %indvars.iv.next39, %.lr.ph35 ]
  %indvars.iv36 = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next37, %.lr.ph35 ]
  %19 = phi i8 [ %13, %.lr.ph35.preheader ], [ %22, %.lr.ph35 ]
  %indvars.iv.next39 = add nsw i64 %indvars.iv38, 1
  %20 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv38
  store i8 %19, ptr %20, align 1, !tbaa !5
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %21 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next37
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %.not30 = icmp eq i8 %22, 0
  br i1 %.not30, label %._crit_edge, label %.lr.ph35, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph35, %.preheader
  %.024.lcssa.in = phi i64 [ %6, %.preheader ], [ %indvars.iv.next39, %.lr.ph35 ]
  %sext41 = shl i64 %.024.lcssa.in, 32
  %23 = ashr exact i64 %sext41, 32
  %24 = getelementptr inbounds i8, ptr %11, i64 %23
  store i8 0, ptr %24, align 1, !tbaa !5
  br label %25

25:                                               ; preds = %5, %2, %._crit_edge
  %.0 = phi ptr [ %11, %._crit_edge ], [ null, %2 ], [ null, %5 ]
  ret ptr %.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

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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass