#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*/ keepInterval;
typedef int /*<<< orphan*/ keepIdle;
typedef int /*<<< orphan*/ keepCount;
typedef int /*<<< orphan*/ keepAlive;

/* 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 setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int SockAPI_TCPSetKeepAlive(int sd, int interval, int cnt) {
  int keepAlive = 1;
  int keepIdle = interval;
  int keepInterval = interval;
  int keepCount = 3;
  int ret1 = setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepAlive,
                        sizeof(keepAlive));
  int ret2 = setsockopt(sd, SOL_TCP, TCP_KEEPIDLE, (void *)&keepIdle,
                        sizeof(keepIdle));
  int ret3 = setsockopt(sd, SOL_TCP, TCP_KEEPINTVL, (void *)&keepInterval,
                        sizeof(keepInterval));
  int ret4 = setsockopt(sd, SOL_TCP, TCP_KEEPCNT, (void *)&keepCount,
                        sizeof(keepCount));
  return 0;
}


x86 assembly (clang, -O0):
<SockAPI_TCPSetKeepAlive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SockAPI_TCPSetKeepAlive>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x1,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %esi,0xc(%rsp)
movl   $0x3,0x8(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2e86(%rip),%r14
mov    (%r14),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r14),%esi
mov    0x2e56(%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>
xor    %eax,%eax
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_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
define i32 @SockAPI_TCPSetKeepAlive(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %7
%15 = load i32, i32* %5
store i32 %15, i32* %8
%16 = load i32, i32* %5
store i32 %16, i32* %9
store i32 3, i32* %10
%17 = load i32, i32* %4
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_KEEPALIVE
%20 = bitcast i32* %7 to i8*
%21 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32 4)
store i32 %21, i32* %11
%22 = load i32, i32* %4
%23 = load i32, i32* @SOL_TCP
%24 = load i32, i32* @TCP_KEEPIDLE
%25 = bitcast i32* %8 to i8*
%26 = call i32 @setsockopt(i32 %22, i32 %23, i32 %24, i8* %25, i32 4)
store i32 %26, i32* %12
%27 = load i32, i32* %4
%28 = load i32, i32* @SOL_TCP
%29 = load i32, i32* @TCP_KEEPINTVL
%30 = bitcast i32* %9 to i8*
%31 = call i32 @setsockopt(i32 %27, i32 %28, i32 %29, i8* %30, i32 4)
store i32 %31, i32* %13
%32 = load i32, i32* %4
%33 = load i32, i32* @SOL_TCP
%34 = load i32, i32* @TCP_KEEPCNT
%35 = bitcast i32* %10 to i8*
%36 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i8* %35, i32 4)
store i32 %36, i32* %14
ret i32 0
}

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 i32 @SockAPI_TCPSetKeepAlive(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 %1, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 %1, i32* %6
%11 = bitcast i32* %7 to i8*
store i32 3, i32* %7
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_KEEPALIVE
%14 = call i32 @setsockopt(i32 %0, i32 %12, i32 %13, i8* %8, i32 4)
%15 = load i32, i32* @SOL_TCP
%16 = load i32, i32* @TCP_KEEPIDLE
%17 = call i32 @setsockopt(i32 %0, i32 %15, i32 %16, i8* %9, i32 4)
%18 = load i32, i32* @SOL_TCP
%19 = load i32, i32* @TCP_KEEPINTVL
%20 = call i32 @setsockopt(i32 %0, i32 %18, i32 %19, i8* %10, i32 4)
%21 = load i32, i32* @SOL_TCP
%22 = load i32, i32* @TCP_KEEPCNT
%23 = call i32 @setsockopt(i32 %0, i32 %21, i32 %22, i8* %11, i32 4)
ret i32 0
}