#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 */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
long int lmu_read_varint(FILE *in) {
  long int res;
  int byte;
  res = 0;
  byte = fgetc(in);
  if (byte & 0x80) {
    while (byte & 0x80 && !feof(in)) {
      res = (res << 7) | (byte & 0x7f);
      byte = fgetc(in);
    };
    res = (res << 7) | (byte & 0x7f);
  } else {
    return byte;
  }
  return res;
}


x86 assembly (clang, -O0):
<lmu_read_varint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11d7 <lmu_read_varint+0xb7>
jmp    1156 <lmu_read_varint+0x36>
mov    -0x1c(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1181 <lmu_read_varint+0x61>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1191 <lmu_read_varint+0x71>
jmp    11ba <lmu_read_varint+0x9a>
mov    -0x18(%rbp),%rax
shl    $0x7,%rax
mov    -0x1c(%rbp),%ecx
and    $0x7f,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
jmp    1156 <lmu_read_varint+0x36>
mov    -0x18(%rbp),%rax
shl    $0x7,%rax
mov    -0x1c(%rbp),%ecx
and    $0x7f,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11e4 <lmu_read_varint+0xc4>
movslq -0x1c(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <lmu_read_varint+0xcc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lmu_read_varint>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    %eax,%r15d
test   $0x80,%r15b
jne    113b <lmu_read_varint+0x1b>
movslq %r15d,%r15
jmp    116f <lmu_read_varint+0x4f>
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    1168 <lmu_read_varint+0x48>
and    $0x7f,%r15d
or     %r15,%rbx
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r15d
shl    $0x7,%rbx
test   $0x80,%r15b
jne    1140 <lmu_read_varint+0x20>
and    $0x7f,%r15d
or     %rbx,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @lmu_read_varint(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 0, i64* %4
%6 = load i32*, i32** %3
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = and i32 %8, 128
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %1
br label %12
12: ; preds = %23, %11
%13 = load i32, i32* %5
%14 = and i32 %13, 128
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32*, i32** %3
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = load i64, i64* %4
%25 = shl i64 %24, 7
%26 = load i32, i32* %5
%27 = and i32 %26, 127
%28 = sext i32 %27 to i64
%29 = or i64 %25, %28
store i64 %29, i64* %4
%30 = load i32*, i32** %3
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %5
br label %12
32: ; preds = %21
%33 = load i64, i64* %4
%34 = shl i64 %33, 7
%35 = load i32, i32* %5
%36 = and i32 %35, 127
%37 = sext i32 %36 to i64
%38 = or i64 %34, %37
store i64 %38, i64* %4
br label %42
39: ; preds = %1
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
store i64 %41, i64* %2
br label %44
42: ; preds = %32
%43 = load i64, i64* %4
store i64 %43, i64* %2
br label %44
44: ; preds = %42, %39
%45 = load i64, i64* %2
ret i64 %45
}

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