#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 */

/* Variables and functions */
int egetc();
long readvarinum() {
  long value;
  int c;
  c = egetc();
  value = c;
  if (c & 0x80) {
    value &= 0x7f;
    do {
      c = egetc();
      value = (value << 7) + (c & 0x7f);
    } while (c & 0x80);
  }
  return (value);
}


x86 assembly (clang, -O0):
<readvarinum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <egetc@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     117f <readvarinum+0x6f>
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <egetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x7,%rax
mov    -0xc(%rbp),%ecx
and    $0x7f,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1147 <readvarinum+0x37>
jmp    117f <readvarinum+0x6f>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readvarinum>:
push   %rbx
xor    %eax,%eax
call   1030 <egetc@plt>
mov    %eax,%ebx
test   $0x80,%bl
jne    1124 <readvarinum+0x14>
movslq %ebx,%rbx
jmp    1147 <readvarinum+0x37>
and    $0x7f,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <egetc@plt>
shl    $0x7,%rbx
mov    %eax,%ecx
and    $0x7f,%ecx
or     %rcx,%rbx
test   $0x80,%al
jne    1130 <readvarinum+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @readvarinum() {
%1 = alloca i64
%2 = alloca i32
%3 = call i32 (...) @egetc()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = sext i32 %4 to i64
store i64 %5, i64* %1
%6 = load i32, i32* %2
%7 = and i32 %6, 128
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %0
%10 = load i64, i64* %1
%11 = and i64 %10, 127
store i64 %11, i64* %1
br label %12
12: ; preds = %20, %9
%13 = call i32 (...) @egetc()
store i32 %13, i32* %2
%14 = load i64, i64* %1
%15 = shl i64 %14, 7
%16 = load i32, i32* %2
%17 = and i32 %16, 127
%18 = sext i32 %17 to i64
%19 = add nsw i64 %15, %18
store i64 %19, i64* %1
br label %20
20: ; preds = %12
%21 = load i32, i32* %2
%22 = and i32 %21, 128
%23 = icmp ne i32 %22, 0
br i1 %23, label %12, label %24
24: ; preds = %20
br label %25
25: ; preds = %24, %0
%26 = load i64, i64* %1
ret i64 %26
}

LLVM IR (-O2):
define i64 @readvarinum() {
%1 = tail call i32 (...) @egetc()
%2 = sext i32 %1 to i64
%3 = and i32 %1, 128
%4 = icmp eq i32 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = and i64 %2, 127
br label %7
7: ; preds = %7, %5
%8 = phi i64 [ %6, %5 ], [ %13, %7 ]
%9 = tail call i32 (...) @egetc()
%10 = shl i64 %8, 7
%11 = and i32 %9, 127
%12 = zext i32 %11 to i64
%13 = or i64 %10, %12
%14 = and i32 %9, 128
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %0
%17 = phi i64 [ %2, %0 ], [ %13, %7 ]
ret i64 %17
}