// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/sentinel.c
// Function: sentinelSendHello
int sentinelSendHello(sentinelRedisInstance *ri) {
    char ip[REDIS_IP_STR_LEN];
    char payload[REDIS_IP_STR_LEN+1024];
    int retval;

    // 如果实例是主服务器，那么使用此实例的信息
    // 如果实例是从服务器，那么使用这个从服务器的主服务器的信息
    sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master;

    // 获取地址信息
    sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master);

    /* Try to obtain our own IP address. */
    // 获取实例自身的地址
    if (anetSockName(ri->cc->c.fd,ip,sizeof(ip),NULL) == -1) return REDIS_ERR;
    if (ri->flags & SRI_DISCONNECTED) return REDIS_ERR;

    /* Format and send the Hello message. */
    // 格式化信息
    snprintf(payload,sizeof(payload),
        "%s,%d,%s,%llu," /* Info about this sentinel. */
        "%s,%s,%d,%llu", /* Info about current master. */
        ip, server.port, server.runid,
        (unsigned long long) sentinel.current_epoch,
        /* --- */
        master->name,master_addr->ip,master_addr->port,
        (unsigned long long) master->config_epoch);
    
    // 发送信息
    retval = redisAsyncCommand(ri->cc,
        sentinelPublishReplyCallback, NULL, "PUBLISH %s %s",
            SENTINEL_HELLO_CHANNEL,payload);

    if (retval != REDIS_OK) return REDIS_ERR;

    ri->pending_commands++;

    return REDIS_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7e0ed
movq -0x20(%rbp), %rax
movq %rax, -0x4a0(%rbp)
jmp 0x7e0ff
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x4a0(%rbp)
movq -0x4a0(%rbp), %rax
movq %rax, -0x490(%rbp)
movq -0x490(%rbp), %rdi
callq 0x7b960
movq %rax, -0x498(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x84(%rax), %edi
leaq -0x50(%rbp), %rsi
movl $0x2e, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x22d30
cmpl $-0x1, %eax
jne 0x7e151
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x7e247
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x7e16b
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x7e247
leaq -0x480(%rbp), %rdi
leaq -0x50(%rbp), %rcx
leaq 0x9577b(%rip), %rax     # 0x1138f8
movl 0x88(%rax), %r8d
movq 0xaa0ad(%rip), %r14     # 0x128238
movq -0x490(%rbp), %rax
movq 0x8(%rax), %rbx
movq -0x498(%rbp), %rax
movq (%rax), %r11
movq -0x498(%rbp), %rax
movl 0x8(%rax), %r10d
movq -0x490(%rbp), %rax
movq 0x18(%rax), %rax
movl $0x42e, %esi            # imm = 0x42E
leaq 0x6b522(%rip), %rdx     # 0xe96e4
leaq 0x9572f(%rip), %r9      # 0x1138f8
addq $0x58, %r9
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x1f120
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
leaq -0x480(%rbp), %r9
leaq -0x4e2(%rip), %rsi      # 0x7dd20
xorl %eax, %eax
movl %eax, %edx
leaq 0x6b4f3(%rip), %rcx     # 0xe9700
leaq 0x6b2d7(%rip), %r8      # 0xe94eb
movb $0x0, %al
callq 0x86730
movl %eax, -0x484(%rbp)
cmpl $0x0, -0x484(%rbp)
je 0x7e233
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x7e247
movq -0x20(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)