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

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

@_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 uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12charStream103addEm(ptr noundef nonnull align 8 dereferenceable(49) %0, i64 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.charStreamNonNative, ptr %7, i32 0, i32 2
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = add i32 %9, 1
  store i32 %10, ptr %8, align 8, !tbaa !11
  %11 = getelementptr inbounds %class.charStream10, ptr %7, i32 0, i32 3
  %12 = load i8, ptr %11, align 8, !tbaa !19
  %13 = zext i8 %12 to i32
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %2
  %16 = getelementptr inbounds %class.charStreamNonNative, ptr %7, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = load i8, ptr @_ZN12charStream108lshift1_E, align 1, !tbaa !21
  %19 = zext i8 %18 to i32
  %20 = zext i32 %19 to i64
  %21 = lshr i64 %17, %20
  %22 = trunc i64 %21 to i8
  store i8 %22, ptr %5, align 1, !tbaa !21
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %39

23:                                               ; preds = %2
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %class.charStream10, ptr %7, i32 0, i32 3
  %26 = load i8, ptr %25, align 8, !tbaa !19
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream108lshift1_E, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !21
  %30 = zext i8 %29 to i32
  %31 = zext i32 %30 to i64
  %32 = lshr i64 %24, %31
  %33 = getelementptr inbounds %class.charStreamNonNative, ptr %7, i32 0, i32 1
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %33) #3
  %35 = load i8, ptr %34, align 1, !tbaa !21
  %36 = zext i8 %35 to i64
  %37 = or i64 %36, %32
  %38 = trunc i64 %37 to i8
  store i8 %38, ptr %34, align 1, !tbaa !21
  br label %39

39:                                               ; preds = %23, %15
  %40 = getelementptr inbounds %class.charStreamNonNative, ptr %7, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %41 = load i64, ptr %4, align 8, !tbaa !9
  %42 = getelementptr inbounds %class.charStream10, ptr %7, i32 0, i32 3
  %43 = load i8, ptr %42, align 8, !tbaa !19
  %44 = zext i8 %43 to i64
  %45 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream107shift2_E, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !21
  %47 = zext i8 %46 to i32
  %48 = zext i32 %47 to i64
  %49 = shl i64 %41, %48
  %50 = trunc i64 %49 to i8
  store i8 %50, ptr %6, align 1, !tbaa !21
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %40, ptr noundef nonnull align 1 dereferenceable(1) %6)
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %51 = getelementptr inbounds %class.charStream10, ptr %7, i32 0, i32 3
  %52 = load i8, ptr %51, align 8, !tbaa !19
  %53 = zext i8 %52 to i32
  %54 = add nsw i32 %53, 1
  %55 = srem i32 %54, 4
  %56 = trunc i32 %55 to i8
  %57 = getelementptr inbounds %class.charStream10, ptr %7, i32 0, i32 3
  store i8 %56, ptr %57, align 8, !tbaa !19
  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 = { 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 #3 = { 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, !18, i64 32}
!12 = !{!"_ZTS19charStreamNonNative", !13, i64 0, !14, i64 8, !18, i64 32}
!13 = !{!"_ZTS10charStream"}
!14 = !{!"_ZTSSt6vectorIhSaIhEE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !7, i64 48}
!20 = !{!"_ZTS12charStream10", !12, i64 0, !6, i64 40, !7, i64 48}
!21 = !{!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"

@_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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12charStream103addEm(ptr noundef nonnull align 8 dereferenceable(49) %0, i64 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add i32 %6, 1
  store i32 %7, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i8, ptr %8, align 8, !tbaa !16
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %17

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %13 = load i8, ptr @_ZN12charStream108lshift1_E, align 1, !tbaa !18
  %14 = zext nneg i8 %13 to i64
  %15 = lshr i64 %1, %14
  %16 = trunc i64 %15 to i8
  store i8 %16, ptr %3, align 1, !tbaa !18
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  br label %28

17:                                               ; preds = %2
  %18 = zext i8 %9 to i64
  %19 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream108lshift1_E, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !18
  %21 = zext nneg i8 %20 to i64
  %22 = lshr i64 %1, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %23) #3
  %25 = load i8, ptr %24, align 1, !tbaa !18
  %26 = trunc i64 %22 to i8
  %27 = or i8 %25, %26
  store i8 %27, ptr %24, align 1, !tbaa !18
  br label %28

28:                                               ; preds = %17, %11
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %30 = load i8, ptr %8, align 8, !tbaa !16
  %31 = zext i8 %30 to i64
  %32 = getelementptr inbounds [4 x i8], ptr @_ZN12charStream107shift2_E, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !18
  %34 = zext nneg i8 %33 to i64
  %35 = shl i64 %1, %34
  %36 = trunc i64 %35 to i8
  store i8 %36, ptr %4, align 1, !tbaa !18
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %29, ptr noundef nonnull align 1 dereferenceable(1) %4)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  %37 = load i8, ptr %8, align 8, !tbaa !16
  %38 = add i8 %37, 1
  %39 = and i8 %38, 3
  store i8 %39, ptr %8, align 8, !tbaa !16
  ret void
}

attributes #0 = { mustprogress 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 = { 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 #3 = { 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, !15, i64 32}
!6 = !{!"_ZTS19charStreamNonNative", !7, i64 0, !8, i64 8, !15, i64 32}
!7 = !{!"_ZTS10charStream"}
!8 = !{!"_ZTSSt6vectorIhSaIhEE", !9, i64 0}
!9 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !11, i64 0}
!11 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"int", !13, i64 0}
!16 = !{!17, !13, i64 48}
!17 = !{!"_ZTS12charStream10", !6, i64 0, !12, i64 40, !13, i64 48}
!18 = !{!13, !13, i64 0}


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