#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 uint32_t;
struct xmi_ctx {
  int dummy;
};

/* Variables and functions */
int read1(struct xmi_ctx *);
int GetVLQ(struct xmi_ctx *ctx, uint32_t *quant) {
  int i;
  uint32_t data;
  *quant = 0;
  for (i = 0; i < 4; i++) {
    data = read1(ctx);
    *quant <<= 7;
    *quant |= data & 0x7F;
    if (!(data & 0x80)) {
      i++;
      break;
    }
  }
  return (i);
}


x86 assembly (clang, -O0):
<GetVLQ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1192 <GetVLQ+0x82>
mov    -0x8(%rbp),%rdi
call   1030 <read1@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x7,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%ecx
and    $0x7f,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    117f <GetVLQ+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <GetVLQ+0x82>
jmp    1184 <GetVLQ+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <GetVLQ+0x21>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetVLQ>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,(%rsi)
call   1030 <read1@plt>
mov    %eax,%ecx
mov    (%rbx),%eax
shl    $0x7,%eax
mov    %ecx,%edx
and    $0x7f,%edx
or     %eax,%edx
mov    %edx,(%rbx)
mov    $0x1,%eax
test   $0x80,%cl
je     119c <GetVLQ+0x8c>
mov    %r14,%rdi
call   1030 <read1@plt>
mov    %eax,%ecx
mov    (%rbx),%eax
shl    $0x7,%eax
mov    %ecx,%edx
and    $0x7f,%edx
or     %eax,%edx
mov    %edx,(%rbx)
mov    $0x2,%eax
test   $0x80,%cl
je     119c <GetVLQ+0x8c>
mov    %r14,%rdi
call   1030 <read1@plt>
mov    %eax,%ecx
mov    (%rbx),%eax
shl    $0x7,%eax
mov    %ecx,%edx
and    $0x7f,%edx
or     %eax,%edx
mov    %edx,(%rbx)
mov    $0x3,%eax
test   $0x80,%cl
je     119c <GetVLQ+0x8c>
mov    %r14,%rdi
call   1030 <read1@plt>
mov    (%rbx),%ecx
shl    $0x7,%ecx
and    $0x7f,%eax
or     %ecx,%eax
mov    %eax,(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.xmi_ctx = type { i32 }
define i32 @GetVLQ(%struct.xmi_ctx* %0, i32* %1) {
%3 = alloca %struct.xmi_ctx*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store %struct.xmi_ctx* %0, %struct.xmi_ctx** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %29, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %32
11: ; preds = %8
%12 = load %struct.xmi_ctx*, %struct.xmi_ctx** %3
%13 = call i32 @read1(%struct.xmi_ctx* %12)
store i32 %13, i32* %6
%14 = load i32*, i32** %4
%15 = load i32, i32* %14
%16 = shl i32 %15, 7
store i32 %16, i32* %14
%17 = load i32, i32* %6
%18 = and i32 %17, 127
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* %6
%23 = and i32 %22, 128
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %11
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %32
28: ; preds = %11
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %8
32: ; preds = %25, %8
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.xmi_ctx = type { i32 }
define i32 @GetVLQ(%struct.xmi_ctx* %0, i32* nocapture %1) {
store i32 0, i32* %1
%3 = tail call i32 @read1(%struct.xmi_ctx* %0)
%4 = load i32, i32* %1
%5 = shl i32 %4, 7
%6 = and i32 %3, 127
%7 = or i32 %5, %6
store i32 %7, i32* %1
%8 = and i32 %3, 128
%9 = icmp eq i32 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %2
%11 = tail call i32 @read1(%struct.xmi_ctx* %0)
%12 = load i32, i32* %1
%13 = shl i32 %12, 7
%14 = and i32 %11, 127
%15 = or i32 %13, %14
store i32 %15, i32* %1
%16 = and i32 %11, 128
%17 = icmp eq i32 %16, 0
br i1 %17, label %32, label %18
18: ; preds = %10
%19 = tail call i32 @read1(%struct.xmi_ctx* %0)
%20 = load i32, i32* %1
%21 = shl i32 %20, 7
%22 = and i32 %19, 127
%23 = or i32 %21, %22
store i32 %23, i32* %1
%24 = and i32 %19, 128
%25 = icmp eq i32 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %18
%27 = tail call i32 @read1(%struct.xmi_ctx* %0)
%28 = load i32, i32* %1
%29 = shl i32 %28, 7
%30 = and i32 %27, 127
%31 = or i32 %29, %30
store i32 %31, i32* %1
br label %32
32: ; preds = %26, %2, %10, %18
%33 = phi i32 [ 1, %2 ], [ 2, %10 ], [ 3, %18 ], [ 4, %26 ]
ret i32 %33
}