// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/anet.c
// Function: anetKeepAlive
int anetKeepAlive(char *err, int fd, int interval)
{
    int val = 1;

    if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1)
    {
        anetSetError(err, "setsockopt SO_KEEPALIVE: %s", strerror(errno));
        return ANET_ERR;
    }

#ifdef __linux__
    /* Default settings are more or less garbage, with the keepalive time
     * set to 7200 by default on Linux. Modify settings to make the feature
     * actually useful. */

    /* Send first probe after interval. */
    val = interval;
    if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
        anetSetError(err, "setsockopt TCP_KEEPIDLE: %s\n", strerror(errno));
        return ANET_ERR;
    }

    /* Send next probes after the specified interval. Note that we set the
     * delay as interval / 3, as we send three probes before detecting
     * an error (see the next setsockopt call). */
    val = interval/3;
    if (val == 0) val = 1;
    if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
        anetSetError(err, "setsockopt TCP_KEEPINTVL: %s\n", strerror(errno));
        return ANET_ERR;
    }

    /* Consider the socket in error state after three we send three ACK
     * probes without getting a reply. */
    val = 3;
    if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
        anetSetError(err, "setsockopt TCP_KEEPCNT: %s\n", strerror(errno));
        return ANET_ERR;
    }
#else
    ((void) interval); /* Avoid unused var warning for non Linux systems. */
#endif

    return ANET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x9, %edx
leaq -0x1c(%rbp), %rcx
movl $0x4, %r8d
callq 0x10100
cmpl $-0x1, %eax
jne 0x10a7f
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x28(%rbp), %rdi
movq %rax, %rdx
leaq 0x765c9(%rip), %rsi     # 0x87035
movb $0x0, %al
callq 0x10900
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10ba5
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %edi
movl $0x6, %esi
movl $0x4, %r8d
leaq -0x1c(%rbp), %rcx
movl %r8d, %edx
callq 0x10100
cmpl $0x0, %eax
jge 0x10ad9
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x7658b(%rip), %rsi     # 0x87051
movb $0x0, %al
callq 0x10900
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10ba5
movl -0x18(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x10af4
movl $0x1, -0x1c(%rbp)
movl -0x14(%rbp), %edi
movl $0x6, %esi
movl $0x5, %edx
leaq -0x1c(%rbp), %rcx
movl $0x4, %r8d
callq 0x10100
cmpl $0x0, %eax
jge 0x10b47
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x76537(%rip), %rsi     # 0x8706e
movb $0x0, %al
callq 0x10900
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10ba5
movl $0x3, -0x1c(%rbp)
movl -0x14(%rbp), %edi
movl $0x6, %edx
leaq -0x1c(%rbp), %rcx
movl $0x4, %r8d
movl %edx, %esi
callq 0x10100
cmpl $0x0, %eax
jge 0x10b9e
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x764fe(%rip), %rsi     # 0x8708c
movb $0x0, %al
callq 0x10900
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10ba5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop