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

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

@_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 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 @_ZN11charStream63addEm(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.charStream6, 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 %27

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 = getelementptr inbounds %class.charStream6, ptr %7, 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 @_ZN11charStream67shift1_E, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !21
  %23 = sext i8 %22 to i32
  %24 = zext i32 %23 to i64
  %25 = shl i64 %17, %24
  %26 = trunc i64 %25 to i8
  store i8 %26, 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 %44

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

44:                                               ; preds = %27, %15
  %45 = getelementptr inbounds %class.charStream6, ptr %7, i32 0, i32 3
  %46 = load i8, ptr %45, align 8, !tbaa !19
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask2_E, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !21
  %50 = zext i8 %49 to i32
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %64

52:                                               ; preds = %44
  %53 = getelementptr inbounds %class.charStreamNonNative, ptr %7, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %54 = load i64, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %class.charStream6, ptr %7, i32 0, i32 3
  %56 = load i8, ptr %55, align 8, !tbaa !19
  %57 = zext i8 %56 to i64
  %58 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift2_E, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !21
  %60 = zext i8 %59 to i32
  %61 = zext i32 %60 to i64
  %62 = shl i64 %54, %61
  %63 = trunc i64 %62 to i8
  store i8 %63, ptr %6, align 1, !tbaa !21
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %53, ptr noundef nonnull align 1 dereferenceable(1) %6)
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %64

64:                                               ; preds = %52, %44
  %65 = getelementptr inbounds %class.charStream6, ptr %7, i32 0, i32 3
  %66 = load i8, ptr %65, align 8, !tbaa !19
  %67 = zext i8 %66 to i32
  %68 = add nsw i32 %67, 1
  %69 = srem i32 %68, 4
  %70 = trunc i32 %69 to i8
  %71 = getelementptr inbounds %class.charStream6, ptr %7, i32 0, i32 3
  store i8 %70, ptr %71, 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 = !{!"_ZTS11charStream6", !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"

@_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 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 @_ZN11charStream63addEm(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 %18

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 @_ZN11charStream67shift1_E, align 1, !tbaa !18
  %14 = sext i8 %13 to i64
  %15 = and i64 %14, 4294967295
  %16 = shl i64 %1, %15
  %17 = trunc i64 %16 to i8
  store i8 %17, 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 %31

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

31:                                               ; preds = %18, %11
  %32 = load i8, ptr %8, align 8, !tbaa !16
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream66mask2_E, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !18
  %.not = icmp eq i8 %35, 0
  br i1 %.not, label %43, label %36

36:                                               ; preds = %31
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %38 = getelementptr inbounds [4 x i8], ptr @_ZN11charStream67shift2_E, i64 0, i64 %33
  %39 = load i8, ptr %38, align 1, !tbaa !18
  %40 = zext nneg i8 %39 to i64
  %41 = shl i64 %1, %40
  %42 = trunc i64 %41 to i8
  store i8 %42, ptr %4, align 1, !tbaa !18
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %37, ptr noundef nonnull align 1 dereferenceable(1) %4)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  %.pre = load i8, ptr %8, align 8, !tbaa !16
  br label %43

43:                                               ; preds = %36, %31
  %44 = phi i8 [ %.pre, %36 ], [ %32, %31 ]
  %45 = add i8 %44, 1
  %46 = and i8 %45, 3
  store i8 %46, 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 = !{!"_ZTS11charStream6", !6, i64 0, !12, i64 40, !13, i64 48}
!18 = !{!13, !13, i64 0}


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