#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 */
scalar_t__ EOF;
scalar_t__ MIDI_Fpeek(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
unsigned int MIDI_ReadV(FILE *fp) {
  unsigned int acc = 0;
  unsigned char val = 0;
  while (1) {
    if (EOF == MIDI_Fpeek(fp)) {
      return acc;
    }
    val = (fgetc(fp) & 0x00ff);
    acc |= (val & 0x7F);
    if (0 == (val & 0x80)) {
      return acc;
    }
    acc <<= 7;
  }
}


x86 assembly (clang, -O0):
<MIDI_ReadV>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <MIDI_Fpeek@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    1169 <MIDI_ReadV+0x49>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <MIDI_ReadV+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
and    $0xff,%eax
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
and    $0x7f,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movzbl -0x15(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11a6 <MIDI_ReadV+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <MIDI_ReadV+0x94>
mov    -0x14(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <MIDI_ReadV+0x17>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MIDI_ReadV>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    0x2eb6(%rip),%r14
mov    (%r14),%rbx
call   1030 <MIDI_Fpeek@plt>
xor    %ebp,%ebp
cmp    %rax,%rbx
je     1178 <MIDI_ReadV+0x58>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
and    $0x7f,%ebp
or     %ebx,%ebp
test   $0x80,%al
je     1178 <MIDI_ReadV+0x58>
shl    $0x7,%ebp
mov    (%r14),%r12
mov    %r15,%rdi
call   1030 <MIDI_Fpeek@plt>
mov    %ebp,%ebx
cmp    %rax,%r12
jne    1150 <MIDI_ReadV+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i64 0
define i32 @MIDI_ReadV(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i32* %0, i32** %3
store i32 0, i32* %4
store i8 0, i8* %5
br label %6
6: ; preds = %1, %29
%7 = load i64, i64* @EOF
%8 = load i32*, i32** %3
%9 = call i64 @MIDI_Fpeek(i32* %8)
%10 = icmp eq i64 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %32
13: ; preds = %6
%14 = load i32*, i32** %3
%15 = call i32 @fgetc(i32* %14)
%16 = and i32 %15, 255
%17 = trunc i32 %16 to i8
store i8 %17, i8* %5
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = and i32 %19, 127
%21 = load i32, i32* %4
%22 = or i32 %21, %20
store i32 %22, i32* %4
%23 = load i8, i8* %5
%24 = zext i8 %23 to i32
%25 = and i32 %24, 128
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %29
27: ; preds = %13
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %32
29: ; preds = %13
%30 = load i32, i32* %4
%31 = shl i32 %30, 7
store i32 %31, i32* %4
br label %6
32: ; preds = %27, %11
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@EOF = global i64 0
define i32 @MIDI_ReadV(i32* %0) {
%2 = load i64, i64* @EOF
%3 = tail call i64 @MIDI_Fpeek(i32* %0)
%4 = icmp eq i64 %2, %3
br i1 %4, label %17, label %5
5: ; preds = %1, %12
%6 = phi i32 [ %13, %12 ], [ 0, %1 ]
%7 = tail call i32 @fgetc(i32* %0)
%8 = and i32 %7, 127
%9 = or i32 %8, %6
%10 = and i32 %7, 128
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %5
%13 = shl i32 %9, 7
%14 = load i64, i64* @EOF
%15 = tail call i64 @MIDI_Fpeek(i32* %0)
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %5
17: ; preds = %12, %5, %1
%18 = phi i32 [ 0, %1 ], [ %9, %5 ], [ %13, %12 ]
ret i32 %18
}