; LLVM IR from LlimaV10/doom-nukem_v2 :: 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 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 %54

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

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

25:                                               ; preds = %14
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

26:                                               ; preds = %14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %7, align 8, !tbaa !5
  br label %28

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

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %4, align 8, !tbaa !5
  %36 = load i8, ptr %34, align 1, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %6, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !9
  br label %28, !llvm.loop !10

39:                                               ; preds = %28
  br label %40

40:                                               ; preds = %45, %39
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %51

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %5, align 8, !tbaa !5
  %48 = load i8, ptr %46, align 1, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %6, align 8, !tbaa !5
  store i8 %48, ptr %49, align 1, !tbaa !9
  br label %40, !llvm.loop !12

51:                                               ; preds = %40
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %52, align 1, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %53, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

54:                                               ; preds = %11, %2
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %60

57:                                               ; preds = %54
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = call ptr @ft_strdup(ptr noundef %58)
  store ptr %59, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

60:                                               ; preds = %54
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = call ptr @ft_strdup(ptr noundef %61)
  store ptr %62, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %60, %57, %51, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %64 = load ptr, ptr %3, align 8
  ret ptr %64
}

; 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

declare ptr @ft_strdup(ptr 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 = { 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 }
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 = distinct !{!12, !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 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 %22

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 %6, 1
  %9 = add i64 %8, %7
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #4
  %11 = icmp eq ptr %10, null
  br i1 %11, label %27, label %.preheader27

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

.preheader:                                       ; preds = %.lr.ph, %.preheader27
  %.019.lcssa = phi ptr [ %10, %.preheader27 ], [ %16, %.lr.ph ]
  %13 = load i8, ptr %1, align 1, !tbaa !5
  %.not2631 = icmp eq i8 %13, 0
  br i1 %.not2631, label %._crit_edge, label %.lr.ph34

.lr.ph:                                           ; preds = %.preheader27, %.lr.ph
  %14 = phi i8 [ %17, %.lr.ph ], [ %12, %.preheader27 ]
  %.01930 = phi ptr [ %16, %.lr.ph ], [ %10, %.preheader27 ]
  %.02129 = phi ptr [ %15, %.lr.ph ], [ %0, %.preheader27 ]
  %15 = getelementptr inbounds i8, ptr %.02129, i64 1
  %16 = getelementptr inbounds i8, ptr %.01930, i64 1
  store i8 %14, ptr %.01930, align 1, !tbaa !5
  %17 = load i8, ptr %15, align 1, !tbaa !5
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !8

.lr.ph34:                                         ; preds = %.preheader, %.lr.ph34
  %18 = phi i8 [ %21, %.lr.ph34 ], [ %13, %.preheader ]
  %.133 = phi ptr [ %20, %.lr.ph34 ], [ %.019.lcssa, %.preheader ]
  %.02032 = phi ptr [ %19, %.lr.ph34 ], [ %1, %.preheader ]
  %19 = getelementptr inbounds i8, ptr %.02032, i64 1
  %20 = getelementptr inbounds i8, ptr %.133, i64 1
  store i8 %18, ptr %.133, align 1, !tbaa !5
  %21 = load i8, ptr %19, align 1, !tbaa !5
  %.not26 = icmp eq i8 %21, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph34, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph34, %.preheader
  %.1.lcssa = phi ptr [ %.019.lcssa, %.preheader ], [ %20, %.lr.ph34 ]
  store i8 0, ptr %.1.lcssa, align 1, !tbaa !5
  br label %27

22:                                               ; preds = %2
  br i1 %3, label %23, label %25

23:                                               ; preds = %22
  %24 = tail call ptr @ft_strdup(ptr noundef nonnull %0) #3
  br label %27

25:                                               ; preds = %22
  %26 = tail call ptr @ft_strdup(ptr noundef %1) #3
  br label %27

27:                                               ; preds = %5, %25, %23, %._crit_edge
  %.0 = phi ptr [ %10, %._crit_edge ], [ %24, %23 ], [ %26, %25 ], [ null, %5 ]
  ret ptr %.0
}

; 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

declare ptr @ft_strdup(ptr 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 = { 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 = { 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass