#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 evbuffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ evbuffer_add(struct evbuffer *, int *, int);
int /*<<< orphan*/ evbuffer_expand(struct evbuffer *, int);
struct evbuffer *evbuffer_new();
struct evbuffer *buffer_with_header(int size, int type) {
  struct evbuffer *msg = evbuffer_new();
  evbuffer_expand(msg, size + 2 * sizeof(int));
  evbuffer_add(msg, &size, sizeof(int));
  evbuffer_add(msg, &type, sizeof(int));
  return msg;
}


x86 assembly (clang, -O0):
<buffer_with_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <evbuffer_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
add    $0x8,%rax
mov    %eax,%esi
call   1030 <evbuffer_expand@plt>
mov    -0x10(%rbp),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1040 <evbuffer_add@plt>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <evbuffer_add@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_with_header>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,0x4(%rsp)
mov    %esi,(%rsp)
xor    %eax,%eax
call   1050 <evbuffer_new@plt>
mov    %rax,%r14
add    $0x8,%ebx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <evbuffer_expand@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <evbuffer_add@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <evbuffer_add@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.evbuffer = type { i32 }
define %struct.evbuffer* @buffer_with_header(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.evbuffer*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call %struct.evbuffer* (...) @evbuffer_new()
store %struct.evbuffer* %6, %struct.evbuffer** %5
%7 = load %struct.evbuffer*, %struct.evbuffer** %5
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = add i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i32 @evbuffer_expand(%struct.evbuffer* %7, i32 %11)
%13 = load %struct.evbuffer*, %struct.evbuffer** %5
%14 = call i32 @evbuffer_add(%struct.evbuffer* %13, i32* %3, i32 4)
%15 = load %struct.evbuffer*, %struct.evbuffer** %5
%16 = call i32 @evbuffer_add(%struct.evbuffer* %15, i32* %4, i32 4)
%17 = load %struct.evbuffer*, %struct.evbuffer** %5
ret %struct.evbuffer* %17
}

LLVM IR (-O2):
%struct.evbuffer = type { i32 }
define %struct.evbuffer* @buffer_with_header(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = tail call %struct.evbuffer* (...) @evbuffer_new()
%6 = add i32 %0, 8
%7 = tail call i32 @evbuffer_expand(%struct.evbuffer* %5, i32 %6)
%8 = call i32 @evbuffer_add(%struct.evbuffer* %5, i32* %3, i32 4)
%9 = call i32 @evbuffer_add(%struct.evbuffer* %5, i32* %4, i32 4)
ret %struct.evbuffer* %5
}