#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 midigetc();
long readvarinum() {
  long value;
  int c;
  value = c = midigetc();
  if (c & 0x80) {
    value &= 0x7f;
    do {
      c = midigetc();
      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 <midigetc@plt>
mov    %eax,-0xc(%rbp)
cltq
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     117d <readvarinum+0x6d>
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <midigetc@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    1145 <readvarinum+0x35>
jmp    117d <readvarinum+0x6d>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readvarinum>:
push   %rbx
xor    %eax,%eax
call   1030 <midigetc@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 <midigetc@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 (...) @midigetc()
store i32 %3, i32* %2
%4 = sext i32 %3 to i64
store i64 %4, i64* %1
%5 = load i32, i32* %2
%6 = and i32 %5, 128
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %0
%9 = load i64, i64* %1
%10 = and i64 %9, 127
store i64 %10, i64* %1
br label %11
11: ; preds = %19, %8
%12 = call i32 (...) @midigetc()
store i32 %12, i32* %2
%13 = load i64, i64* %1
%14 = shl i64 %13, 7
%15 = load i32, i32* %2
%16 = and i32 %15, 127
%17 = sext i32 %16 to i64
%18 = add nsw i64 %14, %17
store i64 %18, i64* %1
br label %19
19: ; preds = %11
%20 = load i32, i32* %2
%21 = and i32 %20, 128
%22 = icmp ne i32 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %19
br label %24
24: ; preds = %23, %0
%25 = load i64, i64* %1
ret i64 %25
}

LLVM IR (-O2):
define i64 @readvarinum() {
%1 = tail call i32 (...) @midigetc()
%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 (...) @midigetc()
%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
}