#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
unsigned long getc(int /*<<< orphan*/ *);
unsigned long int variable_byte_decode(int *bytes, FILE *stream) {
  unsigned long int x, b;
  int shift;
  x = 0, shift = 0, b = 0;
  while ((*bytes)-- && (b = getc(stream)) > 127 && !feof(stream)) {
    x |= (b & 127) << shift;
    shift += 7;
  }
  return x | (b << shift);
}


x86 assembly (clang, -O0):
<variable_byte_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,(%rax)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     1195 <variable_byte_decode+0x75>
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x7f,%rcx
mov    %al,-0x25(%rbp)
jbe    1195 <variable_byte_decode+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11a5 <variable_byte_decode+0x85>
jmp    11c9 <variable_byte_decode+0xa9>
mov    -0x20(%rbp),%rax
and    $0x7f,%rax
mov    -0x24(%rbp),%ecx
shl    %cl,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x24(%rbp)
jmp    1147 <variable_byte_decode+0x27>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
shl    %cl,%rdx
mov    %rdx,%rcx
or     %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variable_byte_decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
subl   $0x1,(%rdi)
jae    1133 <variable_byte_decode+0x13>
xor    %r14d,%r14d
jmp    1180 <variable_byte_decode+0x60>
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
xor    %r13d,%r13d
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <getc@plt>
mov    %rax,%r14
cmp    $0x80,%rax
jb     1178 <variable_byte_decode+0x58>
mov    %r15,%rdi
call   1030 <feof@plt>
test   %eax,%eax
jne    1178 <variable_byte_decode+0x58>
mov    %r14d,%eax
and    $0x7f,%eax
mov    %ebx,%ecx
shl    %cl,%rax
or     %rax,%r13
add    $0x7,%rbx
subl   $0x1,(%r12)
jae    1140 <variable_byte_decode+0x20>
mov    %ebx,%ecx
shl    %cl,%r14
or     %r13,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @variable_byte_decode(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i64 0, i64* %5
store i32 0, i32* %7
store i64 0, i64* %6
br label %8
8: ; preds = %24, %2
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
%11 = add nsw i32 %10, -1
store i32 %11, i32* %9
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i32*, i32** %4
%15 = call i64 @getc(i32* %14)
store i64 %15, i64* %6
%16 = icmp ugt i64 %15, 127
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32*, i32** %4
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br label %22
22: ; preds = %17, %13, %8
%23 = phi i1 [ false, %13 ], [ false, %8 ], [ %21, %17 ]
br i1 %23, label %24, label %34
24: ; preds = %22
%25 = load i64, i64* %6
%26 = and i64 %25, 127
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = shl i64 %26, %28
%30 = load i64, i64* %5
%31 = or i64 %30, %29
store i64 %31, i64* %5
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 7
store i32 %33, i32* %7
br label %8
34: ; preds = %22
%35 = load i64, i64* %5
%36 = load i64, i64* %6
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = shl i64 %36, %38
%40 = or i64 %35, %39
ret i64 %40
}

LLVM IR (-O2):
define i64 @variable_byte_decode(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = add nsw i32 %3, -1
store i32 %4, i32* %0
%5 = icmp eq i32 %3, 0
br i1 %5, label %28, label %6
6: ; preds = %2, %14
%7 = phi i64 [ %18, %14 ], [ 0, %2 ]
%8 = phi i64 [ %17, %14 ], [ 0, %2 ]
%9 = tail call i64 @getc(i32* %1)
%10 = icmp ugt i64 %9, 127
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = tail call i32 @feof(i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = and i64 %9, 127
%16 = shl i64 %15, %7
%17 = or i64 %16, %8
%18 = add nuw i64 %7, 7
%19 = load i32, i32* %0
%20 = add nsw i32 %19, -1
store i32 %20, i32* %0
%21 = icmp eq i32 %19, 0
br i1 %21, label %22, label %6
22: ; preds = %14, %6, %11
%23 = phi i64 [ %8, %11 ], [ %8, %6 ], [ %17, %14 ]
%24 = phi i64 [ %7, %11 ], [ %7, %6 ], [ %18, %14 ]
%25 = and i64 %24, 4294967295
%26 = shl i64 %9, %25
%27 = or i64 %26, %23
br label %28
28: ; preds = %22, %2
%29 = phi i64 [ %27, %22 ], [ 0, %2 ]
ret i64 %29
}