; LLVM IR from trustwallet/wallet-core :: src/FIO/Action.ll (ZN2TW3FIO12encodeVarIntEmRSt6vectorIhSaIhEE)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN2TW3FIO12encodeVarIntEmRSt6vectorIhSaIhEE(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !11
  br label %6

6:                                                ; preds = %25, %2
  br label %7

7:                                                ; preds = %6
  %8 = load i8, ptr %5, align 1, !tbaa !11
  %9 = add i8 %8, 1
  store i8 %9, ptr %5, align 1, !tbaa !11
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = lshr i64 %10, 7
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %7
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = and i64 %15, 127
  %17 = or i64 128, %16
  %18 = trunc i64 %17 to i8
  call void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24) %14, i8 noundef zeroext %18)
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = lshr i64 %19, 7
  store i64 %20, ptr %3, align 8, !tbaa !5
  br label %25

21:                                               ; preds = %7
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = trunc i64 %23 to i8
  call void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24) %22, i8 noundef zeroext %24)
  br label %26

25:                                               ; preds = %13
  br label %6, !llvm.loop !12

26:                                               ; preds = %21
  %27 = load i8, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  ret i8 %27
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 uwtable
define dso_local noundef zeroext i8 @_ZN2TW3FIO12encodeVarIntEmRSt6vectorIhSaIhEE(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #0 {
  %.not9 = icmp ult i64 %0, 128
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %3 = phi i8 [ %7, %.lr.ph ], [ 1, %2 ]
  %.0710 = phi i64 [ %4, %.lr.ph ], [ %0, %2 ]
  %4 = lshr i64 %.0710, 7
  %5 = trunc i64 %.0710 to i8
  %6 = or i8 %5, -128
  tail call void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24) %1, i8 noundef zeroext %6)
  %7 = add nuw nsw i8 %3, 1
  %.not = icmp ult i64 %.0710, 16384
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.07.lcssa = phi i64 [ %0, %2 ], [ %4, %.lr.ph ]
  %.lcssa = phi i8 [ 1, %2 ], [ %7, %.lr.ph ]
  %8 = trunc nuw i64 %.07.lcssa to i8
  tail call void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24) %1, i8 noundef zeroext %8)
  ret i8 %.lcssa
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN2TW6appendERSt6vectorIhSaIhEEh(ptr noundef nonnull align 8 dereferenceable(24), i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass