#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 iovec {
  int /*<<< orphan*/ iov_len;
  int /*<<< orphan*/ iov_base;
};
struct cm_attr {
  int dummy;
};

/* Variables and functions */
void *cm_default_alloc(struct cm_attr *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/, int /*<<< orphan*/);
void *cm_append(struct cm_attr *mem, struct iovec iov) {
  void *p = cm_default_alloc(mem, iov.iov_len);
  if (!p)
    return NULL;
  memcpy(p, iov.iov_base, iov.iov_len);
  return p;
}


x86 assembly (clang, -O0):
<cm_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rsi,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <cm_default_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1158 <cm_append+0x38>
movq   $0x0,-0x8(%rbp)
jmp    116f <cm_append+0x4f>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm_append>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1030 <cm_default_alloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1146 <cm_append+0x26>
mov    %r14,%rsi
shr    $0x20,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cm_attr = type { i32 }
%struct.iovec = type { i32, i32 }
define i8* @cm_append(%struct.cm_attr* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca %struct.iovec
%5 = alloca %struct.cm_attr*
%6 = alloca i8*
%7 = bitcast %struct.iovec* %4 to i64*
store i64 %1, i64* %7
store %struct.cm_attr* %0, %struct.cm_attr** %5
%8 = load %struct.cm_attr*, %struct.cm_attr** %5
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i8* @cm_default_alloc(%struct.cm_attr* %8, i32 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8* null, i8** %3
br label %23
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @memcpy(i8* %16, i32 %18, i32 %20)
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %23
23: ; preds = %15, %14
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
%struct.cm_attr = type { i32 }
define i8* @cm_append(%struct.cm_attr* %0, i64 %1) {
%3 = trunc i64 %1 to i32
%4 = tail call i8* @cm_default_alloc(%struct.cm_attr* %0, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = lshr i64 %1, 32
%8 = trunc i64 %7 to i32
%9 = tail call i32 @memcpy(i8* %4, i32 %8, i32 %3)
br label %10
10: ; preds = %2, %6
ret i8* %4
}