; LLVM IR from clibraries/array-algorithms :: test (impl)

; 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"

%struct.Person = type { i32, [32 x i8] }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @person_array_copy(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @person_array_merge(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noalias noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %12, align 8, !tbaa !5
  %18 = icmp eq ptr %16, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %7
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = call ptr @person_array_copy(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %8, align 8
  br label %75

24:                                               ; preds = %7
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp eq ptr %25, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %24
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = call ptr @person_array_copy(ptr noundef %29, ptr noundef %30, ptr noundef %31)
  store ptr %32, ptr %8, align 8
  br label %75

33:                                               ; preds = %24
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %74, %34
  %36 = load ptr, ptr %14, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = call i32 %36(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  %41 = icmp sge i32 %40, 0
  br i1 %41, label %42, label %58

42:                                               ; preds = %35
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %43, ptr align 4 %44, i64 36, i1 false), !tbaa.struct !9
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Person, ptr %45, i32 1
  store ptr %46, ptr %13, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Person, ptr %47, i32 1
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = icmp eq ptr %49, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %42
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = call ptr @person_array_copy(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  store ptr %56, ptr %8, align 8
  br label %75

57:                                               ; preds = %42
  br label %74

58:                                               ; preds = %35
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %59, ptr align 4 %60, i64 36, i1 false), !tbaa.struct !9
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Person, ptr %61, i32 1
  store ptr %62, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Person, ptr %63, i32 1
  store ptr %64, ptr %9, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = icmp eq ptr %65, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %58
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = call ptr @person_array_copy(ptr noundef %69, ptr noundef %70, ptr noundef %71)
  store ptr %72, ptr %8, align 8
  br label %75

73:                                               ; preds = %58
  br label %74

74:                                               ; preds = %73, %57
  br label %35

75:                                               ; preds = %68, %52, %28, %19
  %76 = load ptr, ptr %8, align 8
  ret ptr %76
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }

!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 = !{i64 0, i64 4, !10, i64 4, i64 32, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @person_array_copy(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @person_array_merge(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noalias noundef %4, ptr nocapture noundef readonly %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = icmp eq ptr %2, %3
  br i1 %8, label %9, label %11

9:                                                ; preds = %7
  %10 = tail call ptr @person_array_copy(ptr noundef %0, ptr noundef %1, ptr noundef %4)
  br label %28

11:                                               ; preds = %7
  %12 = icmp eq ptr %0, %1
  br i1 %12, label %13, label %.preheader.outer

13:                                               ; preds = %11
  %14 = tail call ptr @person_array_copy(ptr noundef %2, ptr noundef %3, ptr noundef %4)
  br label %28

.preheader:                                       ; preds = %.preheader.outer, %23
  %.034 = phi ptr [ %17, %23 ], [ %.034.ph, %.preheader.outer ]
  %.033 = phi ptr [ %24, %23 ], [ %.033.ph, %.preheader.outer ]
  %15 = tail call i32 %5(ptr noundef %.033, ptr noundef %.036.ph, ptr noundef %6) #2
  %16 = icmp sgt i32 %15, -1
  %17 = getelementptr inbounds i8, ptr %.034, i64 36
  br i1 %16, label %18, label %23

18:                                               ; preds = %.preheader
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %.034, ptr noundef nonnull align 4 dereferenceable(36) %.036.ph, i64 36, i1 false), !tbaa.struct !5
  %19 = getelementptr inbounds i8, ptr %.036.ph, i64 36
  %20 = icmp eq ptr %19, %3
  br i1 %20, label %21, label %.preheader.outer

.preheader.outer:                                 ; preds = %11, %18
  %.036.ph = phi ptr [ %19, %18 ], [ %2, %11 ]
  %.034.ph = phi ptr [ %17, %18 ], [ %4, %11 ]
  %.033.ph = phi ptr [ %.033, %18 ], [ %0, %11 ]
  br label %.preheader

21:                                               ; preds = %18
  %22 = tail call ptr @person_array_copy(ptr noundef %.033, ptr noundef %1, ptr noundef nonnull %17)
  br label %28

23:                                               ; preds = %.preheader
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %.034, ptr noundef nonnull align 4 dereferenceable(36) %.033, i64 36, i1 false), !tbaa.struct !5
  %24 = getelementptr inbounds i8, ptr %.033, i64 36
  %25 = icmp eq ptr %24, %1
  br i1 %25, label %26, label %.preheader

26:                                               ; preds = %23
  %27 = tail call ptr @person_array_copy(ptr noundef %.036.ph, ptr noundef %3, ptr noundef nonnull %17)
  br label %28

28:                                               ; preds = %26, %21, %13, %9
  %.0 = phi ptr [ %10, %9 ], [ %14, %13 ], [ %22, %21 ], [ %27, %26 ]
  ret ptr %.0
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{i64 0, i64 4, !6, i64 4, i64 32, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass