#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;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fgetc(int /*<<< orphan*/ *);
uint32_t read_compressed_int(FILE *f) {
  int i;
  uint64_t result;
  uint8_t temp;
  result = 0;
  for (i = 0; i <= 4; i++) {
    temp = fgetc(f);
    result = result | ((temp & 0x7f) << (i * 7));
    if (temp < 0x80)
      break;
  }
  return (uint32_t)result;
}


x86 assembly (clang, -O0):
<read_compressed_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jg     117b <read_compressed_int+0x6b>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%edx
and    $0x7f,%edx
imul   $0x7,-0xc(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x80,-0x14(%rbp)
jge    1168 <read_compressed_int+0x58>
jmp    117b <read_compressed_int+0x6b>
jmp    116d <read_compressed_int+0x5d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <read_compressed_int+0x1a>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_compressed_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    %eax,%ebx
and    $0x7f,%ebx
cmp    $0x80,%eax
jl     1180 <read_compressed_int+0x70>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
and    $0x7f,%ecx
shl    $0x7,%ecx
or     %ecx,%ebx
cmp    $0x80,%eax
jl     1180 <read_compressed_int+0x70>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
and    $0x7f,%ecx
shl    $0xe,%ecx
or     %ecx,%ebx
cmp    $0x80,%eax
jl     1180 <read_compressed_int+0x70>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
and    $0x7f,%ecx
shl    $0x15,%ecx
or     %ecx,%ebx
cmp    $0x80,%eax
jl     1180 <read_compressed_int+0x70>
mov    %r14,%rdi
call   1030 <fgetc@plt>
shl    $0x1c,%eax
or     %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @read_compressed_int(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = and i32 %2, 127
%4 = icmp slt i32 %2, 128
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = tail call i32 @fgetc(i32* %0)
%7 = shl i32 %6, 7
%8 = and i32 %7, 16256
%9 = or i32 %8, %3
%10 = icmp slt i32 %6, 128
br i1 %10, label %27, label %11
11: ; preds = %5
%12 = tail call i32 @fgetc(i32* %0)
%13 = shl i32 %12, 14
%14 = and i32 %13, 2080768
%15 = or i32 %14, %9
%16 = icmp slt i32 %12, 128
br i1 %16, label %27, label %17
17: ; preds = %11
%18 = tail call i32 @fgetc(i32* %0)
%19 = shl i32 %18, 21
%20 = and i32 %19, 266338304
%21 = or i32 %20, %15
%22 = icmp slt i32 %18, 128
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = tail call i32 @fgetc(i32* %0)
%25 = shl i32 %24, 28
%26 = or i32 %25, %21
br label %27
27: ; preds = %23, %17, %11, %5, %1
%28 = phi i32 [ %3, %1 ], [ %9, %5 ], [ %15, %11 ], [ %21, %17 ], [ %26, %23 ]
ret i32 %28
}