#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 */
unsigned int getc(int /*<<< orphan*/ *);
unsigned int ReadVarLen(FILE *file) {
  unsigned int value;
  unsigned char c;
  if ((value = getc(file)) & 0x80) {
    value &= 0x7f;
    do
      value = (value << 7) + ((c = (unsigned char)getc(file)) & 0x7f);
    while (c & 0x80);
  }
  return (value);
}


x86 assembly (clang, -O0):
<ReadVarLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0xc(%rbp)
and    $0x80,%eax
cmp    $0x0,%eax
je     117b <ReadVarLen+0x6b>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
mov    %cl,-0xd(%rbp)
movzbl %cl,%ecx
and    $0x7f,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
movzbl -0xd(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    113f <ReadVarLen+0x2f>
jmp    117b <ReadVarLen+0x6b>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadVarLen>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <getc@plt>
mov    %eax,%ebp
test   $0x80,%bpl
je     1146 <ReadVarLen+0x36>
and    $0x7f,%ebp
cs nopw 0x0(%rax,%rax,1)
shl    $0x7,%ebp
mov    %rbx,%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
and    $0x7f,%ecx
or     %ecx,%ebp
test   $0x80,%al
jne    1130 <ReadVarLen+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ReadVarLen(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @getc(i32* %5)
store i32 %6, i32* %3
%7 = and i32 %6, 128
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = load i32, i32* %3
%11 = and i32 %10, 127
store i32 %11, i32* %3
br label %12
12: ; preds = %21, %9
%13 = load i32, i32* %3
%14 = shl i32 %13, 7
%15 = load i32*, i32** %2
%16 = call i32 @getc(i32* %15)
%17 = trunc i32 %16 to i8
store i8 %17, i8* %4
%18 = zext i8 %17 to i32
%19 = and i32 %18, 127
%20 = add i32 %14, %19
store i32 %20, i32* %3
br label %21
21: ; preds = %12
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = and i32 %23, 128
%25 = icmp ne i32 %24, 0
br i1 %25, label %12, label %26
26: ; preds = %21
br label %27
27: ; preds = %26, %1
%28 = load i32, i32* %3
ret i32 %28
}

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