#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 configure_keepalive(int fd) {
  int optval = 1;
  socklen_t optlen = sizeof(optval);
  setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
  int keepcnt = 7;
  int keepidle = 30;
  int keepintvl = 30;
  setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &keepcnt, sizeof(int));
  setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &keepidle, sizeof(int));
  setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(int));
}


x86 assembly (clang, -O0):
<configure_keepalive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x4,-0xc(%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   $0x7,-0x10(%rbp)
movl   $0x1e,-0x14(%rbp)
movl   $0x1e,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configure_keepalive>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x1,0x14(%rsp)
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0x7,0x10(%rsp)
movl   $0x1e,0xc(%rsp)
movl   $0x1e,0x8(%rsp)
mov    0x2e7e(%rip),%r14
mov    (%r14),%esi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r14),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r14),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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