; 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.charStream4 = 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 }

@_ZN11charStream45mask_E = external dso_local constant [2 x i8], align 1
@_ZN11charStream46shift_E = external dso_local constant [2 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 @_ZN11charStream413getNextUnsafeEv(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.charStream4, ptr %4, i32 0, i32 2
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load i8, ptr %6, align 1, !tbaa !19
  %8 = zext i8 %7 to i64
  store i64 %8, ptr %3, align 8, !tbaa !20
  %9 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 3
  %10 = load i8, ptr %9, align 8, !tbaa !22, !range !23, !noundef !24
  %11 = trunc i8 %10 to i1
  %12 = xor i1 %11, true
  %13 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 3
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 8, !tbaa !22
  %15 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 3
  %16 = load i8, ptr %15, align 8, !tbaa !22, !range !23, !noundef !24
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i32
  %19 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store ptr %22, ptr %19, align 8, !tbaa !9
  %23 = load i64, ptr %3, align 8, !tbaa !20
  %24 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 3
  %25 = load i8, ptr %24, align 8, !tbaa !22, !range !23, !noundef !24
  %26 = trunc i8 %25 to i1
  %27 = xor i1 %26, true
  %28 = zext i1 %27 to i64
  %29 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream45mask_E, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !19
  %31 = zext i8 %30 to i64
  %32 = and i64 %23, %31
  %33 = getelementptr inbounds %class.charStream4, ptr %4, i32 0, i32 3
  %34 = load i8, ptr %33, align 8, !tbaa !22, !range !23, !noundef !24
  %35 = trunc i8 %34 to i1
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i64
  %38 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream46shift_E, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !19
  %40 = zext i8 %39 to i32
  %41 = zext i32 %40 to i64
  %42 = lshr i64 %32, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %42
}

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 = !{!"_ZTS11charStream4", !11, i64 0, !6, i64 40, !18, 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 = !{!"bool", !7, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!10, !18, i64 48}
!23 = !{i8 0, i8 2}
!24 = !{}


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

@_ZN11charStream45mask_E = external dso_local local_unnamed_addr constant [2 x i8], align 1
@_ZN11charStream46shift_E = external dso_local local_unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 0, 256) i64 @_ZN11charStream413getNextUnsafeEv(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 !18
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i8, ptr %5, align 8, !tbaa !19, !range !20, !noundef !21
  %7 = trunc nuw i8 %6 to i1
  %8 = xor i1 %7, true
  %9 = zext i1 %8 to i8
  store i8 %9, ptr %5, align 8, !tbaa !19
  %10 = zext i1 %8 to i64
  %11 = getelementptr inbounds i8, ptr %3, i64 %10
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = zext nneg i8 %6 to i64
  %13 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream45mask_E, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !18
  %15 = and i8 %14, %4
  %16 = zext i8 %15 to i64
  %17 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream46shift_E, i64 0, i64 %12
  %18 = load i8, ptr %17, align 1, !tbaa !18
  %19 = zext nneg i8 %18 to i64
  %20 = lshr i64 %16, %19
  ret i64 %20
}

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 = !{!"_ZTS11charStream4", !7, i64 0, !13, i64 40, !17, 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 = !{!"bool", !14, i64 0}
!18 = !{!14, !14, i64 0}
!19 = !{!6, !17, i64 48}
!20 = !{i8 0, i8 2}
!21 = !{}


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