; 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.bgcobject = type { ptr, i8, i8 }
%struct.blist = type { ptr, i8, i8, ptr, i32, i32, ptr }
%struct.bvm = type { %struct.bglobaldesc, ptr, ptr, ptr, %struct.bvector, %struct.bvector, ptr, ptr, ptr, ptr, ptr, %struct.bvector, %struct.bmoduledesc, %struct.bstringtable, %struct.bvector, ptr, %struct.bgc, ptr, i8, i64, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.bglobaldesc = type { %struct.anon, %struct.anon.0 }
%struct.anon = type { ptr, %struct.bvector }
%struct.anon.0 = type { ptr, %struct.bvector }
%struct.bmoduledesc = type { ptr, ptr }
%struct.bstringtable = type { ptr, i32, i32 }
%struct.bvector = type { i32, i32, i32, ptr, ptr }
%struct.bgc = type { ptr, ptr, ptr, ptr, ptr, i64, i64, i8, i8 }
%struct.bvalue = type { %union.bvaldata, i32 }
%union.bvaldata = type { double }

; Function Attrs: nounwind uwtable
define dso_local ptr @be_list_new(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @be_newgcobj(ptr noundef %5, i32 noundef 20, i64 noundef 40)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %17

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.bgcobject, ptr %10, i32 0, i32 1
  %12 = load i8, ptr %11, align 8, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = icmp eq i32 %13, 20
  br i1 %14, label %15, label %17

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  br label %18

17:                                               ; preds = %9, %1
  br label %18

18:                                               ; preds = %17, %15
  %19 = phi ptr [ %16, %15 ], [ null, %17 ]
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %53

22:                                               ; preds = %18
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.blist, ptr %23, i32 0, i32 4
  store i32 0, ptr %24, align 8, !tbaa !11
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.blist, ptr %25, i32 0, i32 5
  store i32 2, ptr %26, align 4, !tbaa !14
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.bvm, ptr %28, i32 0, i32 8
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.bvalue, ptr %30, i32 0, i32 0
  store ptr %27, ptr %31, align 8, !tbaa !24
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.bvm, ptr %32, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.bvalue, ptr %34, i32 0, i32 1
  store i32 20, ptr %35, align 8, !tbaa !25
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bvm, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds %struct.bvalue, ptr %38, i32 1
  store ptr %39, ptr %37, align 8, !tbaa !15
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.blist, ptr %41, i32 0, i32 5
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = sext i32 %43 to i64
  %45 = mul i64 %44, 16
  %46 = call ptr @be_realloc(ptr noundef %40, ptr noundef null, i64 noundef 0, i64 noundef %45)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.blist, ptr %47, i32 0, i32 6
  store ptr %46, ptr %48, align 8, !tbaa !27
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.bvm, ptr %49, i32 0, i32 8
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = getelementptr inbounds %struct.bvalue, ptr %51, i64 -1
  store ptr %52, ptr %50, align 8, !tbaa !15
  br label %53

53:                                               ; preds = %22, %18
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %54
}

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

declare ptr @be_newgcobj(ptr noundef, i32 noundef, i64 noundef) #2

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

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

!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, !7, i64 8}
!10 = !{!"bgcobject", !6, i64 0, !7, i64 8, !7, i64 9}
!11 = !{!12, !13, i64 24}
!12 = !{!"blist", !6, i64 0, !7, i64 8, !7, i64 9, !6, i64 16, !13, i64 24, !13, i64 28, !6, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 28}
!15 = !{!16, !6, i64 184}
!16 = !{!"bvm", !17, i64 0, !6, i64 80, !6, i64 88, !6, i64 96, !19, i64 104, !19, i64 136, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !19, i64 208, !20, i64 240, !21, i64 256, !19, i64 272, !6, i64 304, !22, i64 312, !6, i64 376, !7, i64 384, !23, i64 392, !6, i64 400, !13, i64 408, !13, i64 412, !13, i64 416, !13, i64 420, !13, i64 424, !13, i64 428, !13, i64 432, !13, i64 436, !13, i64 440, !13, i64 444, !13, i64 448, !13, i64 452, !13, i64 456, !13, i64 460, !13, i64 464, !13, i64 468, !13, i64 472, !13, i64 476, !13, i64 480, !13, i64 484, !13, i64 488, !13, i64 492, !13, i64 496}
!17 = !{!"", !18, i64 0, !18, i64 40}
!18 = !{!"", !6, i64 0, !19, i64 8}
!19 = !{!"bvector", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!"bmoduledesc", !6, i64 0, !6, i64 8}
!21 = !{!"bstringtable", !6, i64 0, !13, i64 8, !13, i64 12}
!22 = !{!"bgc", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !23, i64 40, !23, i64 48, !7, i64 56, !7, i64 57}
!23 = !{!"long", !7, i64 0}
!24 = !{!7, !7, i64 0}
!25 = !{!26, !13, i64 8}
!26 = !{!"bvalue", !7, i64 0, !13, i64 8}
!27 = !{!12, !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"

; Function Attrs: nounwind uwtable
define dso_local ptr @be_list_new(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @be_newgcobj(ptr noundef %0, i32 noundef 20, i64 noundef 40) #2
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.thread, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i8 %5, 20
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 0, ptr %8, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 2, ptr %9, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 184
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  store ptr %2, ptr %11, align 8, !tbaa !23
  %12 = load ptr, ptr %10, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 20, ptr %13, align 8, !tbaa !24
  %14 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %14, ptr %10, align 8, !tbaa !14
  %15 = load i32, ptr %9, align 4, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = shl nsw i64 %16, 4
  %18 = tail call ptr @be_realloc(ptr noundef %0, ptr noundef null, i64 noundef 0, i64 noundef %17) #2
  %19 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %18, ptr %19, align 8, !tbaa !26
  %20 = load ptr, ptr %10, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %20, i64 -16
  store ptr %21, ptr %10, align 8, !tbaa !14
  br label %.thread

.thread:                                          ; preds = %3, %1, %7
  %22 = phi ptr [ %2, %7 ], [ null, %1 ], [ null, %3 ]
  ret ptr %22
}

declare ptr @be_newgcobj(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

declare ptr @be_realloc(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #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 = { "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, !8, i64 8}
!6 = !{!"bgcobject", !7, i64 0, !8, i64 8, !8, i64 9}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 24}
!11 = !{!"blist", !7, i64 0, !8, i64 8, !8, i64 9, !7, i64 16, !12, i64 24, !12, i64 28, !7, i64 32}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !12, i64 28}
!14 = !{!15, !7, i64 184}
!15 = !{!"bvm", !16, i64 0, !7, i64 80, !7, i64 88, !7, i64 96, !18, i64 104, !18, i64 136, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !18, i64 208, !19, i64 240, !20, i64 256, !18, i64 272, !7, i64 304, !21, i64 312, !7, i64 376, !8, i64 384, !22, i64 392, !7, i64 400, !12, i64 408, !12, i64 412, !12, i64 416, !12, i64 420, !12, i64 424, !12, i64 428, !12, i64 432, !12, i64 436, !12, i64 440, !12, i64 444, !12, i64 448, !12, i64 452, !12, i64 456, !12, i64 460, !12, i64 464, !12, i64 468, !12, i64 472, !12, i64 476, !12, i64 480, !12, i64 484, !12, i64 488, !12, i64 492, !12, i64 496}
!16 = !{!"", !17, i64 0, !17, i64 40}
!17 = !{!"", !7, i64 0, !18, i64 8}
!18 = !{!"bvector", !12, i64 0, !12, i64 4, !12, i64 8, !7, i64 16, !7, i64 24}
!19 = !{!"bmoduledesc", !7, i64 0, !7, i64 8}
!20 = !{!"bstringtable", !7, i64 0, !12, i64 8, !12, i64 12}
!21 = !{!"bgc", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !22, i64 40, !22, i64 48, !8, i64 56, !8, i64 57}
!22 = !{!"long", !8, i64 0}
!23 = !{!8, !8, i64 0}
!24 = !{!25, !12, i64 8}
!25 = !{!"bvalue", !8, i64 0, !12, i64 8}
!26 = !{!11, !7, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass