#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_dogechat_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_dogechat_msg_free(struct t_relay_dogechat_msg *);
struct t_relay_dogechat_msg *relay_dogechat_msg_new(char *);
int /*<<< orphan*/ relay_dogechat_msg_send(struct t_relay_client *,
                                           struct t_relay_dogechat_msg *);
scalar_t__ relay_dogechat_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_dogechat_protocol_signal_upgrade_cb(void *data, const char *signal,
                                              const char *type_data,
                                              void *signal_data) {
  struct t_relay_client *ptr_client;
  struct t_relay_dogechat_msg *msg;
  char str_signal[128];
  (void)type_data;
  (void)signal_data;
  ptr_client = (struct t_relay_client *)data;
  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_dogechat_protocol_is_sync(ptr_client, NULL, 8)) {
      msg = relay_dogechat_msg_new(str_signal);
      if (msg) {
        relay_dogechat_msg_send(ptr_client, msg);
        relay_dogechat_msg_free(msg);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<relay_dogechat_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    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b0 <relay_dogechat_protocol_signal_upgrade_cb+0x40>
mov    -0x30(%rbp),%rdi
call   1070 <relay_client_valid@plt>
cmp    $0x0,%eax
jne    11bc <relay_dogechat_protocol_signal_upgrade_cb+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    126a <relay_dogechat_protocol_signal_upgrade_cb+0xfa>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x80,%esi
lea    0xe2d(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     120c <relay_dogechat_protocol_signal_upgrade_cb+0x9c>
mov    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1263 <relay_dogechat_protocol_signal_upgrade_cb+0xf3>
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1080 <relay_dogechat_protocol_is_sync@plt>
cmp    $0x0,%rax
je     125e <relay_dogechat_protocol_signal_upgrade_cb+0xee>
lea    -0xc0(%rbp),%rdi
call   1090 <relay_dogechat_msg_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1259 <relay_dogechat_protocol_signal_upgrade_cb+0xe9>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <relay_dogechat_msg_send@plt>
mov    -0x38(%rbp),%rdi
call   1060 <relay_dogechat_msg_free@plt>
jmp    125e <relay_dogechat_protocol_signal_upgrade_cb+0xee>
jmp    1263 <relay_dogechat_protocol_signal_upgrade_cb+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relay_dogechat_protocol_signal_upgrade_cb>:
push   %r14
push   %rbx
sub    $0x88,%rsp
test   %rdi,%rdi
je     1208 <relay_dogechat_protocol_signal_upgrade_cb+0x98>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1070 <relay_client_valid@plt>
test   %eax,%eax
je     1208 <relay_dogechat_protocol_signal_upgrade_cb+0x98>
lea    0xe67(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d1 <relay_dogechat_protocol_signal_upgrade_cb+0x61>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1208 <relay_dogechat_protocol_signal_upgrade_cb+0x98>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <relay_dogechat_protocol_is_sync@plt>
test   %rax,%rax
je     1208 <relay_dogechat_protocol_signal_upgrade_cb+0x98>
mov    %rsp,%rdi
call   1090 <relay_dogechat_msg_new@plt>
test   %rax,%rax
je     1208 <relay_dogechat_protocol_signal_upgrade_cb+0x98>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <relay_dogechat_msg_send@plt>
mov    %rbx,%rdi
call   1060 <relay_dogechat_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_dogechat_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_dogechat_protocol_signal_upgrade_cb(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.t_relay_client*
%11 = alloca %struct.t_relay_dogechat_msg*
%12 = alloca [128 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %8
%14 = load i8*, i8** %9
%15 = load i8*, i8** %6
%16 = bitcast i8* %15 to %struct.t_relay_client*
store %struct.t_relay_client* %16, %struct.t_relay_client** %10
%17 = load %struct.t_relay_client*, %struct.t_relay_client** %10
%18 = icmp ne %struct.t_relay_client* %17, null
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = load %struct.t_relay_client*, %struct.t_relay_client** %10
%21 = call i32 @relay_client_valid(%struct.t_relay_client* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19, %4
store i32 0, i32* %5
br label %53
24: ; preds = %19
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%26 = load i8*, i8** %7
%27 = call i32 @snprintf(i8* %25, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %7
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = load i8*, i8** %7
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %52
35: ; preds = %31, %24
%36 = load %struct.t_relay_client*, %struct.t_relay_client** %10
%37 = call i64 @relay_dogechat_protocol_is_sync(%struct.t_relay_client* %36, i32* null, i32 8)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%41 = call %struct.t_relay_dogechat_msg* @relay_dogechat_msg_new(i8* %40)
store %struct.t_relay_dogechat_msg* %41, %struct.t_relay_dogechat_msg** %11
%42 = load %struct.t_relay_dogechat_msg*, %struct.t_relay_dogechat_msg** %11
%43 = icmp ne %struct.t_relay_dogechat_msg* %42, null
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = load %struct.t_relay_client*, %struct.t_relay_client** %10
%46 = load %struct.t_relay_dogechat_msg*, %struct.t_relay_dogechat_msg** %11
%47 = call i32 @relay_dogechat_msg_send(%struct.t_relay_client* %45, %struct.t_relay_dogechat_msg* %46)
%48 = load %struct.t_relay_dogechat_msg*, %struct.t_relay_dogechat_msg** %11
%49 = call i32 @relay_dogechat_msg_free(%struct.t_relay_dogechat_msg* %48)
br label %50
50: ; preds = %44, %39
br label %51
51: ; preds = %50, %35
br label %52
52: ; preds = %51, %31
store i32 0, i32* %5
br label %53
53: ; preds = %52, %23
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
%struct.t_relay_client = type { i32 }
%struct.t_relay_dogechat_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_dogechat_protocol_signal_upgrade_cb(i8* %0, i8* %1, i8* nocapture readnone %2, i8* nocapture readnone %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = bitcast i8* %0 to %struct.t_relay_client*
%8 = icmp eq i8* %0, null
br i1 %8, label %28, label %9
9: ; preds = %4
%10 = tail call i32 @relay_client_valid(%struct.t_relay_client* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%14 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16, %12
%20 = call i64 @relay_dogechat_protocol_is_sync(%struct.t_relay_client* %7, i32* null, i32 8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call %struct.t_relay_dogechat_msg* @relay_dogechat_msg_new(i8* %6)
%24 = icmp eq %struct.t_relay_dogechat_msg* %23, null
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i32 @relay_dogechat_msg_send(%struct.t_relay_client* %7, %struct.t_relay_dogechat_msg* %23)
%27 = call i32 @relay_dogechat_msg_free(%struct.t_relay_dogechat_msg* %23)
br label %28
28: ; preds = %16, %22, %25, %19, %4, %9
ret i32 0
}