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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ buffer_write_char(struct rpc_buffer *, int);
int /*<<< orphan*/ buffer_write_data(struct rpc_buffer *, ...);
int /*<<< orphan*/ buffer_write_pad(struct rpc_buffer *);
void buffer_write_string(struct rpc_buffer *buf, int len, const char *s) {
  assert(!(len & 0xff000000));
  buffer_write_char(buf, 254);
  buffer_write_data(buf, &len, 3);
  buffer_write_data(buf, s, len);
  buffer_write_pad(buf);
}


x86 assembly (clang, -O0):
<buffer_write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff000000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0xfe,%esi
call   1030 <buffer_write_char@plt>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1060 <buffer_write_data@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1060 <buffer_write_data@plt>
mov    -0x8(%rbp),%rdi
call   1040 <buffer_write_pad@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_write_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
xor    %edi,%edi
cmp    $0x1000000,%esi
setb   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0xfe,%esi
call   1030 <buffer_write_char@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
xor    %eax,%eax
call   1060 <buffer_write_data@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <buffer_write_data@plt>
mov    %rbx,%rdi
call   1040 <buffer_write_pad@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rpc_buffer = type { i32 }
define void @buffer_write_string(%struct.rpc_buffer* %0, i32 %1, i8* %2) {
%4 = alloca %struct.rpc_buffer*
%5 = alloca i32
%6 = alloca i8*
store %struct.rpc_buffer* %0, %struct.rpc_buffer** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %5
%8 = and i32 %7, -16777216
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load %struct.rpc_buffer*, %struct.rpc_buffer** %4
%14 = call i32 @buffer_write_char(%struct.rpc_buffer* %13, i32 254)
%15 = load %struct.rpc_buffer*, %struct.rpc_buffer** %4
%16 = call i32 (%struct.rpc_buffer*, ...) @buffer_write_data(%struct.rpc_buffer* %15, i32* %5, i32 3)
%17 = load %struct.rpc_buffer*, %struct.rpc_buffer** %4
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = call i32 (%struct.rpc_buffer*, ...) @buffer_write_data(%struct.rpc_buffer* %17, i8* %18, i32 %19)
%21 = load %struct.rpc_buffer*, %struct.rpc_buffer** %4
%22 = call i32 @buffer_write_pad(%struct.rpc_buffer* %21)
ret void
}

LLVM IR (-O2):
%struct.rpc_buffer = type { i32 }
define void @buffer_write_string(%struct.rpc_buffer* %0, i32 %1, i8* %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = icmp ult i32 %1, 16777216
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @buffer_write_char(%struct.rpc_buffer* %0, i32 254)
%9 = call i32 (%struct.rpc_buffer*, ...) @buffer_write_data(%struct.rpc_buffer* %0, i32* %4, i32 3)
%10 = load i32, i32* %4
%11 = call i32 (%struct.rpc_buffer*, ...) @buffer_write_data(%struct.rpc_buffer* %0, i8* %2, i32 %10)
%12 = call i32 @buffer_write_pad(%struct.rpc_buffer* %0)
ret void
}