#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 *,
                                               char const *, int);
int /*<<< orphan*/ relay_weechat_msg_add_int(struct t_relay_weechat_msg *, int);
int strlen(char const *);
void relay_weechat_msg_add_string(struct t_relay_weechat_msg *msg,
                                  const char *string) {
  int length;
  if (string) {
    length = strlen(string);
    relay_weechat_msg_add_int(msg, length);
    if (length > 0)
      relay_weechat_msg_add_bytes(msg, string, length);
  } else {
    relay_weechat_msg_add_int(msg, -1);
  }
}


x86 assembly (clang, -O0):
<relay_weechat_msg_add_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1182 <relay_weechat_msg_add_string+0x52>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <relay_weechat_msg_add_int@plt>
cmpl   $0x0,-0x14(%rbp)
jle    117d <relay_weechat_msg_add_string+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <relay_weechat_msg_add_bytes@plt>
jmp    1190 <relay_weechat_msg_add_string+0x60>
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_string>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     1168 <relay_weechat_msg_add_string+0x38>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <relay_weechat_msg_add_int@plt>
test   %ebp,%ebp
jle    1179 <relay_weechat_msg_add_string+0x49>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <relay_weechat_msg_add_bytes@plt>
mov    %r14,%rdi
mov    $0xffffffff,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <relay_weechat_msg_add_int@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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