#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*/ IO_Read_UBYTE(unsigned char *, int /*<<< orphan*/ *);
int vlq_read_short(FILE *fp, short *v) {
  unsigned char c;
  short s;
  if (!IO_Read_UBYTE(&c, fp))
    return 0;
  s = c & 0x7f;
  if (c & 0x80) {
    *v = s - 64;
    return 1;
  }
  if (!IO_Read_UBYTE(&c, fp))
    return 0;
  s = (s << 8) | (c & 0xff);
  *v = s - 16384;
  return 1;
}


x86 assembly (clang, -O0):
<vlq_read_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x19(%rbp),%rdi
call   1030 <IO_Read_UBYTE@plt>
cmp    $0x0,%eax
jne    1142 <vlq_read_short+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11cf <vlq_read_short+0xbf>
movzbl -0x19(%rbp),%eax
and    $0x7f,%eax
mov    %ax,-0x1c(%rbp)
movzbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     117c <vlq_read_short+0x6c>
movswl -0x1c(%rbp),%eax
sub    $0x40,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11cf <vlq_read_short+0xbf>
mov    -0x10(%rbp),%rsi
lea    -0x19(%rbp),%rdi
call   1030 <IO_Read_UBYTE@plt>
cmp    $0x0,%eax
jne    119e <vlq_read_short+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11cf <vlq_read_short+0xbf>
movswl -0x1c(%rbp),%eax
shl    $0x8,%eax
movzbl -0x19(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %ax,-0x1c(%rbp)
movswl -0x1c(%rbp),%eax
sub    $0x4000,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlq_read_short>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <IO_Read_UBYTE@plt>
xor    %r15d,%r15d
test   %eax,%eax
je     1175 <vlq_read_short+0x65>
movzbl 0x7(%rsp),%eax
mov    %eax,%ebp
and    $0x7f,%ebp
test   %al,%al
js     1165 <vlq_read_short+0x55>
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <IO_Read_UBYTE@plt>
test   %eax,%eax
je     1175 <vlq_read_short+0x65>
movzbl %bpl,%eax
shl    $0x8,%eax
movzbl 0x7(%rsp),%ecx
add    %ecx,%eax
add    $0xffffc000,%eax
jmp    116b <vlq_read_short+0x5b>
movzwl %bp,%eax
add    $0xffffffc0,%eax
mov    %ax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @vlq_read_short(i32* %0, i16* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i16*
%6 = alloca i8
%7 = alloca i16
store i32* %0, i32** %4
store i16* %1, i16** %5
%8 = load i32*, i32** %4
%9 = call i32 @IO_Read_UBYTE(i8* %6, i32* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %46
12: ; preds = %2
%13 = load i8, i8* %6
%14 = zext i8 %13 to i32
%15 = and i32 %14, 127
%16 = trunc i32 %15 to i16
store i16 %16, i16* %7
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = and i32 %18, 128
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %12
%22 = load i16, i16* %7
%23 = sext i16 %22 to i32
%24 = sub nsw i32 %23, 64
%25 = trunc i32 %24 to i16
%26 = load i16*, i16** %5
store i16 %25, i16* %26
store i32 1, i32* %3
br label %46
27: ; preds = %12
%28 = load i32*, i32** %4
%29 = call i32 @IO_Read_UBYTE(i8* %6, i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27
store i32 0, i32* %3
br label %46
32: ; preds = %27
%33 = load i16, i16* %7
%34 = sext i16 %33 to i32
%35 = shl i32 %34, 8
%36 = load i8, i8* %6
%37 = zext i8 %36 to i32
%38 = and i32 %37, 255
%39 = or i32 %35, %38
%40 = trunc i32 %39 to i16
store i16 %40, i16* %7
%41 = load i16, i16* %7
%42 = sext i16 %41 to i32
%43 = sub nsw i32 %42, 16384
%44 = trunc i32 %43 to i16
%45 = load i16*, i16** %5
store i16 %44, i16* %45
store i32 1, i32* %3
br label %46
46: ; preds = %32, %31, %21, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
define i32 @vlq_read_short(i32* %0, i16* nocapture writeonly %1) {
%3 = alloca i8
%4 = call i32 @IO_Read_UBYTE(i8* %3, i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %2
%7 = load i8, i8* %3
%8 = and i8 %7, 127
%9 = icmp sgt i8 %7, -1
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = zext i8 %8 to i16
%12 = add nsw i16 %11, -64
br label %23
13: ; preds = %6
%14 = call i32 @IO_Read_UBYTE(i8* %3, i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = zext i8 %8 to i16
%18 = shl nuw nsw i16 %17, 8
%19 = load i8, i8* %3
%20 = zext i8 %19 to i16
%21 = add nsw i16 %18, -16384
%22 = or i16 %21, %20
br label %23
23: ; preds = %10, %16
%24 = phi i16 [ %22, %16 ], [ %12, %10 ]
store i16 %24, i16* %1
br label %25
25: ; preds = %23, %13, %2
%26 = phi i32 [ 0, %2 ], [ 0, %13 ], [ 1, %23 ]
ret i32 %26
}