; LLVM IR from yinqiwen/ardb :: src/common/buffer/buffer_helper.ll (ZN4ardb12BufferHelper13ReadVarUInt64ERNS_6BufferERm)

; 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: 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) #1 align 2

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

11:                                               ; preds = %37, %2
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = icmp eq i32 %12, 10
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %44

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %16, ptr noundef %10, i64 noundef 1)
  %18 = icmp ne i32 1, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %34

20:                                               ; preds = %15
  %21 = load i8, ptr %10, align 1, !tbaa !13
  %22 = zext i8 %21 to i32
  store i32 %22, ptr %8, align 4, !tbaa !11
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = and i32 %23, 127
  %25 = zext i32 %24 to i64
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = mul nsw i32 7, %26
  %28 = zext i32 %27 to i64
  %29 = shl i64 %25, %28
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = or i64 %30, %29
  store i64 %31, ptr %6, align 8, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !11
  store i32 0, ptr %9, align 4
  br label %34

34:                                               ; preds = %20, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %35 = load i32, ptr %9, align 4
  switch i32 %35, label %44 [
    i32 0, label %36
  ]

36:                                               ; preds = %34
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %8, align 4, !tbaa !11
  %39 = and i32 %38, 128
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %11, label %41, !llvm.loop !14

41:                                               ; preds = %37
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %42, ptr %43, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %44

44:                                               ; preds = %41, %34, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %45 = load i1, ptr %3, align 1
  ret i1 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb12BufferHelper13ReadVarUInt64ERNS_6BufferERm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %4 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not = icmp eq i32 %4, 1
  br i1 %.not, label %6, label %5

5:                                                ; preds = %74, %66, %58, %50, %42, %34, %26, %18, %10, %2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  br label %.loopexit

6:                                                ; preds = %2
  %7 = load i8, ptr %3, align 1, !tbaa !5
  %8 = and i8 %7, 127
  %9 = zext nneg i8 %8 to i64
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17 = icmp sgt i8 %7, -1
  br i1 %.not17, label %81, label %10, !llvm.loop !8

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %11 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.1 = icmp eq i32 %11, 1
  br i1 %.not.1, label %12, label %5

12:                                               ; preds = %10
  %13 = load i8, ptr %3, align 1, !tbaa !5
  %14 = and i8 %13, 127
  %15 = zext nneg i8 %14 to i64
  %16 = shl nuw nsw i64 %15, 7
  %17 = or disjoint i64 %16, %9
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.1 = icmp sgt i8 %13, -1
  br i1 %.not17.1, label %81, label %18, !llvm.loop !8

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %19 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.2 = icmp eq i32 %19, 1
  br i1 %.not.2, label %20, label %5

20:                                               ; preds = %18
  %21 = load i8, ptr %3, align 1, !tbaa !5
  %22 = and i8 %21, 127
  %23 = zext nneg i8 %22 to i64
  %24 = shl nuw nsw i64 %23, 14
  %25 = or disjoint i64 %24, %17
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.2 = icmp sgt i8 %21, -1
  br i1 %.not17.2, label %81, label %26, !llvm.loop !8

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %27 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.3 = icmp eq i32 %27, 1
  br i1 %.not.3, label %28, label %5

28:                                               ; preds = %26
  %29 = load i8, ptr %3, align 1, !tbaa !5
  %30 = and i8 %29, 127
  %31 = zext nneg i8 %30 to i64
  %32 = shl nuw nsw i64 %31, 21
  %33 = or disjoint i64 %32, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.3 = icmp sgt i8 %29, -1
  br i1 %.not17.3, label %81, label %34, !llvm.loop !8

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %35 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.4 = icmp eq i32 %35, 1
  br i1 %.not.4, label %36, label %5

36:                                               ; preds = %34
  %37 = load i8, ptr %3, align 1, !tbaa !5
  %38 = and i8 %37, 127
  %39 = zext nneg i8 %38 to i64
  %40 = shl nuw nsw i64 %39, 28
  %41 = or disjoint i64 %40, %33
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.4 = icmp sgt i8 %37, -1
  br i1 %.not17.4, label %81, label %42, !llvm.loop !8

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %43 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.5 = icmp eq i32 %43, 1
  br i1 %.not.5, label %44, label %5

44:                                               ; preds = %42
  %45 = load i8, ptr %3, align 1, !tbaa !5
  %46 = and i8 %45, 127
  %47 = zext nneg i8 %46 to i64
  %48 = shl nuw nsw i64 %47, 35
  %49 = or i64 %48, %41
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.5 = icmp sgt i8 %45, -1
  br i1 %.not17.5, label %81, label %50, !llvm.loop !8

50:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %51 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.6 = icmp eq i32 %51, 1
  br i1 %.not.6, label %52, label %5

52:                                               ; preds = %50
  %53 = load i8, ptr %3, align 1, !tbaa !5
  %54 = and i8 %53, 127
  %55 = zext nneg i8 %54 to i64
  %56 = shl nuw nsw i64 %55, 42
  %57 = or i64 %56, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.6 = icmp sgt i8 %53, -1
  br i1 %.not17.6, label %81, label %58, !llvm.loop !8

58:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %59 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.7 = icmp eq i32 %59, 1
  br i1 %.not.7, label %60, label %5

60:                                               ; preds = %58
  %61 = load i8, ptr %3, align 1, !tbaa !5
  %62 = and i8 %61, 127
  %63 = zext nneg i8 %62 to i64
  %64 = shl nuw nsw i64 %63, 49
  %65 = or i64 %64, %57
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.7 = icmp sgt i8 %61, -1
  br i1 %.not17.7, label %81, label %66, !llvm.loop !8

66:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %67 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.8 = icmp eq i32 %67, 1
  br i1 %.not.8, label %68, label %5

68:                                               ; preds = %66
  %69 = load i8, ptr %3, align 1, !tbaa !5
  %70 = and i8 %69, 127
  %71 = zext nneg i8 %70 to i64
  %72 = shl nuw nsw i64 %71, 56
  %73 = or i64 %72, %65
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.8 = icmp sgt i8 %69, -1
  br i1 %.not17.8, label %81, label %74, !llvm.loop !8

74:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %75 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull %3, i64 noundef 1)
  %.not.9 = icmp eq i32 %75, 1
  br i1 %.not.9, label %76, label %5

76:                                               ; preds = %74
  %77 = load i8, ptr %3, align 1, !tbaa !5
  %78 = zext i8 %77 to i64
  %79 = shl i64 %78, 63
  %80 = or i64 %79, %73
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  %.not17.9 = icmp sgt i8 %77, -1
  br i1 %.not17.9, label %81, label %.loopexit, !llvm.loop !8

81:                                               ; preds = %76, %68, %60, %52, %44, %36, %28, %20, %12, %6
  %.lcssa = phi i64 [ %9, %6 ], [ %17, %12 ], [ %25, %20 ], [ %33, %28 ], [ %41, %36 ], [ %49, %44 ], [ %57, %52 ], [ %65, %60 ], [ %73, %68 ], [ %80, %76 ]
  store i64 %.lcssa, ptr %1, align 8, !tbaa !10
  br label %.loopexit

.loopexit:                                        ; preds = %76, %5, %81
  %.2 = phi i1 [ true, %81 ], [ false, %5 ], [ false, %76 ]
  ret i1 %.2
}

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass