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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ TCP_KEEPCNT;
int /*<<< orphan*/ TCP_KEEPIDLE;
int /*<<< orphan*/ TCP_KEEPINTVL;
int /*<<< orphan*/ TCP_USER_TIMEOUT;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
void socket_ready(int fd) {
  int optval = 1;
  assert(!setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)));
  optval = 30;
  assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &optval, sizeof(optval)));
  optval = 10;
  assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &optval, sizeof(optval)));
  optval = 3;
  assert(!setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof(optval)));
  optval = 60000;
  assert(
      !setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &optval, sizeof(optval)));
}


x86 assembly (clang, -O0):
<socket_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x1e,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0xa,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x3,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0xea60,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_ready>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r14
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0x1e,0xc(%rsp)
mov    0x2e64(%rip),%r15
mov    (%r15),%esi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0xa,0xc(%rsp)
mov    (%r15),%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0x3,0xc(%rsp)
mov    (%r15),%esi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0xea60,0xc(%rsp)
mov    (%r15),%esi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@IPPROTO_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
@TCP_USER_TIMEOUT = global i32 0
define void @socket_ready(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @SOL_SOCKET
%6 = load i32, i32* @SO_KEEPALIVE
%7 = call i32 @setsockopt(i32 %4, i32 %5, i32 %6, i32* %3, i32 4)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
store i32 30, i32* %3
%12 = load i32, i32* %2
%13 = load i32, i32* @IPPROTO_TCP
%14 = load i32, i32* @TCP_KEEPIDLE
%15 = call i32 @setsockopt(i32 %12, i32 %13, i32 %14, i32* %3, i32 4)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
store i32 10, i32* %3
%20 = load i32, i32* %2
%21 = load i32, i32* @IPPROTO_TCP
%22 = load i32, i32* @TCP_KEEPINTVL
%23 = call i32 @setsockopt(i32 %20, i32 %21, i32 %22, i32* %3, i32 4)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
store i32 3, i32* %3
%28 = load i32, i32* %2
%29 = load i32, i32* @IPPROTO_TCP
%30 = load i32, i32* @TCP_KEEPCNT
%31 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %3, i32 4)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
store i32 60000, i32* %3
%36 = load i32, i32* %2
%37 = load i32, i32* @IPPROTO_TCP
%38 = load i32, i32* @TCP_USER_TIMEOUT
%39 = call i32 @setsockopt(i32 %36, i32 %37, i32 %38, i32* %3, i32 4)
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@IPPROTO_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
@TCP_USER_TIMEOUT = global i32 0
define void @socket_ready(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)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
store i32 30, i32* %2
%10 = load i32, i32* @IPPROTO_TCP
%11 = load i32, i32* @TCP_KEEPIDLE
%12 = call i32 @setsockopt(i32 %0, i32 %10, i32 %11, i32* %2, i32 4)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i32 10, i32* %2
%16 = load i32, i32* @IPPROTO_TCP
%17 = load i32, i32* @TCP_KEEPINTVL
%18 = call i32 @setsockopt(i32 %0, i32 %16, i32 %17, i32* %2, i32 4)
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 3, i32* %2
%22 = load i32, i32* @IPPROTO_TCP
%23 = load i32, i32* @TCP_KEEPCNT
%24 = call i32 @setsockopt(i32 %0, i32 %22, i32 %23, i32* %2, i32 4)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
store i32 60000, i32* %2
%28 = load i32, i32* @IPPROTO_TCP
%29 = load i32, i32* @TCP_USER_TIMEOUT
%30 = call i32 @setsockopt(i32 %0, i32 %28, i32 %29, i32* %2, i32 4)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
ret void
}