#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 */
typedef int /*<<< orphan*/ val;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
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 -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<anetKeepAlive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11aa <anetKeepAlive+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe67(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <anetKeepAlive+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetKeepAlive>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %rdi,%rbx
movl   $0x1,0xc(%rsp)
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rcx
mov    %eax,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1193 <anetKeepAlive+0x63>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <anetSetError@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str = [28 x i8] c"setsockopt SO_KEEPALIVE: %s\00"
@errno = global i32 0
define i32 @anetKeepAlive(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 1, i32* %8
%9 = load i32, i32* %6
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_KEEPALIVE
%12 = call i32 @setsockopt(i32 %9, i32 %10, i32 %11, i32* %8, i32 4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @anetSetError(i8* %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 -1, i32* %4
br label %20
19: ; preds = %3
store i32 0, i32* %4
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str = [28 x i8] c"setsockopt SO_KEEPALIVE: %s\00"
@errno = global i32 0
define i32 @anetKeepAlive(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_KEEPALIVE
%8 = call i32 @setsockopt(i32 %1, i32 %6, i32 %7, i32* %4, i32 4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %3, %10
%15 = phi i32 [ -1, %10 ], [ 0, %3 ]
ret i32 %15
}