#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 */

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SOL_TCP;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ TCP_KEEPIDLE;
int /*<<< orphan*/ TCP_KEEPINTVL;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
void set_ka(int fd) {
  int on = 1, interval = 31;
  setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof on);
  setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &interval, sizeof interval);
  setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof interval);
}


x86 assembly (clang, -O0):
<set_ka>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1f,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb5(%rip),%rax
mov    (%rax),%esi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ka>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
movl   $0x1f,0x8(%rsp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2e8c(%rip),%r15
mov    (%r15),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r15),%esi
mov    0x2e59(%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
define void @set_ka(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
store i32 31, i32* %4
%5 = load i32, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_KEEPALIVE
%8 = call i32 @setsockopt(i32 %5, i32 %6, i32 %7, i32* %3, i32 4)
%9 = load i32, i32* %2
%10 = load i32, i32* @SOL_TCP
%11 = load i32, i32* @TCP_KEEPIDLE
%12 = call i32 @setsockopt(i32 %9, i32 %10, i32 %11, i32* %4, i32 4)
%13 = load i32, i32* %2
%14 = load i32, i32* @SOL_TCP
%15 = load i32, i32* @TCP_KEEPINTVL
%16 = call i32 @setsockopt(i32 %13, i32 %14, i32 %15, i32* %4, i32 4)
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
define void @set_ka(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 31, i32* %3
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_KEEPALIVE
%8 = call i32 @setsockopt(i32 %0, i32 %6, i32 %7, i32* %2, i32 4)
%9 = load i32, i32* @SOL_TCP
%10 = load i32, i32* @TCP_KEEPIDLE
%11 = call i32 @setsockopt(i32 %0, i32 %9, i32 %10, i32* %3, i32 4)
%12 = load i32, i32* @SOL_TCP
%13 = load i32, i32* @TCP_KEEPINTVL
%14 = call i32 @setsockopt(i32 %0, i32 %12, i32 %13, i32* %3, i32 4)
ret void
}