#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 */
struct iobuf {
  int dummy;
};

/* Variables and functions */
void *iobuf_reserve(struct iobuf *, size_t);
int /*<<< orphan*/ memmove(void *, void const *, size_t);
int iobuf_queue(struct iobuf *io, const void *data, size_t len) {
  void *buf;
  if (len == 0)
    return (0);
  if ((buf = iobuf_reserve(io, len)) == NULL)
    return (-1);
  memmove(buf, data, len);
  return (0);
}


x86 assembly (clang, -O0):
<iobuf_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114b <iobuf_queue+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    118a <iobuf_queue+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <iobuf_reserve@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1172 <iobuf_queue+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <iobuf_queue+0x6a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memmove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iobuf_queue>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
test   %rdx,%rdx
je     1153 <iobuf_queue+0x33>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdx,%rsi
call   1040 <iobuf_reserve@plt>
test   %rax,%rax
je     114e <iobuf_queue+0x2e>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memmove@plt>
jmp    1153 <iobuf_queue+0x33>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iobuf = type { i32 }
define i32 @iobuf_queue(%struct.iobuf* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.iobuf*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store %struct.iobuf* %0, %struct.iobuf** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %23
12: ; preds = %3
%13 = load %struct.iobuf*, %struct.iobuf** %5
%14 = load i64, i64* %7
%15 = call i8* @iobuf_reserve(%struct.iobuf* %13, i64 %14)
store i8* %15, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %4
br label %23
18: ; preds = %12
%19 = load i8*, i8** %8
%20 = load i8*, i8** %6
%21 = load i64, i64* %7
%22 = call i32 @memmove(i8* %19, i8* %20, i64 %21)
store i32 0, i32* %4
br label %23
23: ; preds = %18, %17, %11
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.iobuf = type { i32 }
define i32 @iobuf_queue(%struct.iobuf* %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i8* @iobuf_reserve(%struct.iobuf* %0, i64 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @memmove(i8* %6, i8* %1, i64 %2)
br label %10
10: ; preds = %5, %3, %8
%11 = phi i32 [ 0, %8 ], [ 0, %3 ], [ -1, %5 ]
ret i32 %11
}