#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void const *, unsigned int);
int buffer_put(uint8_t *out, unsigned length, unsigned *offset, const void *in,
               unsigned inlen) {
  if (*offset + inlen > length)
    return 0;
  memcpy(out + *offset, in, inlen);
  (*offset) += inlen;
  return 1;
}


x86 assembly (clang, -O0):
<buffer_put>:
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    %r8d,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    1149 <buffer_put+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1178 <buffer_put+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%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):
<buffer_put>:
push   %r15
push   %r14
push   %rbx
mov    %r8d,%r15d
mov    %rdx,%r14
mov    (%rdx),%edx
lea    (%rdx,%r15,1),%ebx
xor    %eax,%eax
cmp    %esi,%ebx
ja     113e <buffer_put+0x2e>
lea    (%rdi,%rdx,4),%rdi
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 @buffer_put(i32* %0, i32 %1, i32* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%12 = load i32*, i32** %9
%13 = load i32, i32* %12
%14 = load i32, i32* %11
%15 = add i32 %13, %14
%16 = load i32, i32* %8
%17 = icmp ugt i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %5
store i32 0, i32* %6
br label %32
19: ; preds = %5
%20 = load i32*, i32** %7
%21 = load i32*, i32** %9
%22 = load i32, i32* %21
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = call i32 @memcpy(i32* %24, i8* %25, i32 %26)
%28 = load i32, i32* %11
%29 = load i32*, i32** %9
%30 = load i32, i32* %29
%31 = add i32 %30, %28
store i32 %31, i32* %29
store i32 1, i32* %6
br label %32
32: ; preds = %19, %18
%33 = load i32, i32* %6
ret i32 %33
}

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