; 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.charStream12 = type { %class.charStreamNonNative.base, i8, ptr }
%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 }

; 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 @_ZN12charStream1213getNextUnsafeEv(ptr noundef nonnull align 8 dereferenceable(48) %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
  store i64 0, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 1
  %6 = load i8, ptr %5, align 4, !tbaa !11, !range !21, !noundef !22
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %24

8:                                                ; preds = %1
  %9 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !23
  %11 = load i8, ptr %10, align 1, !tbaa !24
  %12 = zext i8 %11 to i16
  %13 = zext i16 %12 to i32
  %14 = shl i32 %13, 4
  %15 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !23
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !24
  %19 = zext i8 %18 to i32
  %20 = and i32 %19, 240
  %21 = ashr i32 %20, 4
  %22 = or i32 %14, %21
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %3, align 8, !tbaa !9
  br label %40

24:                                               ; preds = %1
  %25 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !23
  %27 = load i8, ptr %26, align 1, !tbaa !24
  %28 = zext i8 %27 to i32
  %29 = and i32 %28, 15
  %30 = trunc i32 %29 to i16
  %31 = zext i16 %30 to i32
  %32 = shl i32 %31, 8
  %33 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !23
  %35 = getelementptr inbounds i8, ptr %34, i64 1
  %36 = load i8, ptr %35, align 1, !tbaa !24
  %37 = zext i8 %36 to i32
  %38 = or i32 %32, %37
  %39 = sext i32 %38 to i64
  store i64 %39, ptr %3, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %24, %8
  %41 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 1
  %42 = load i8, ptr %41, align 4, !tbaa !11, !range !21, !noundef !22
  %43 = trunc i8 %42 to i1
  %44 = xor i1 %43, true
  %45 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 1
  %46 = zext i1 %44 to i8
  store i8 %46, ptr %45, align 4, !tbaa !11
  %47 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 1
  %48 = load i8, ptr %47, align 4, !tbaa !11, !range !21, !noundef !22
  %49 = trunc i8 %48 to i1
  %50 = zext i1 %49 to i32
  %51 = add nsw i32 1, %50
  %52 = getelementptr inbounds %class.charStream12, ptr %4, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !23
  %54 = sext i32 %51 to i64
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store ptr %55, ptr %52, align 8, !tbaa !23
  %56 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %56
}

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !20, i64 36}
!12 = !{!"_ZTS12charStream12", !13, i64 0, !20, i64 36, !6, i64 40}
!13 = !{!"_ZTS19charStreamNonNative", !14, i64 0, !15, i64 8, !19, i64 32}
!14 = !{!"_ZTS10charStream"}
!15 = !{!"_ZTSSt6vectorIhSaIhEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"int", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!12, !6, i64 40}
!24 = !{!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 nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 0, 4096) i64 @_ZN12charStream1213getNextUnsafeEv(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i8, ptr %2, align 4, !tbaa !5, !range !18, !noundef !19
  %4 = trunc nuw i8 %3 to i1
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !20
  %7 = load i8, ptr %6, align 1, !tbaa !21
  br i1 %4, label %8, label %14

8:                                                ; preds = %1
  %9 = zext i8 %7 to i64
  %10 = shl nuw nsw i64 %9, 4
  %11 = getelementptr inbounds i8, ptr %6, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !21
  %13 = lshr i8 %12, 4
  br label %20

14:                                               ; preds = %1
  %15 = and i8 %7, 15
  %16 = zext nneg i8 %15 to i64
  %17 = shl nuw nsw i64 %16, 8
  %18 = getelementptr inbounds i8, ptr %6, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !21
  br label %20

20:                                               ; preds = %14, %8
  %.sink2 = phi i8 [ %19, %14 ], [ %13, %8 ]
  %.sink = phi i64 [ %17, %14 ], [ %10, %8 ]
  %21 = phi i64 [ 2, %14 ], [ 1, %8 ]
  %22 = zext i8 %.sink2 to i64
  %23 = or disjoint i64 %.sink, %22
  %24 = xor i8 %3, 1
  store i8 %24, ptr %2, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = getelementptr inbounds i8, ptr %6, i64 %21
  store ptr %26, ptr %25, align 8, !tbaa !20
  ret i64 %23
}

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


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