#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*/ memcpy(void *, char const *, unsigned int);
int tbBufferRead(void *Destination, unsigned int ElementSize,
                 const long BufferSize, const char *Buffer,
                 unsigned int *BufferPointer) {
  if ((*BufferPointer + ElementSize) > (unsigned int)BufferSize) {
    return 0;
  } else {
    memcpy(Destination, &Buffer[*BufferPointer], ElementSize);
    *BufferPointer += ElementSize;
    return 1;
  }
}


x86 assembly (clang, -O0):
<tbBufferRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    %ecx,%eax
jbe    114c <tbBufferRead+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    1177 <tbBufferRead+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tbBufferRead>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
mov    (%r8),%esi
lea    (%rsi,%r15,1),%ebx
xor    %eax,%eax
cmp    %edx,%ebx
ja     113e <tbBufferRead+0x2e>
mov    %r8,%r14
add    %rsi,%rcx
mov    %rcx,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
add    %r15d,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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