; 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

declare i32 @be_nextsize(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @be_list_resize(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %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 !11
  %14 = icmp ne i32 %10, %13
  br i1 %14, label %15, label %69

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = call i32 @be_nextsize(i32 noundef %16)
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.blist, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = icmp sgt i32 %18, %21
  br i1 %22, label %23, label %65

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.blist, ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.blist, ptr %28, i32 0, i32 5
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = mul i64 %31, 16
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = mul i64 %34, 16
  %36 = call ptr @be_realloc(ptr noundef %24, ptr noundef %27, i64 noundef %32, i64 noundef %35)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.blist, ptr %37, i32 0, i32 6
  store ptr %36, ptr %38, align 8, !tbaa !14
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.blist, ptr %40, i32 0, i32 5
  store i32 %39, ptr %41, align 4, !tbaa !13
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.blist, ptr %42, i32 0, i32 6
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.blist, ptr %45, i32 0, i32 4
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.bvalue, ptr %44, i64 %48
  store ptr %49, ptr %8, align 8, !tbaa !5
  %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 %6, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.bvalue, ptr %52, i64 %54
  store ptr %55, ptr %9, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %60, %23
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = icmp ult ptr %57, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %56
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.bvalue, ptr %61, i32 1
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.bvalue, ptr %61, i32 0, i32 1
  store i32 0, ptr %63, align 8, !tbaa !15
  br label %56, !llvm.loop !17

64:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %65

65:                                               ; preds = %64, %15
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.blist, ptr %67, i32 0, i32 4
  store i32 %66, ptr %68, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %69

69:                                               ; preds = %65, %3
  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 = { 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, !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 = !{!12, !10, i64 24}
!12 = !{!"blist", !6, i64 0, !7, i64 8, !7, i64 9, !6, i64 16, !10, i64 24, !10, i64 28, !6, i64 32}
!13 = !{!12, !10, i64 28}
!14 = !{!12, !6, i64 32}
!15 = !{!16, !10, i64 8}
!16 = !{!"bvalue", !7, i64 0, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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

declare i32 @be_nextsize(i32 noundef) local_unnamed_addr #0

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

6:                                                ; preds = %3
  %7 = tail call i32 @be_nextsize(i32 noundef %2) #2
  %8 = getelementptr inbounds i8, ptr %1, i64 28
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = icmp sgt i32 %7, %9
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %1, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = sext i32 %9 to i64
  %15 = shl nsw i64 %14, 4
  %16 = sext i32 %7 to i64
  %17 = shl nsw i64 %16, 4
  %18 = tail call ptr @be_realloc(ptr noundef %0, ptr noundef %13, i64 noundef %15, i64 noundef %17) #2
  store ptr %18, ptr %12, align 8, !tbaa !12
  store i32 %7, ptr %8, align 4, !tbaa !11
  %19 = load i32, ptr %4, align 8, !tbaa !5
  %20 = sext i32 %2 to i64
  %21 = getelementptr inbounds %struct.bvalue, ptr %18, i64 %20
  %22 = icmp slt i32 %19, %2
  br i1 %22, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %11
  %23 = sext i32 %19 to i64
  %24 = getelementptr inbounds %struct.bvalue, ptr %18, i64 %23
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.023 = phi ptr [ %25, %.lr.ph ], [ %24, %.lr.ph.preheader ]
  %25 = getelementptr inbounds i8, ptr %.023, i64 16
  %26 = getelementptr inbounds i8, ptr %.023, i64 8
  store i32 0, ptr %26, align 8, !tbaa !13
  %27 = icmp ult ptr %25, %21
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %11, %6
  store i32 %2, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %.loopexit, %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 = { 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 = !{!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}
!13 = !{!14, !10, i64 8}
!14 = !{!"bvalue", !8, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass