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

/* Variables and functions */
struct buffer *alloc_buffer(int);
int /*<<< orphan*/ write_int8_buffer(struct buffer *, int /*<<< orphan*/);
int /*<<< orphan*/ write_string_buffer(struct buffer *, char const *);
struct buffer *gen_message_buffer(const char *key, const char *value) {
  struct buffer *msg_buf;
  msg_buf = alloc_buffer(32);
  write_int8_buffer(msg_buf, 0);
  write_int8_buffer(msg_buf, 0);
  write_string_buffer(msg_buf, key);
  write_string_buffer(msg_buf, value);
  return msg_buf;
}


x86 assembly (clang, -O0):
<gen_message_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1050 <alloc_buffer@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <write_int8_buffer@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <write_int8_buffer@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <write_string_buffer@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <write_string_buffer@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_message_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x20,%edi
call   1050 <alloc_buffer@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <write_int8_buffer@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <write_int8_buffer@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <write_string_buffer@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <write_string_buffer@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
define %struct.buffer* @gen_message_buffer(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.buffer*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call %struct.buffer* @alloc_buffer(i32 32)
store %struct.buffer* %6, %struct.buffer** %5
%7 = load %struct.buffer*, %struct.buffer** %5
%8 = call i32 @write_int8_buffer(%struct.buffer* %7, i32 0)
%9 = load %struct.buffer*, %struct.buffer** %5
%10 = call i32 @write_int8_buffer(%struct.buffer* %9, i32 0)
%11 = load %struct.buffer*, %struct.buffer** %5
%12 = load i8*, i8** %3
%13 = call i32 @write_string_buffer(%struct.buffer* %11, i8* %12)
%14 = load %struct.buffer*, %struct.buffer** %5
%15 = load i8*, i8** %4
%16 = call i32 @write_string_buffer(%struct.buffer* %14, i8* %15)
%17 = load %struct.buffer*, %struct.buffer** %5
ret %struct.buffer* %17
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define %struct.buffer* @gen_message_buffer(i8* %0, i8* %1) {
%3 = tail call %struct.buffer* @alloc_buffer(i32 32)
%4 = tail call i32 @write_int8_buffer(%struct.buffer* %3, i32 0)
%5 = tail call i32 @write_int8_buffer(%struct.buffer* %3, i32 0)
%6 = tail call i32 @write_string_buffer(%struct.buffer* %3, i8* %0)
%7 = tail call i32 @write_string_buffer(%struct.buffer* %3, i8* %1)
ret %struct.buffer* %3
}