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

; 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 @_ZN16LongColumnVector3addEi(ptr noundef nonnull align 8 dereferenceable(89) %0, i32 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !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 !15
  %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 !16
  %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 !9
  %24 = getelementptr inbounds %class.LongColumnVector, ptr %6, i32 0, i32 3
  %25 = load i8, ptr %24, align 8, !tbaa !18, !range !20, !noundef !21
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %35

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

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

43:                                               ; preds = %35, %27
  %44 = getelementptr inbounds %class.ColumnVector, ptr %6, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !25
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 0, ptr %48, 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"_ZTS12ColumnVector", !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !14, i64 40, !14, i64 41, !6, i64 48, !14, i64 56, !6, i64 64}
!13 = !{!"long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!19, !14, i64 88}
!19 = !{!"_ZTS16LongColumnVector", !12, i64 0, !6, i64 72, !6, i64 80, !14, i64 88}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!19, !6, i64 72}
!23 = !{!13, !13, i64 0}
!24 = !{!19, !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 @_ZN16LongColumnVector3addEi(ptr noundef nonnull align 8 dereferenceable(89) %0, i32 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
  %18 = sext i32 %1 to i64
  %sext5 = shl i64 %13, 32
  %19 = ashr exact i64 %sext5, 29
  %. = select i1 %17, i64 72, i64 80
  %20 = getelementptr inbounds i8, ptr %0, i64 %.
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %21, i64 %19
  store i64 %18, ptr %22, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %0, i64 48
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = ashr exact i64 %sext5, 32
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  store i8 0, ptr %26, 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