#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;
};
struct t_relay_client {
  int dummy;
};
typedef int /*<<< orphan*/ str_signal;

/* Variables and functions */
int /*<<< orphan*/ relay_client_valid(struct t_relay_client *);
int /*<<< orphan*/ relay_weechat_msg_free(struct t_relay_weechat_msg *);
struct t_relay_weechat_msg *relay_weechat_msg_new(char *);
int /*<<< orphan*/ relay_weechat_msg_send(struct t_relay_client *,
                                          struct t_relay_weechat_msg *);
scalar_t__ relay_weechat_protocol_is_sync(struct t_relay_client *,
                                          int /*<<< orphan*/ *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strcmp(char const *, char *);
int relay_weechat_protocol_signal_upgrade_cb(const void *pointer, void *data,
                                             const char *signal,
                                             const char *type_data,
                                             void *signal_data) {
  struct t_relay_client *ptr_client;
  struct t_relay_weechat_msg *msg;
  char str_signal[128];
  (void)data;
  (void)type_data;
  (void)signal_data;
  ptr_client = (struct t_relay_client *)pointer;
  if (!ptr_client || !relay_client_valid(ptr_client))
    return 0;
  snprintf(str_signal, sizeof(str_signal), "_%s", signal);
  if ((strcmp(signal, "upgrade") == 0) ||
      (strcmp(signal, "upgrade_ended") == 0)) {
    if (relay_weechat_protocol_is_sync(ptr_client, NULL, 8)) {
      msg = relay_weechat_msg_new(str_signal);
      if (msg) {
        relay_weechat_msg_send(ptr_client, msg);
        relay_weechat_msg_free(msg);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<relay_weechat_protocol_signal_upgrade_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b4 <relay_weechat_protocol_signal_upgrade_cb+0x44>
mov    -0x38(%rbp),%rdi
call   1070 <relay_client_valid@plt>
cmp    $0x0,%eax
jne    11c0 <relay_weechat_protocol_signal_upgrade_cb+0x50>
movl   $0x0,-0x4(%rbp)
jmp    126e <relay_weechat_protocol_signal_upgrade_cb+0xfe>
lea    -0xc0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x80,%esi
lea    0xe29(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1210 <relay_weechat_protocol_signal_upgrade_cb+0xa0>
mov    -0x20(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1267 <relay_weechat_protocol_signal_upgrade_cb+0xf7>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1060 <relay_weechat_protocol_is_sync@plt>
cmp    $0x0,%rax
je     1262 <relay_weechat_protocol_signal_upgrade_cb+0xf2>
lea    -0xc0(%rbp),%rdi
call   1080 <relay_weechat_msg_new@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     125d <relay_weechat_protocol_signal_upgrade_cb+0xed>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1090 <relay_weechat_msg_send@plt>
mov    -0x40(%rbp),%rdi
call   1040 <relay_weechat_msg_free@plt>
jmp    1262 <relay_weechat_protocol_signal_upgrade_cb+0xf2>
jmp    1267 <relay_weechat_protocol_signal_upgrade_cb+0xf7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relay_weechat_protocol_signal_upgrade_cb>:
push   %r14
push   %rbx
sub    $0x88,%rsp
test   %rdi,%rdi
je     1208 <relay_weechat_protocol_signal_upgrade_cb+0x98>
mov    %rdx,%rbx
mov    %rdi,%r14
call   1070 <relay_client_valid@plt>
test   %eax,%eax
je     1208 <relay_weechat_protocol_signal_upgrade_cb+0x98>
lea    0xe67(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d1 <relay_weechat_protocol_signal_upgrade_cb+0x61>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1208 <relay_weechat_protocol_signal_upgrade_cb+0x98>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <relay_weechat_protocol_is_sync@plt>
test   %rax,%rax
je     1208 <relay_weechat_protocol_signal_upgrade_cb+0x98>
mov    %rsp,%rdi
call   1080 <relay_weechat_msg_new@plt>
test   %rax,%rax
je     1208 <relay_weechat_protocol_signal_upgrade_cb+0x98>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <relay_weechat_msg_send@plt>
mov    %rbx,%rdi
call   1040 <relay_weechat_msg_free@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.t_relay_client = type { i32 }
%struct.t_relay_weechat_msg = type { i32 }
@.str = [4 x i8] c"_%s\00"
@.str.1 = [8 x i8] c"upgrade\00"
@.str.2 = [14 x i8] c"upgrade_ended\00"
define i32 @relay_weechat_protocol_signal_upgrade_cb(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca %struct.t_relay_client*
%13 = alloca %struct.t_relay_weechat_msg*
%14 = alloca [128 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%15 = load i8*, i8** %8
%16 = load i8*, i8** %10
%17 = load i8*, i8** %11
%18 = load i8*, i8** %7
%19 = bitcast i8* %18 to %struct.t_relay_client*
store %struct.t_relay_client* %19, %struct.t_relay_client** %12
%20 = load %struct.t_relay_client*, %struct.t_relay_client** %12
%21 = icmp ne %struct.t_relay_client* %20, null
br i1 %21, label %22, label %26
22: ; preds = %5
%23 = load %struct.t_relay_client*, %struct.t_relay_client** %12
%24 = call i32 @relay_client_valid(%struct.t_relay_client* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22, %5
store i32 0, i32* %6
br label %56
27: ; preds = %22
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%29 = load i8*, i8** %9
%30 = call i32 @snprintf(i8* %28, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %9
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %27
%35 = load i8*, i8** %9
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %55
38: ; preds = %34, %27
%39 = load %struct.t_relay_client*, %struct.t_relay_client** %12
%40 = call i64 @relay_weechat_protocol_is_sync(%struct.t_relay_client* %39, i32* null, i32 8)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%44 = call %struct.t_relay_weechat_msg* @relay_weechat_msg_new(i8* %43)
store %struct.t_relay_weechat_msg* %44, %struct.t_relay_weechat_msg** %13
%45 = load %struct.t_relay_weechat_msg*, %struct.t_relay_weechat_msg** %13
%46 = icmp ne %struct.t_relay_weechat_msg* %45, null
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load %struct.t_relay_client*, %struct.t_relay_client** %12
%49 = load %struct.t_relay_weechat_msg*, %struct.t_relay_weechat_msg** %13
%50 = call i32 @relay_weechat_msg_send(%struct.t_relay_client* %48, %struct.t_relay_weechat_msg* %49)
%51 = load %struct.t_relay_weechat_msg*, %struct.t_relay_weechat_msg** %13
%52 = call i32 @relay_weechat_msg_free(%struct.t_relay_weechat_msg* %51)
br label %53
53: ; preds = %47, %42
br label %54
54: ; preds = %53, %38
br label %55
55: ; preds = %54, %34
store i32 0, i32* %6
br label %56
56: ; preds = %55, %26
%57 = load i32, i32* %6
ret i32 %57
}

LLVM IR (-O2):
%struct.t_relay_client = type { i32 }
%struct.t_relay_weechat_msg = type { i32 }
@.str = [4 x i8] c"_%s\00"
@.str.1 = [8 x i8] c"upgrade\00"
@.str.2 = [14 x i8] c"upgrade_ended\00"
define i32 @relay_weechat_protocol_signal_upgrade_cb(i8* %0, i8* nocapture readnone %1, i8* %2, i8* nocapture readnone %3, i8* nocapture readnone %4) {
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%8 = bitcast i8* %0 to %struct.t_relay_client*
%9 = icmp eq i8* %0, null
br i1 %9, label %29, label %10
10: ; preds = %5
%11 = tail call i32 @relay_client_valid(%struct.t_relay_client* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %29, label %13
13: ; preds = %10
%14 = call i32 @snprintf(i8* %7, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%15 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %17, %13
%21 = call i64 @relay_weechat_protocol_is_sync(%struct.t_relay_client* %8, i32* null, i32 8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = call %struct.t_relay_weechat_msg* @relay_weechat_msg_new(i8* %7)
%25 = icmp eq %struct.t_relay_weechat_msg* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i32 @relay_weechat_msg_send(%struct.t_relay_client* %8, %struct.t_relay_weechat_msg* %24)
%28 = call i32 @relay_weechat_msg_free(%struct.t_relay_weechat_msg* %24)
br label %29
29: ; preds = %17, %23, %26, %20, %5, %10
ret i32 0
}