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

/* Variables and functions */
int /*<<< orphan*/ relay_weechat_msg_add_bytes(struct t_relay_weechat_msg *,
                                               void *, int);
int /*<<< orphan*/ relay_weechat_msg_add_int(struct t_relay_weechat_msg *, int);
void relay_weechat_msg_add_buffer(struct t_relay_weechat_msg *msg, void *buffer,
                                  int length) {
  if (buffer) {
    relay_weechat_msg_add_int(msg, length);
    if (length > 0)
      relay_weechat_msg_add_bytes(msg, buffer, length);
  } else {
    relay_weechat_msg_add_int(msg, -1);
  }
}


x86 assembly (clang, -O0):
<relay_weechat_msg_add_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1169 <relay_weechat_msg_add_buffer+0x49>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <relay_weechat_msg_add_int@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1164 <relay_weechat_msg_add_buffer+0x44>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <relay_weechat_msg_add_bytes@plt>
jmp    1177 <relay_weechat_msg_add_buffer+0x57>
mov    -0x8(%rbp),%rdi
mov    $0xffffffff,%esi
call   1030 <relay_weechat_msg_add_int@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relay_weechat_msg_add_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     1152 <relay_weechat_msg_add_buffer+0x32>
mov    %edx,%ebx
mov    %rsi,%r15
mov    %r14,%rdi
mov    %edx,%esi
call   1030 <relay_weechat_msg_add_int@plt>
test   %ebx,%ebx
jle    1164 <relay_weechat_msg_add_buffer+0x44>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <relay_weechat_msg_add_bytes@plt>
mov    %r14,%rdi
mov    $0xffffffff,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <relay_weechat_msg_add_int@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.t_relay_weechat_msg = type { i32 }
define void @relay_weechat_msg_add_buffer(%struct.t_relay_weechat_msg* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i32 @relay_weechat_msg_add_int(%struct.t_relay_weechat_msg* %0, i32 %2)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @relay_weechat_msg_add_bytes(%struct.t_relay_weechat_msg* %0, i8* %1, i32 %2)
br label %12
10: ; preds = %3
%11 = tail call i32 @relay_weechat_msg_add_int(%struct.t_relay_weechat_msg* %0, i32 -1)
br label %12
12: ; preds = %5, %8, %10
ret void
}