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

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

@_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 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 @_ZN11charStream43addEm(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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.charStreamNonNative, ptr %6, i32 0, i32 2
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = add i32 %8, 1
  store i32 %9, ptr %7, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.charStream4, ptr %6, i32 0, i32 3
  %11 = load i8, ptr %10, align 8, !tbaa !19, !range !22, !noundef !23
  %12 = trunc i8 %11 to i1
  br i1 %12, label %13, label %26

13:                                               ; preds = %2
  %14 = getelementptr inbounds %class.charStreamNonNative, ptr %6, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %class.charStream4, ptr %6, i32 0, i32 3
  %17 = load i8, ptr %16, align 8, !tbaa !19, !range !22, !noundef !23
  %18 = trunc i8 %17 to i1
  %19 = zext i1 %18 to i64
  %20 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream46shift_E, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !24
  %22 = zext i8 %21 to i32
  %23 = zext i32 %22 to i64
  %24 = shl i64 %15, %23
  %25 = trunc i64 %24 to i8
  store i8 %25, ptr %5, align 1, !tbaa !24
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %43

26:                                               ; preds = %2
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %class.charStream4, ptr %6, i32 0, i32 3
  %29 = load i8, ptr %28, align 8, !tbaa !19, !range !22, !noundef !23
  %30 = trunc i8 %29 to i1
  %31 = zext i1 %30 to i64
  %32 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream46shift_E, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !24
  %34 = zext i8 %33 to i32
  %35 = zext i32 %34 to i64
  %36 = shl i64 %27, %35
  %37 = getelementptr inbounds %class.charStreamNonNative, ptr %6, i32 0, i32 1
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %37) #3
  %39 = load i8, ptr %38, align 1, !tbaa !24
  %40 = zext i8 %39 to i64
  %41 = or i64 %40, %36
  %42 = trunc i64 %41 to i8
  store i8 %42, ptr %38, align 1, !tbaa !24
  br label %43

43:                                               ; preds = %26, %13
  %44 = getelementptr inbounds %class.charStream4, ptr %6, i32 0, i32 3
  %45 = load i8, ptr %44, align 8, !tbaa !19, !range !22, !noundef !23
  %46 = trunc i8 %45 to i1
  %47 = xor i1 %46, true
  %48 = getelementptr inbounds %class.charStream4, ptr %6, i32 0, i32 3
  %49 = zext i1 %47 to i8
  store i8 %49, ptr %48, 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, !21, i64 48}
!20 = !{!"_ZTS11charStream4", !12, i64 0, !6, i64 40, !21, i64 48}
!21 = !{!"bool", !7, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!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"

@_ZN11charStream46shift_E = external dso_local local_unnamed_addr constant [2 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 @_ZN11charStream43addEm(ptr noundef nonnull align 8 dereferenceable(49) %0, i64 noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca i8, align 1
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = add i32 %5, 1
  store i32 %6, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load i8, ptr %7, align 8, !tbaa !16, !range !19, !noundef !20
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %12 = zext nneg i8 %8 to i64
  %13 = getelementptr inbounds [2 x i8], ptr @_ZN11charStream46shift_E, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !21
  %15 = zext nneg i8 %14 to i64
  %16 = shl i64 %1, %15
  %17 = trunc i64 %16 to i8
  store i8 %17, ptr %3, align 1, !tbaa !21
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %11, ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  br label %27

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

27:                                               ; preds = %18, %10
  %28 = load i8, ptr %7, align 8, !tbaa !16, !range !19, !noundef !20
  %29 = xor i8 %28, 1
  store i8 %29, ptr %7, 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, !18, i64 48}
!17 = !{!"_ZTS11charStream4", !6, i64 0, !12, i64 40, !18, i64 48}
!18 = !{!"bool", !13, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!13, !13, i64 0}


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