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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN16LongColumnVector3addEl(ptr noundef nonnull align 8 dereferenceable(89) %0, i64 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 2
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !14
  %11 = icmp uge i64 %8, %10
  br i1 %11, label %12, label %19

12:                                               ; preds = %2
  %13 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = mul i64 %14, 2
  %16 = load ptr, ptr %6, align 8, !tbaa !15
  %17 = getelementptr inbounds ptr, ptr %16, i64 4
  %18 = load ptr, ptr %17, align 8
  call void %18(ptr noundef nonnull align 8 dereferenceable(89) %6, i64 noundef %15, i1 noundef zeroext true)
  br label %19

19:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %20 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = add i64 %21, 1
  store i64 %22, ptr %20, align 8, !tbaa !11
  %23 = trunc i64 %21 to i32
  store i32 %23, ptr %5, align 4, !tbaa !17
  %24 = getelementptr inbounds %class.LongColumnVector, ptr %6, i32 0, i32 3
  %25 = load i8, ptr %24, align 8, !tbaa !19, !range !21, !noundef !22
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %34

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %class.LongColumnVector, ptr %6, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !23
  %31 = load i32, ptr %5, align 4, !tbaa !17
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i64, ptr %30, i64 %32
  store i64 %28, ptr %33, align 8, !tbaa !9
  br label %41

34:                                               ; preds = %19
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %class.LongColumnVector, ptr %6, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !24
  %38 = load i32, ptr %5, align 4, !tbaa !17
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i64, ptr %37, i64 %39
  store i64 %35, ptr %40, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %34, %27
  %42 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 7
  %43 = load ptr, ptr %42, align 8, !tbaa !25
  %44 = load i32, ptr %5, align 4, !tbaa !17
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  store i8 0, ptr %46, align 1, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 16}
!12 = !{!"_ZTS12ColumnVector", !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !13, i64 41, !6, i64 48, !13, i64 56, !6, i64 64}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !13, i64 88}
!20 = !{!"_ZTS16LongColumnVector", !12, i64 0, !6, i64 72, !6, i64 80, !13, i64 88}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!20, !6, i64 72}
!24 = !{!20, !6, i64 80}
!25 = !{!12, !6, i64 48}
!26 = !{!7, !7, i64 0}


; 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: mustprogress uwtable
define dso_local void @_ZN16LongColumnVector3addEl(ptr noundef nonnull align 8 dereferenceable(89) %0, i64 noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !12
  %.not = icmp ult i64 %4, %6
  br i1 %.not, label %12, label %7

7:                                                ; preds = %2
  %8 = shl i64 %4, 1
  %9 = load ptr, ptr %0, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load ptr, ptr %10, align 8
  tail call void %11(ptr noundef nonnull align 8 dereferenceable(89) %0, i64 noundef %8, i1 noundef zeroext true)
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %7, %2
  %13 = phi i64 [ %.pre, %7 ], [ %4, %2 ]
  %14 = add i64 %13, 1
  store i64 %14, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 88
  %16 = load i8, ptr %15, align 8, !tbaa !15, !range !17, !noundef !18
  %17 = trunc nuw i8 %16 to i1
  %sext5 = shl i64 %13, 32
  %18 = ashr exact i64 %sext5, 29
  %. = select i1 %17, i64 72, i64 80
  %19 = getelementptr inbounds i8, ptr %0, i64 %.
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %20, i64 %18
  store i64 %1, ptr %21, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = ashr exact i64 %sext5, 32
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  store i8 0, ptr %25, align 1, !tbaa !22
  ret void
}

attributes #0 = { 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" }

!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 16}
!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 = !{!6, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !9, i64 0}
!15 = !{!16, !10, i64 88}
!16 = !{!"_ZTS16LongColumnVector", !6, i64 0, !11, i64 72, !11, i64 80, !10, i64 88}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!11, !11, i64 0}
!20 = !{!7, !7, i64 0}
!21 = !{!6, !11, i64 48}
!22 = !{!8, !8, i64 0}


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