#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 */
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int Read7BitEncodedInt(FILE *fp) {
  int result = 0;
  int bitsRead = 0;
  char value;
  size_t read;
  do {
    read = fread(&value, 1, 1, fp);
    if (read != 1)
      return -1;
    result |= (value & 0x7f) << bitsRead;
    bitsRead += 7;
  } while (value & 0x80);
  return result;
}


x86 assembly (clang, -O0):
<Read7BitEncodedInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
je     1159 <Read7BitEncodedInt+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <Read7BitEncodedInt+0x7c>
movsbl -0x19(%rbp),%eax
and    $0x7f,%eax
mov    -0x18(%rbp),%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x19(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    112a <Read7BitEncodedInt+0x1a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Read7BitEncodedInt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x7(%rsp),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%rax
jne    1164 <Read7BitEncodedInt+0x54>
movzbl 0x7(%rsp),%eax
mov    %eax,%edx
and    $0x7f,%edx
mov    %ebp,%ecx
shl    %cl,%edx
or     %edx,%ebx
add    $0x7,%ebp
test   $0x80,%al
jne    1130 <Read7BitEncodedInt+0x20>
jmp    1169 <Read7BitEncodedInt+0x59>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @Read7BitEncodedInt(i32* nocapture %0) {
%2 = alloca i8
br label %3
3: ; preds = %8, %1
%4 = phi i32 [ 0, %1 ], [ %13, %8 ]
%5 = phi i32 [ 0, %1 ], [ %14, %8 ]
%6 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %0)
%7 = icmp eq i64 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = load i8, i8* %2
%10 = zext i8 %9 to i32
%11 = and i32 %10, 127
%12 = shl i32 %11, %5
%13 = or i32 %12, %4
%14 = add nuw nsw i32 %5, 7
%15 = and i32 %10, 128
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %3
17: ; preds = %8, %3
%18 = phi i32 [ -1, %3 ], [ %13, %8 ]
ret i32 %18
}