#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ uint8_t;
typedef int uint64_t;

/* Variables and functions */
uint64_t vbudecode(uint64_t *value, const uint8_t *buffer) {
  const uint8_t *buffer0 = buffer;
  uint64_t out = 0, j = -7;
  do {
    out |= ((((uint64_t)(*buffer)) & 0x7f) << (j += 7));
  } while (((uint64_t)(*buffer++)) & 0x80);
  *value = out;
  return buffer - buffer0;
}


x86 assembly (clang, -O0):
<vbudecode>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xfffffff9,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
and    $0x7f,%eax
mov    -0x20(%rbp),%ecx
add    $0x7,%ecx
mov    %ecx,-0x20(%rbp)
shl    %cl,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1122 <vbudecode+0x22>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<vbudecode>:
xor    %ecx,%ecx
xor    %eax,%eax
xor    %r9d,%r9d
nopw   0x0(%rax,%rax,1)
mov    (%rsi,%rax,1),%r8d
mov    %r8d,%edx
and    $0x7f,%edx
shl    %cl,%edx
or     %edx,%r9d
add    $0x8,%rax
add    $0x7,%ecx
test   $0x80,%r8b
jne    1110 <vbudecode+0x10>
mov    %r9d,(%rdi)
shr    $0x3,%rax
ret

LLVM IR (-O0):
define i32 @vbudecode(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i64* %1, i64** %4
%8 = load i64*, i64** %4
store i64* %8, i64** %5
store i32 0, i32* %6
store i32 -7, i32* %7
br label %9
9: ; preds = %19, %2
%10 = load i64*, i64** %4
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 127
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 7
store i32 %15, i32* %7
%16 = shl i32 %13, %15
%17 = load i32, i32* %6
%18 = or i32 %17, %16
store i32 %18, i32* %6
br label %19
19: ; preds = %9
%20 = load i64*, i64** %4
%21 = getelementptr inbounds i64, i64* %20, i32 1
store i64* %21, i64** %4
%22 = load i64, i64* %20
%23 = trunc i64 %22 to i32
%24 = and i32 %23, 128
%25 = icmp ne i32 %24, 0
br i1 %25, label %9, label %26
26: ; preds = %19
%27 = load i32, i32* %6
%28 = load i32*, i32** %3
store i32 %27, i32* %28
%29 = load i64*, i64** %4
%30 = load i64*, i64** %5
%31 = ptrtoint i64* %29 to i64
%32 = ptrtoint i64* %30 to i64
%33 = sub i64 %31, %32
%34 = sdiv exact i64 %33, 8
%35 = trunc i64 %34 to i32
ret i32 %35
}

LLVM IR (-O2):
define i32 @vbudecode(i32* nocapture writeonly %0, i64* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64* [ %1, %2 ], [ %13, %3 ]
%5 = phi i32 [ 0, %2 ], [ %12, %3 ]
%6 = phi i32 [ -7, %2 ], [ %10, %3 ]
%7 = load i64, i64* %4
%8 = trunc i64 %7 to i32
%9 = and i32 %8, 127
%10 = add nsw i32 %6, 7
%11 = shl i32 %9, %10
%12 = or i32 %11, %5
%13 = getelementptr inbounds i64, i64* %4, i64 1
%14 = and i32 %8, 128
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %3
16: ; preds = %3
store i32 %12, i32* %0
%17 = ptrtoint i64* %13 to i64
%18 = ptrtoint i64* %1 to i64
%19 = sub i64 %17, %18
%20 = lshr exact i64 %19, 3
%21 = trunc i64 %20 to i32
ret i32 %21
}