#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 */
scalar_t__ ENOTSOCK;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ TCP_WINDOW_CLAMP;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
void socket_ready_send(int fd) {
  int optval = 128;
  int res = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval));
  if (res == -1 && errno == ENOTSOCK) {
    return;
  }
  assert(res == 0);
  optval = 128;
  assert(
      !setsockopt(fd, IPPROTO_TCP, TCP_WINDOW_CLAMP, &optval, sizeof(optval)));
}


x86 assembly (clang, -O0):
<socket_ready_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x80,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1182 <socket_ready_send+0x62>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <socket_ready_send+0x62>
jmp    11d0 <socket_ready_send+0xb0>
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x80,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%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_send>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x80,0xc(%rsp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    116c <socket_ready_send+0x4c>
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e59(%rip),%rdx
cmp    (%rdx),%rcx
je     11b2 <socket_ready_send+0x92>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
movl   $0x80,0xc(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
@IPPROTO_TCP = global i32 0
@TCP_WINDOW_CLAMP = global i32 0
define void @socket_ready_send(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 128, i32* %3
%5 = load i32, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_RCVBUF
%8 = call i32 @setsockopt(i32 %5, i32 %6, i32 %7, i32* %3, i32 4)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOTSOCK
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %29
16: ; preds = %11, %1
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i32 128, i32* %3
%21 = load i32, i32* %2
%22 = load i32, i32* @IPPROTO_TCP
%23 = load i32, i32* @TCP_WINDOW_CLAMP
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %3, i32 4)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
br label %29
29: ; preds = %16, %15
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
@IPPROTO_TCP = global i32 0
@TCP_WINDOW_CLAMP = global i32 0
define void @socket_ready_send(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 128, i32* %2
%4 = load i32, i32* @SOL_SOCKET
%5 = load i32, i32* @SO_RCVBUF
%6 = call i32 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %2, i32 4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOTSOCK
%11 = icmp eq i64 %9, %10
br i1 %11, label %22, label %12
12: ; preds = %8, %1
%13 = icmp eq i32 %6, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i32 128, i32* %2
%16 = load i32, i32* @IPPROTO_TCP
%17 = load i32, i32* @TCP_WINDOW_CLAMP
%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)
br label %22
22: ; preds = %8, %12
ret void
}