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

@_ZN11charStream66mask1_E = external dso_local constant [4 x i8], align 1
@_ZN11charStream66mask2_E = external dso_local constant [4 x i8], align 1
@_ZN11charStream67shift1_E = external dso_local constant [4 x i8], align 1
@_ZN11charStream67shift2_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 @_ZN11charStream613getNextUnsafeEv(ptr noundef nonnull align 8 dereferenceable(49) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = 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
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %6 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 2
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load i8, ptr %7, align 1, !tbaa !20
  store i8 %8, ptr %4, align 1, !tbaa !20
  %9 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %10 = load i8, ptr %9, align 8, !tbaa !21
  %11 = zext i8 %10 to i64
  %12 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift1_E, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !20
  %14 = sext i8 %13 to i32
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %34

16:                                               ; preds = %1
  %17 = load i8, ptr %4, align 1, !tbaa !20
  %18 = zext i8 %17 to i32
  %19 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %20 = load i8, ptr %19, align 8, !tbaa !21
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask1_E, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !20
  %24 = zext i8 %23 to i32
  %25 = and i32 %18, %24
  %26 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %27 = load i8, ptr %26, align 8, !tbaa !21
  %28 = zext i8 %27 to i64
  %29 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift1_E, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !20
  %31 = sext i8 %30 to i32
  %32 = ashr i32 %25, %31
  %33 = sext i32 %32 to i64
  store i64 %33, ptr %3, align 8, !tbaa !9
  br label %53

34:                                               ; preds = %1
  %35 = load i8, ptr %4, align 1, !tbaa !20
  %36 = zext i8 %35 to i32
  %37 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %38 = load i8, ptr %37, align 8, !tbaa !21
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask1_E, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !20
  %42 = zext i8 %41 to i32
  %43 = and i32 %36, %42
  %44 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %45 = load i8, ptr %44, align 8, !tbaa !21
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift1_E, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !20
  %49 = sext i8 %48 to i32
  %50 = sub nsw i32 0, %49
  %51 = shl i32 %43, %50
  %52 = sext i32 %51 to i64
  store i64 %52, ptr %3, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %34, %16
  %54 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %55 = load i8, ptr %54, align 8, !tbaa !21
  %56 = zext i8 %55 to i64
  %57 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask2_E, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !20
  %59 = zext i8 %58 to i32
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %84

61:                                               ; preds = %53
  %62 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = getelementptr inbounds i8, ptr %63, i64 1
  %65 = load i8, ptr %64, align 1, !tbaa !20
  %66 = zext i8 %65 to i32
  %67 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %68 = load i8, ptr %67, align 8, !tbaa !21
  %69 = zext i8 %68 to i64
  %70 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask2_E, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !20
  %72 = zext i8 %71 to i32
  %73 = and i32 %66, %72
  %74 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %75 = load i8, ptr %74, align 8, !tbaa !21
  %76 = zext i8 %75 to i64
  %77 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift2_E, i64 0, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !20
  %79 = zext i8 %78 to i32
  %80 = ashr i32 %73, %79
  %81 = sext i32 %80 to i64
  %82 = load i64, ptr %3, align 8, !tbaa !9
  %83 = or i64 %82, %81
  store i64 %83, ptr %3, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %61, %53
  %85 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %86 = load i8, ptr %85, align 8, !tbaa !21
  %87 = zext i8 %86 to i32
  %88 = icmp ne i32 %87, 0
  %89 = zext i1 %88 to i32
  %90 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 2
  %91 = load ptr, ptr %90, align 8, !tbaa !11
  %92 = sext i32 %89 to i64
  %93 = getelementptr inbounds i8, ptr %91, i64 %92
  store ptr %93, ptr %90, align 8, !tbaa !11
  %94 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  %95 = load i8, ptr %94, align 8, !tbaa !21
  %96 = zext i8 %95 to i32
  %97 = add nsw i32 %96, 1
  %98 = srem i32 %97, 4
  %99 = trunc i32 %98 to i8
  %100 = getelementptr inbounds %class.charStream6, ptr %5, i32 0, i32 3
  store i8 %99, ptr %100, align 8, !tbaa !21
  %101 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %101
}

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, !6, i64 40}
!12 = !{!"_ZTS11charStream6", !13, i64 0, !6, i64 40, !7, i64 48}
!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 = !{!7, !7, i64 0}
!21 = !{!12, !7, i64 48}


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

@_ZN11charStream66mask1_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN11charStream66mask2_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN11charStream67shift1_E = external dso_local local_unnamed_addr constant [4 x i8], align 1
@_ZN11charStream67shift2_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 @_ZN11charStream613getNextUnsafeEv(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 @_ZN11charStream67shift1_E, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !17
  %10 = sext i8 %9 to i32
  %11 = icmp sgt i8 %9, 0
  %12 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask1_E, i64 0, i64 %7
  %13 = load i8, ptr %12, align 1, !tbaa !17
  %14 = and i8 %13, %4
  %15 = zext i8 %14 to i32
  %16 = lshr i32 %15, %10
  %17 = zext nneg i32 %16 to i64
  %18 = sub nsw i32 0, %10
  %19 = shl i32 %15, %18
  %20 = sext i32 %19 to i64
  %.0 = select i1 %11, i64 %17, i64 %20
  %21 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask2_E, i64 0, i64 %7
  %22 = load i8, ptr %21, align 1, !tbaa !17
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %34, label %23

23:                                               ; preds = %1
  %24 = getelementptr inbounds i8, ptr %3, i64 1
  %25 = load i8, ptr %24, align 1, !tbaa !17
  %26 = and i8 %25, %22
  %27 = zext i8 %26 to i32
  %28 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift2_E, i64 0, i64 %7
  %29 = load i8, ptr %28, align 1, !tbaa !17
  %30 = zext nneg i8 %29 to i32
  %31 = lshr i32 %27, %30
  %32 = zext nneg i32 %31 to i64
  %33 = or i64 %.0, %32
  br label %34

34:                                               ; preds = %23, %1
  %.1 = phi i64 [ %33, %23 ], [ %.0, %1 ]
  %35 = icmp ne i8 %6, 0
  %36 = zext i1 %35 to i64
  %37 = getelementptr inbounds i8, ptr %3, i64 %36
  store ptr %37, ptr %2, align 8, !tbaa !5
  %38 = add i8 %6, 1
  %39 = and i8 %38, 3
  store i8 %39, ptr %5, align 8, !tbaa !18
  ret i64 %.1
}

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 = !{!"_ZTS11charStream6", !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,SimplifyCFGPass