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

/* Variables and functions */
int fread(int *, int, int, int /*<<< orphan*/ *);
uint32_t descr_length(FILE *in, int *num) {
  uint32_t ret = 0;
  uint8_t byte;
  *num = 0;
  do {
    if (fread(&byte, 1, 1, in) < 1)
      return -1;
    ;
    (*num)++;
    ret = (ret << 7) | (byte & 0x7F);
  } while (byte & 0x80 && *num < 4);
  return ret;
}


x86 assembly (clang, -O0):
<descr_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jge    115a <descr_length+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <descr_length+0x9b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
shl    $0x7,%eax
mov    -0x20(%rbp),%ecx
and    $0x7f,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     119a <descr_length+0x8a>
mov    -0x18(%rbp),%rax
cmpl   $0x4,(%rax)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1131 <descr_length+0x21>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<descr_length>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,(%rsi)
xor    %ebx,%ebx
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    116e <descr_length+0x5e>
mov    (%r14),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%r14)
mov    %ebx,%ecx
shl    $0x7,%ecx
mov    0x4(%rsp),%edx
mov    %edx,%ebx
and    $0x7f,%ebx
or     %ecx,%ebx
test   $0x80,%dl
je     1173 <descr_length+0x63>
cmp    $0x3,%eax
jl     1130 <descr_length+0x20>
jmp    1173 <descr_length+0x63>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @descr_length(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %1
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ 0, %2 ], [ %15, %9 ]
%7 = call i32 @fread(i32* %3, i32 1, i32 1, i32* %0)
%8 = icmp slt i32 %7, 1
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
%12 = shl i32 %6, 7
%13 = load i32, i32* %3
%14 = and i32 %13, 127
%15 = or i32 %14, %12
%16 = and i32 %13, 128
%17 = icmp ne i32 %16, 0
%18 = icmp slt i32 %10, 3
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %5, label %20
20: ; preds = %9, %5
%21 = phi i32 [ -1, %5 ], [ %15, %9 ]
ret i32 %21
}