; LLVM IR from berry-lang/berry :: src (be_list)

; 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.blist = type { ptr, i8, i8, ptr, i32, i32, ptr }
%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @be_realloc(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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) #2

declare i32 @be_nextsize(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @be_list_merge(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.blist, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !9
  store i32 %13, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.blist, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !9
  store i32 %16, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %17 = load i32, ptr %8, align 4, !tbaa !12
  %18 = load i32, ptr %7, align 4, !tbaa !12
  %19 = add nsw i32 %17, %18
  store i32 %19, ptr %9, align 4, !tbaa !12
  %20 = load i32, ptr %9, align 4, !tbaa !12
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %65

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %23 = load i32, ptr %9, align 4, !tbaa !12
  %24 = call i32 @be_nextsize(i32 noundef %23)
  store i32 %24, ptr %10, align 4, !tbaa !12
  %25 = load i32, ptr %10, align 4, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.blist, ptr %26, i32 0, i32 5
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = icmp sgt i32 %25, %28
  br i1 %29, label %30, label %49

30:                                               ; preds = %22
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.blist, ptr %32, i32 0, i32 6
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.blist, ptr %35, i32 0, i32 5
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = sext i32 %37 to i64
  %39 = mul i64 %38, 16
  %40 = load i32, ptr %10, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = mul i64 %41, 16
  %43 = call ptr @be_realloc(ptr noundef %31, ptr noundef %34, i64 noundef %39, i64 noundef %42)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.blist, ptr %44, i32 0, i32 6
  store ptr %43, ptr %45, align 8, !tbaa !14
  %46 = load i32, ptr %10, align 4, !tbaa !12
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.blist, ptr %47, i32 0, i32 5
  store i32 %46, ptr %48, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %30, %22
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.blist, ptr %50, i32 0, i32 6
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load i32, ptr %7, align 4, !tbaa !12
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.bvalue, ptr %52, i64 %54
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.blist, ptr %56, i32 0, i32 6
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = load i32, ptr %8, align 4, !tbaa !12
  %60 = sext i32 %59 to i64
  %61 = mul i64 %60, 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %55, ptr align 8 %58, i64 %61, i1 false)
  %62 = load i32, ptr %9, align 4, !tbaa !12
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.blist, ptr %63, i32 0, i32 4
  store i32 %62, ptr %64, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %65

65:                                               ; preds = %49, %3
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !11, i64 24}
!10 = !{!"blist", !6, i64 0, !7, i64 8, !7, i64 9, !6, i64 16, !11, i64 24, !11, i64 28, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 28}
!14 = !{!10, !6, i64 32}


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

%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }

declare ptr @be_realloc(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; 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) #1

declare i32 @be_nextsize(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @be_list_merge(ptr noundef %0, ptr nocapture noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %7, %5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %29, label %9

9:                                                ; preds = %3
  %10 = tail call i32 @be_nextsize(i32 noundef %8) #3
  %11 = getelementptr inbounds i8, ptr %1, i64 28
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp sgt i32 %10, %12
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  br i1 %13, label %16, label %._crit_edge

16:                                               ; preds = %9
  %17 = sext i32 %12 to i64
  %18 = shl nsw i64 %17, 4
  %19 = sext i32 %10 to i64
  %20 = shl nsw i64 %19, 4
  %21 = tail call ptr @be_realloc(ptr noundef %0, ptr noundef %15, i64 noundef %18, i64 noundef %20) #3
  store ptr %21, ptr %14, align 8, !tbaa !12
  store i32 %10, ptr %11, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %9, %16
  %22 = phi ptr [ %21, %16 ], [ %15, %9 ]
  %23 = sext i32 %5 to i64
  %24 = getelementptr inbounds %struct.bvalue, ptr %22, i64 %23
  %25 = getelementptr inbounds i8, ptr %2, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = sext i32 %7 to i64
  %28 = shl nsw i64 %27, 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %24, ptr align 8 %26, i64 %28, i1 false)
  store i32 %8, ptr %4, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %._crit_edge, %3
  ret void
}

attributes #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 24}
!6 = !{!"blist", !7, i64 0, !8, i64 8, !8, i64 9, !7, i64 16, !10, i64 24, !10, i64 28, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!6, !7, i64 32}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass