#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 */
scalar_t__ hasNextByte(long);
long readUInt8(int /*<<< orphan*/ *);
signed long readEncSInt32(FILE *f) {
  signed long result = 0, temp;
  int shift = 0;
  do {
    if (shift > 4 * 7)
      break;
    temp = readUInt8(f);
    result |= (0x7f & temp) << shift;
    shift += 7;
  } while (hasNextByte(temp));
  return result;
}


x86 assembly (clang, -O0):
<readEncSInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1c,-0x1c(%rbp)
jle    114a <readEncSInt32+0x2a>
jmp    1189 <readEncSInt32+0x69>
mov    -0x8(%rbp),%rdi
call   1030 <readUInt8@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0x7f,%rax
mov    -0x1c(%rbp),%ecx
shl    %cl,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <hasNextByte@plt>
cmp    $0x0,%rax
jne    113b <readEncSInt32+0x1b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readEncSInt32>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
mov    %rbx,%r12
mov    %r14,%rdi
call   1030 <readUInt8@plt>
mov    %eax,%ebx
and    $0x7f,%ebx
mov    %r15d,%ecx
shl    %cl,%rbx
or     %r12,%rbx
mov    %rax,%rdi
call   1040 <hasNextByte@plt>
test   %rax,%rax
je     1163 <readEncSInt32+0x43>
lea    0x7(%r15),%rax
cmp    $0x16,%r15
mov    %rax,%r15
jb     1130 <readEncSInt32+0x10>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @readEncSInt32(i32* %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %9, %2 ]
%4 = phi i64 [ 0, %1 ], [ %8, %2 ]
%5 = tail call i64 @readUInt8(i32* %0)
%6 = and i64 %5, 127
%7 = shl nuw nsw i64 %6, %3
%8 = or i64 %7, %4
%9 = add nuw nsw i64 %3, 7
%10 = tail call i64 @hasNextByte(i64 %5)
%11 = icmp eq i64 %10, 0
%12 = icmp ugt i64 %3, 21
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %2
14: ; preds = %2
ret i64 %8
}