#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 _buffer_get_byte(char **buffer, size_t *allocated, char **cursor,
                     char *byte) {
  if (!(*cursor) || (*cursor) < (*buffer) ||
      ((*cursor) > (*buffer + *allocated))) {
    *byte = 0;
    return 1;
  }
  *byte = **cursor;
  return 1;
}


x86 assembly (clang, -O0):
<_buffer_get_byte>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1154 <_buffer_get_byte+0x54>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jb     1154 <_buffer_get_byte+0x54>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x18(%rbp),%rdx
add    (%rdx),%rcx
cmp    %rcx,%rax
jbe    1167 <_buffer_get_byte+0x67>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    117d <_buffer_get_byte+0x7d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_buffer_get_byte>:
mov    (%rdx),%rax
test   %rax,%rax
je     1118 <_buffer_get_byte+0x18>
mov    (%rdi),%rdx
cmp    %rdx,%rax
jb     1118 <_buffer_get_byte+0x18>
add    (%rsi),%rdx
cmp    %rdx,%rax
jbe    1122 <_buffer_get_byte+0x22>
xor    %eax,%eax
mov    %al,(%rcx)
mov    $0x1,%eax
ret
mov    (%rax),%al
jmp    111a <_buffer_get_byte+0x1a>

LLVM IR (-O0):
define i32 @_buffer_get_byte(i8** %0, i64* %1, i8** %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca i8*
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i8** %2, i8*** %8
store i8* %3, i8** %9
%10 = load i8**, i8*** %8
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %4
%14 = load i8**, i8*** %8
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = icmp ult i8* %15, %17
br i1 %18, label %28, label %19
19: ; preds = %13
%20 = load i8**, i8*** %8
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = load i64*, i64** %7
%25 = load i64, i64* %24
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = icmp ugt i8* %21, %26
br i1 %27, label %28, label %30
28: ; preds = %19, %13, %4
%29 = load i8*, i8** %9
store i8 0, i8* %29
store i32 1, i32* %5
br label %35
30: ; preds = %19
%31 = load i8**, i8*** %8
%32 = load i8*, i8** %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %9
store i8 %33, i8* %34
store i32 1, i32* %5
br label %35
35: ; preds = %30, %28
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @_buffer_get_byte(i8** nocapture %0, i64* nocapture %1, i8** nocapture %2, i8* nocapture writeonly %3) {
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = load i8*, i8** %0
%9 = icmp ult i8* %5, %8
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = load i64, i64* %1
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = icmp ugt i8* %5, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = load i8, i8* %5
br label %16
16: ; preds = %4, %7, %10, %14
%17 = phi i8 [ %15, %14 ], [ 0, %10 ], [ 0, %7 ], [ 0, %4 ]
store i8 %17, i8* %3
ret i32 1
}