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

/* Variables and functions */
int read1(struct xmi_ctx *);
int /*<<< orphan*/ skipsrc(struct xmi_ctx *, int);
int GetVLQ2(struct xmi_ctx *ctx, uint32_t *quant) {
  int i;
  int32_t data;
  *quant = 0;
  for (i = 0; i < 4; i++) {
    data = read1(ctx);
    if (data & 0x80) {
      skipsrc(ctx, -1);
      break;
    }
    *quant += data;
  }
  return (i);
}


x86 assembly (clang, -O0):
<GetVLQ2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1198 <GetVLQ2+0x78>
mov    -0x8(%rbp),%rdi
call   1040 <read1@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     117c <GetVLQ2+0x5c>
mov    -0x8(%rbp),%rdi
mov    $0xffffffff,%esi
call   1030 <skipsrc@plt>
jmp    1198 <GetVLQ2+0x78>
movslq -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <GetVLQ2+0x22>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetVLQ2>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsi)
call   1040 <read1@plt>
xor    %ebp,%ebp
test   $0x80,%al
jne    118a <GetVLQ2+0x6a>
cltq
add    %rax,(%r14)
mov    %rbx,%rdi
call   1040 <read1@plt>
mov    $0x1,%ebp
test   $0x80,%al
jne    118a <GetVLQ2+0x6a>
cltq
add    %rax,(%r14)
mov    %rbx,%rdi
call   1040 <read1@plt>
mov    $0x2,%ebp
test   $0x80,%al
jne    118a <GetVLQ2+0x6a>
cltq
add    %rax,(%r14)
mov    %rbx,%rdi
call   1040 <read1@plt>
mov    $0x3,%ebp
test   $0x80,%al
jne    118a <GetVLQ2+0x6a>
cltq
add    %rax,(%r14)
mov    $0x4,%ebp
jmp    1197 <GetVLQ2+0x77>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1030 <skipsrc@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.xmi_ctx = type { i32 }
define i32 @GetVLQ2(%struct.xmi_ctx* %0, i64* %1) {
%3 = alloca %struct.xmi_ctx*
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
store %struct.xmi_ctx* %0, %struct.xmi_ctx** %3
store i64* %1, i64** %4
%7 = load i64*, i64** %4
store i64 0, i64* %7
store i32 0, i32* %5
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %29
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* %6
%15 = and i32 %14, 128
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load %struct.xmi_ctx*, %struct.xmi_ctx** %3
%19 = call i32 @skipsrc(%struct.xmi_ctx* %18, i32 -1)
br label %29
20: ; preds = %11
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = load i64*, i64** %4
%24 = load i64, i64* %23
%25 = add nsw i64 %24, %22
store i64 %25, i64* %23
br label %26
26: ; preds = %20
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %17, %8
%30 = load i32, i32* %5
ret i32 %30
}

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