#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 */

/* Variables and functions */
int read_raw_byte(char *, void *, int);
int can_read_raw_varint64(void *_buffer, int offset, int length) {
  signed char c;
  if (length < 0)
    length = 0;
  else if (length > 10)
    length = 10;
  while (length > 0) {
    offset = read_raw_byte((char *)&c, _buffer, offset);
    if (c >= 0) {
      return 1;
    }
    length--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<can_read_raw_varint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1138 <can_read_raw_varint64+0x28>
movl   $0x0,-0x18(%rbp)
jmp    114e <can_read_raw_varint64+0x3e>
cmpl   $0xa,-0x18(%rbp)
jle    1149 <can_read_raw_varint64+0x39>
movl   $0xa,-0x18(%rbp)
jmp    114e <can_read_raw_varint64+0x3e>
jmp    1153 <can_read_raw_varint64+0x43>
cmpl   $0x0,-0x18(%rbp)
jle    1197 <can_read_raw_varint64+0x87>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x19(%rbp),%rdi
call   1030 <read_raw_byte@plt>
mov    %eax,-0x14(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jl     1189 <can_read_raw_varint64+0x79>
movl   $0x1,-0x4(%rbp)
jmp    119e <can_read_raw_varint64+0x8e>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <can_read_raw_varint64+0x43>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<can_read_raw_varint64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %edx,%edx
jle    1164 <can_read_raw_varint64+0x54>
mov    %esi,%eax
mov    %rdi,%rbx
cmp    $0xa,%edx
mov    $0xa,%ebp
cmovb  %edx,%ebp
add    $0x1,%ebp
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <read_raw_byte@plt>
cmpb   $0x0,0x7(%rsp)
jns    115e <can_read_raw_varint64+0x4e>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jge    1140 <can_read_raw_varint64+0x30>
jmp    1164 <can_read_raw_varint64+0x54>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @can_read_raw_varint64(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = icmp ult i32 %2, 10
%8 = select i1 %7, i32 %2, i32 10
br label %12
9: ; preds = %12
%10 = add nsw i32 %13, -1
%11 = icmp sgt i32 %13, 1
br i1 %11, label %12, label %18
12: ; preds = %6, %9
%13 = phi i32 [ %10, %9 ], [ %8, %6 ]
%14 = phi i32 [ %15, %9 ], [ %1, %6 ]
%15 = call i32 @read_raw_byte(i8* %4, i8* %0, i32 %14)
%16 = load i8, i8* %4
%17 = icmp sgt i8 %16, -1
br i1 %17, label %18, label %9
18: ; preds = %12, %9, %3
%19 = phi i32 [ 0, %3 ], [ 0, %9 ], [ 1, %12 ]
ret i32 %19
}