#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 /*<<< orphan*/ can_read_raw_varint32(void *, int, unsigned int);
int read_raw_varint32(unsigned long *, void *, int);
int Message_can_read_delimited_from(void *_buffer, int offset,
                                    unsigned int length) {
  unsigned long size;
  int payload_offset;
  if (length <= 0)
    return 0;
  if (!can_read_raw_varint32(_buffer, offset, length)) {
    return 0;
  }
  payload_offset = read_raw_varint32(&size, _buffer, offset);
  length = length - (payload_offset - offset);
  return (length >= size) ? 1 : 0;
}


x86 assembly (clang, -O0):
<Message_can_read_delimited_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
ja     1148 <Message_can_read_delimited_from+0x28>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <Message_can_read_delimited_from+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <can_read_raw_varint32@plt>
cmp    $0x0,%eax
jne    116c <Message_can_read_delimited_from+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <Message_can_read_delimited_from+0x86>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1030 <read_raw_varint32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%edx
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmovae %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Message_can_read_delimited_from>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %edx,%edx
je     115b <Message_can_read_delimited_from+0x3b>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <can_read_raw_varint32@plt>
test   %eax,%eax
je     115b <Message_can_read_delimited_from+0x3b>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <read_raw_varint32@plt>
add    %r14d,%ebx
sub    %eax,%ebx
xor    %ebp,%ebp
cmp    %rbx,(%rsp)
setbe  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Message_can_read_delimited_from(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp ule i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %35
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 @can_read_raw_varint32(i8* %14, i32 %15, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %35
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 @read_raw_varint32(i64* %8, i8* %21, i32 %22)
store i32 %23, i32* %9
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
%28 = sub i32 %24, %27
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = load i64, i64* %8
%32 = icmp uge i64 %30, %31
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 1, i32 0
store i32 %34, i32* %4
br label %35
35: ; preds = %20, %19, %12
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @Message_can_read_delimited_from(i8* %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp eq i32 %2, 0
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = tail call i32 @can_read_raw_varint32(i8* %0, i32 %1, i32 %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = call i32 @read_raw_varint32(i64* %4, i8* %0, i32 %1)
%12 = add i32 %2, %1
%13 = sub i32 %12, %11
%14 = zext i32 %13 to i64
%15 = load i64, i64* %4
%16 = icmp ule i64 %15, %14
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %7, %3, %10
%19 = phi i32 [ %17, %10 ], [ 0, %3 ], [ 0, %7 ]
ret i32 %19
}