; LLVM IR from ox-vgg/vise :: src/search_engine/relja_retrival/compression (char_streams)

; 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.charStream10 = type <{ %class.charStreamNonNative.base, [4 x i8], ptr, i8, [7 x i8] }>
%class.charStreamNonNative.base = type <{ %class.charStream, %"class.std::vector", i32 }>
%class.charStream = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZN12charStream106mask1_E = external dso_local constant [4 x i8], align 1
@_ZN12charStream106mask2_E = external dso_local constant [4 x i8], align 1
@_ZN12charStream108lshift1_E = external dso_local constant [4 x i8], align 1
@_ZN12charStream107shift2_E = external dso_local constant [4 x i8], align 1

; 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 nounwind uwtable
define dso_local noundef i64 @_ZN12charStream1013getNextUnsafeEv(ptr noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 2
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load i8, ptr %6, align 1, !tbaa !18
  %8 = zext i8 %7 to i32
  %9 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %10 = load i8, ptr %9, align 8, !tbaa !19
  %11 = zext i8 %10 to i64
  %12 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream106mask1_E, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !18
  %14 = zext i8 %13 to i32
  %15 = and i32 %8, %14
  %16 = trunc i32 %15 to i16
  %17 = zext i16 %16 to i32
  %18 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %19 = load i8, ptr %18, align 8, !tbaa !19
  %20 = zext i8 %19 to i64
  %21 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream108lshift1_E, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !18
  %23 = zext i8 %22 to i32
  %24 = shl i32 %17, %23
  %25 = sext i32 %24 to i64
  store i64 %25, ptr %3, align 8, !tbaa !20
  %26 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !18
  %30 = zext i8 %29 to i32
  %31 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %32 = load i8, ptr %31, align 8, !tbaa !19
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream106mask2_E, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !18
  %36 = zext i8 %35 to i32
  %37 = and i32 %30, %36
  %38 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %39 = load i8, ptr %38, align 8, !tbaa !19
  %40 = zext i8 %39 to i64
  %41 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream107shift2_E, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !18
  %43 = zext i8 %42 to i32
  %44 = ashr i32 %37, %43
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr %3, align 8, !tbaa !20
  %47 = or i64 %46, %45
  store i64 %47, ptr %3, align 8, !tbaa !20
  %48 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %49 = load i8, ptr %48, align 8, !tbaa !19
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 3
  %52 = zext i1 %51 to i32
  %53 = add nsw i32 1, %52
  %54 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = sext i32 %53 to i64
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store ptr %57, ptr %54, align 8, !tbaa !9
  %58 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  %59 = load i8, ptr %58, align 8, !tbaa !19
  %60 = zext i8 %59 to i32
  %61 = add nsw i32 %60, 1
  %62 = srem i32 %61, 4
  %63 = trunc i32 %62 to i8
  %64 = getelementptr inbounds %class.charStream10, ptr %4, i32 0, i32 3
  store i8 %63, ptr %64, align 8, !tbaa !19
  %65 = load i64, ptr %3, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %65
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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, !6, i64 40}
!10 = !{!"_ZTS12charStream10", !11, i64 0, !6, i64 40, !7, i64 48}
!11 = !{!"_ZTS19charStreamNonNative", !12, i64 0, !13, i64 8, !17, i64 32}
!12 = !{!"_ZTS10charStream"}
!13 = !{!"_ZTSSt6vectorIhSaIhEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"int", !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !7, i64 48}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !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"

@_ZN12charStream106mask1_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN12charStream106mask2_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN12charStream108lshift1_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN12charStream107shift2_E = external dso_local local_unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZN12charStream1013getNextUnsafeEv(ptr nocapture noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load i8, ptr %3, align 1, !tbaa !17
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i8, ptr %5, align 8, !tbaa !18
  %7 = zext i8 %6 to i64
  %8 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream106mask1_E, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !17
  %10 = and i8 %9, %4
  %11 = zext i8 %10 to i32
  %12 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream108lshift1_E, i64 0, i64 %7
  %13 = load i8, ptr %12, align 1, !tbaa !17
  %14 = zext nneg i8 %13 to i32
  %15 = shl i32 %11, %14
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %3, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !17
  %19 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream106mask2_E, i64 0, i64 %7
  %20 = load i8, ptr %19, align 1, !tbaa !17
  %21 = and i8 %20, %18
  %22 = zext i8 %21 to i32
  %23 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream107shift2_E, i64 0, i64 %7
  %24 = load i8, ptr %23, align 1, !tbaa !17
  %25 = zext nneg i8 %24 to i32
  %26 = lshr i32 %22, %25
  %27 = zext nneg i32 %26 to i64
  %28 = or i64 %27, %16
  %29 = icmp eq i8 %6, 3
  %30 = select i1 %29, i64 2, i64 1
  %31 = getelementptr inbounds i8, ptr %3, i64 %30
  store ptr %31, ptr %2, align 8, !tbaa !5
  %32 = add i8 %6, 1
  %33 = and i8 %32, 3
  store i8 %33, ptr %5, align 8, !tbaa !18
  ret i64 %28
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !13, i64 40}
!6 = !{!"_ZTS12charStream10", !7, i64 0, !13, i64 40, !14, i64 48}
!7 = !{!"_ZTS19charStreamNonNative", !8, i64 0, !9, i64 8, !16, i64 32}
!8 = !{!"_ZTS10charStream"}
!9 = !{!"_ZTSSt6vectorIhSaIhEE", !10, i64 0}
!10 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !11, i64 0}
!11 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !13, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"any pointer", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C++ TBAA"}
!16 = !{!"int", !14, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{!6, !14, i64 48}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass