; LLVM IR from pixelsdb/mini-pixels :: pixels-core/lib/vector/DateColumnVector.ll (ZN16DateColumnVector10ensureSizeEmb)

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

%class.ColumnVector = type { ptr, i64, i64, i64, i64, i8, i8, ptr, i8, ptr }
%class.DateColumnVector = type { %class.ColumnVector, ptr }

; Function Attrs: nounwind
declare i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16DateColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(80) %0, i64 noundef %1, i1 noundef zeroext %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %12 = trunc i8 %11 to i1
  call void @_ZN12ColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(72) %9, i64 noundef %10, i1 noundef zeroext %12)
  %13 = getelementptr inbounds %class.ColumnVector, ptr %9, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !15
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %17, label %50

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %18 = getelementptr inbounds %class.DateColumnVector, ptr %9, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.DateColumnVector, ptr %9, i32 0, i32 1
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = mul i64 %21, 4
  %23 = call i32 @posix_memalign(ptr noundef %20, i64 noundef 32, i64 noundef %22) #6
  %24 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %35

26:                                               ; preds = %17
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.ColumnVector, ptr %9, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = getelementptr inbounds %class.DateColumnVector, ptr %9, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef %27, ptr noundef %31, ptr noundef %33)
  br label %35

35:                                               ; preds = %26, %17
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  call void @_ZdaPv(ptr noundef %36) #7
  br label %39

39:                                               ; preds = %38, %35
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %class.ColumnVector, ptr %9, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !15
  %43 = sub i64 %40, %42
  %44 = mul i64 8, %43
  %45 = getelementptr inbounds %class.ColumnVector, ptr %9, i32 0, i32 4
  %46 = load i64, ptr %45, align 8, !tbaa !19
  %47 = add i64 %46, %44
  store i64 %47, ptr %45, align 8, !tbaa !19
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = trunc i64 %48 to i32
  call void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72) %9, i32 noundef %49)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %50

50:                                               ; preds = %39, %3
  ret void
}

declare void @_ZN12ColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef, i1 noundef zeroext) unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #5

declare void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) #3

attributes #0 = { nounwind "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 = { mustprogress 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 = { "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 = { inlinehint mustprogress 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 #5 = { nobuiltin nounwind "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 #6 = { nounwind }
attributes #7 = { builtin 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTS12ColumnVector", !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !12, i64 40, !12, i64 41, !6, i64 48, !12, i64 56, !6, i64 64}
!17 = !{!18, !6, i64 72}
!18 = !{!"_ZTS16DateColumnVector", !16, i64 0, !6, i64 72}
!19 = !{!16, !10, 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: nofree nounwind
declare i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16DateColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(80) %0, i64 noundef %1, i1 noundef zeroext %2) unnamed_addr #1 align 2 {
  tail call void @_ZN12ColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1, i1 noundef zeroext %2)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ult i64 %5, %1
  br i1 %6, label %7, label %28

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = shl i64 %1, 2
  %11 = tail call i32 @posix_memalign(ptr noundef nonnull %8, i64 noundef 32, i64 noundef %10) #5
  br i1 %2, label %12, label %17

12:                                               ; preds = %7
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %9, i64 %13
  %15 = load ptr, ptr %8, align 8, !tbaa !12
  %16 = tail call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef %9, ptr noundef %14, ptr noundef %15)
  br label %17

17:                                               ; preds = %12, %7
  %18 = icmp eq ptr %9, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %17
  tail call void @_ZdaPv(ptr noundef nonnull %9) #6
  br label %20

20:                                               ; preds = %19, %17
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = sub i64 %1, %21
  %23 = shl i64 %22, 3
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = add i64 %23, %25
  store i64 %26, ptr %24, align 8, !tbaa !14
  %27 = trunc i64 %1 to i32
  tail call void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %27)
  br label %28

28:                                               ; preds = %20, %3
  ret void
}

declare void @_ZN12ColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(72), i64 noundef, i1 noundef zeroext) unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #4

declare void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind "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 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 = { "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 = { inlinehint mustprogress 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 = { nobuiltin nounwind "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 #5 = { nounwind }
attributes #6 = { builtin 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, !7, i64 8}
!6 = !{!"_ZTS12ColumnVector", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 41, !11, i64 48, !10, i64 56, !11, i64 64}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !11, i64 72}
!13 = !{!"_ZTS16DateColumnVector", !6, i64 0, !11, i64 72}
!14 = !{!6, !7, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass