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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SOL_TCP;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ TCP_KEEPCNT;
int /*<<< orphan*/ TCP_KEEPIDLE;
int /*<<< orphan*/ TCP_KEEPINTVL;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
void activateKeepAlive(int sd) {
  int optval;
  socklen_t optlen = sizeof(optval);
  optval = 1;
  setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
  optval = 20;
  setsockopt(sd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen);
  optval = 5;
  setsockopt(sd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen);
  optval = 3;
  setsockopt(sd, SOL_TCP, TCP_KEEPCNT, &optval, optlen);
}


x86 assembly (clang, -O0):
<activateKeepAlive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb5(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    -0xc(%rbp),%r8d
lea    -0x8(%rbp),%rcx
call   1030 <setsockopt@plt>
movl   $0x14,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    -0xc(%rbp),%r8d
lea    -0x8(%rbp),%rcx
call   1030 <setsockopt@plt>
movl   $0x5,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    -0xc(%rbp),%r8d
lea    -0x8(%rbp),%rcx
call   1030 <setsockopt@plt>
movl   $0x3,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    -0xc(%rbp),%r8d
lea    -0x8(%rbp),%rcx
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<activateKeepAlive>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r14
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x14,0xc(%rsp)
mov    0x2e89(%rip),%r15
mov    (%r15),%esi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x5,0xc(%rsp)
mov    (%r15),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x3,0xc(%rsp)
mov    (%r15),%esi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@SOL_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
define void @activateKeepAlive(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
store i32 1, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_KEEPALIVE
%8 = load i32, i32* %4
%9 = call i32 @setsockopt(i32 %5, i32 %6, i32 %7, i32* %3, i32 %8)
store i32 20, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* @SOL_TCP
%12 = load i32, i32* @TCP_KEEPIDLE
%13 = load i32, i32* %4
%14 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, i32* %3, i32 %13)
store i32 5, i32* %3
%15 = load i32, i32* %2
%16 = load i32, i32* @SOL_TCP
%17 = load i32, i32* @TCP_KEEPINTVL
%18 = load i32, i32* %4
%19 = call i32 @setsockopt(i32 %15, i32 %16, i32 %17, i32* %3, i32 %18)
store i32 3, i32* %3
%20 = load i32, i32* %2
%21 = load i32, i32* @SOL_TCP
%22 = load i32, i32* @TCP_KEEPCNT
%23 = load i32, i32* %4
%24 = call i32 @setsockopt(i32 %20, i32 %21, i32 %22, i32* %3, i32 %23)
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@SOL_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
define void @activateKeepAlive(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = load i32, i32* @SOL_SOCKET
%5 = load i32, i32* @SO_KEEPALIVE
%6 = call i32 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %2, i32 4)
store i32 20, i32* %2
%7 = load i32, i32* @SOL_TCP
%8 = load i32, i32* @TCP_KEEPIDLE
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, i32* %2, i32 4)
store i32 5, i32* %2
%10 = load i32, i32* @SOL_TCP
%11 = load i32, i32* @TCP_KEEPINTVL
%12 = call i32 @setsockopt(i32 %0, i32 %10, i32 %11, i32* %2, i32 4)
store i32 3, i32* %2
%13 = load i32, i32* @SOL_TCP
%14 = load i32, i32* @TCP_KEEPCNT
%15 = call i32 @setsockopt(i32 %0, i32 %13, i32 %14, i32* %2, i32 4)
ret void
}