#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 uint8_t;
typedef int uint64_t;

/* Variables and functions */
int UINT64_C(int);
int /*<<< orphan*/ error(char *);
int read_byte();
uint64_t read_var(void) {
  uint64_t value = 0;
  uint8_t byte;
  do {
    if (value & UINT64_C(0xe000000000000000))
      error("value too big (more than 64 bits)");
    byte = read_byte();
    value = (value << 7) | (byte & 0x7f);
  } while (byte & 0x80);
  return value;
}


x86 assembly (clang, -O0):
<read_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %edi,%edi
call   1040 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
and    %ecx,%eax
cmp    $0x0,%eax
je     1168 <read_var+0x38>
lea    0xe9d(%rip),%rdi
call   1050 <error@plt>
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x7,%eax
mov    -0x8(%rbp),%ecx
and    $0x7f,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    113f <read_var+0xf>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_var>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rbx
xor    %ebp,%ebp
jmp    1157 <read_var+0x27>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <read_byte@plt>
mov    %ebp,%ecx
shl    $0x7,%ecx
mov    %eax,%ebp
and    $0x7f,%ebp
or     %ecx,%ebp
test   $0x80,%al
je     116c <read_var+0x3c>
xor    %edi,%edi
call   1040 <UINT64_C@plt>
test   %ebp,%eax
je     1140 <read_var+0x10>
mov    %rbx,%rdi
call   1050 <error@plt>
jmp    1140 <read_var+0x10>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"value too big (more than 64 bits)\00"
define i32 @read_var() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* %1
%5 = call i32 @UINT64_C(i32 0)
%6 = and i32 %4, %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = call i32 (...) @read_byte()
store i32 %11, i32* %2
%12 = load i32, i32* %1
%13 = shl i32 %12, 7
%14 = load i32, i32* %2
%15 = and i32 %14, 127
%16 = or i32 %13, %15
store i32 %16, i32* %1
br label %17
17: ; preds = %10
%18 = load i32, i32* %2
%19 = and i32 %18, 128
%20 = icmp ne i32 %19, 0
br i1 %20, label %3, label %21
21: ; preds = %17
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [34 x i8] c"value too big (more than 64 bits)\00"
define i32 @read_var() {
br label %1
1: ; preds = %8, %0
%2 = phi i32 [ 0, %0 ], [ %12, %8 ]
%3 = tail call i32 @UINT64_C(i32 0)
%4 = and i32 %3, %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = tail call i32 (...) @read_byte()
%10 = shl i32 %2, 7
%11 = and i32 %9, 127
%12 = or i32 %11, %10
%13 = and i32 %9, 128
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %1
15: ; preds = %8
ret i32 %12
}