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

; 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.LongColumnVector = type <{ %class.ColumnVector, ptr, ptr, i8, [7 x i8] }>

; 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 @_ZN16LongColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(89) %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
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %9 = zext i1 %2 to i8
  store i8 %9, ptr %6, align 1, !tbaa !11
  %10 = load ptr, ptr %4, align 8
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %13 = trunc i8 %12 to i1
  call void @_ZN12ColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(72) %10, i64 noundef %11, i1 noundef zeroext %13)
  %14 = getelementptr inbounds %class.ColumnVector, ptr %10, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %89

18:                                               ; preds = %3
  %19 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 3
  %20 = load i8, ptr %19, align 8, !tbaa !17, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %55

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %23 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 1
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = mul i64 %26, 8
  %28 = call i32 @posix_memalign(ptr noundef %25, i64 noundef 32, i64 noundef %27) #6
  %29 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %40

31:                                               ; preds = %22
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.ColumnVector, ptr %10, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds i64, ptr %33, i64 %35
  %37 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = call noundef ptr @_ZSt4copyIPlS0_ET0_T_S2_S1_(ptr noundef %32, ptr noundef %36, ptr noundef %38)
  br label %40

40:                                               ; preds = %31, %22
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  call void @_ZdaPv(ptr noundef %41) #7
  br label %44

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

55:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %56 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !21
  store ptr %57, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 2
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = mul i64 %59, 8
  %61 = call i32 @posix_memalign(ptr noundef %58, i64 noundef 32, i64 noundef %60) #6
  %62 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %63 = trunc i8 %62 to i1
  br i1 %63, label %64, label %73

64:                                               ; preds = %55
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.ColumnVector, ptr %10, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !15
  %69 = getelementptr inbounds i64, ptr %66, i64 %68
  %70 = getelementptr inbounds %class.LongColumnVector, ptr %10, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = call noundef ptr @_ZSt4copyIPlS0_ET0_T_S2_S1_(ptr noundef %65, ptr noundef %69, ptr noundef %71)
  br label %73

73:                                               ; preds = %64, %55
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = icmp eq ptr %74, null
  br i1 %75, label %77, label %76

76:                                               ; preds = %73
  call void @_ZdaPv(ptr noundef %74) #7
  br label %77

77:                                               ; preds = %76, %73
  %78 = load i64, ptr %5, align 8, !tbaa !9
  %79 = getelementptr inbounds %class.ColumnVector, ptr %10, i32 0, i32 1
  %80 = load i64, ptr %79, align 8, !tbaa !15
  %81 = sub i64 %78, %80
  %82 = mul i64 4, %81
  %83 = getelementptr inbounds %class.ColumnVector, ptr %10, i32 0, i32 4
  %84 = load i64, ptr %83, align 8, !tbaa !20
  %85 = add i64 %84, %82
  store i64 %85, ptr %83, align 8, !tbaa !20
  %86 = load i64, ptr %5, align 8, !tbaa !9
  %87 = trunc i64 %86 to i32
  call void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72) %10, i32 noundef %87)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %88

88:                                               ; preds = %77, %44
  br label %89

89:                                               ; preds = %88, %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 @_ZSt4copyIPlS0_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, !12, i64 88}
!18 = !{!"_ZTS16LongColumnVector", !16, i64 0, !6, i64 72, !6, i64 80, !12, i64 88}
!19 = !{!18, !6, i64 72}
!20 = !{!16, !10, i64 32}
!21 = !{!18, !6, i64 80}


; 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 @_ZN16LongColumnVector10ensureSizeEmb(ptr noundef nonnull align 8 dereferenceable(89) %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 %41

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load i8, ptr %8, align 8, !tbaa !12, !range !14, !noundef !15
  %10 = trunc nuw i8 %9 to i1
  %11 = shl i64 %1, 3
  br i1 %10, label %12, label %23

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 72
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = tail call i32 @posix_memalign(ptr noundef nonnull %13, i64 noundef 32, i64 noundef %11) #5
  br i1 %2, label %16, label %21

16:                                               ; preds = %12
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i64, ptr %14, i64 %17
  %19 = load ptr, ptr %13, align 8, !tbaa !16
  %20 = tail call noundef ptr @_ZSt4copyIPlS0_ET0_T_S2_S1_(ptr noundef %14, ptr noundef %18, ptr noundef %19)
  br label %21

21:                                               ; preds = %16, %12
  %22 = icmp eq ptr %14, null
  br i1 %22, label %.sink.split, label %.sink.split.sink.split

23:                                               ; preds = %7
  %24 = getelementptr inbounds i8, ptr %0, i64 80
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = tail call i32 @posix_memalign(ptr noundef nonnull %24, i64 noundef 32, i64 noundef %11) #5
  br i1 %2, label %27, label %32

27:                                               ; preds = %23
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i64, ptr %25, i64 %28
  %30 = load ptr, ptr %24, align 8, !tbaa !17
  %31 = tail call noundef ptr @_ZSt4copyIPlS0_ET0_T_S2_S1_(ptr noundef %25, ptr noundef %29, ptr noundef %30)
  br label %32

32:                                               ; preds = %27, %23
  %33 = icmp eq ptr %25, null
  br i1 %33, label %.sink.split, label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %32, %21
  %.sink = phi ptr [ %14, %21 ], [ %25, %32 ]
  %.sink22.ph = phi i64 [ 3, %21 ], [ 2, %32 ]
  tail call void @_ZdaPv(ptr noundef nonnull %.sink) #6
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %32, %21
  %.sink22 = phi i64 [ 3, %21 ], [ 2, %32 ], [ %.sink22.ph, %.sink.split.sink.split ]
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = sub i64 %1, %34
  %36 = shl i64 %35, %.sink22
  %37 = getelementptr inbounds i8, ptr %0, i64 32
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = add i64 %36, %38
  store i64 %39, ptr %37, align 8, !tbaa !18
  %40 = trunc i64 %1 to i32
  tail call void @_ZN12ColumnVector6resizeEi(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %40)
  br label %41

41:                                               ; preds = %.sink.split, %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 @_ZSt4copyIPlS0_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, !10, i64 88}
!13 = !{!"_ZTS16LongColumnVector", !6, i64 0, !11, i64 72, !11, i64 80, !10, i64 88}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!13, !11, i64 72}
!17 = !{!13, !11, i64 80}
!18 = !{!6, !7, i64 32}


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