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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ errno;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int set_rcvbuf(int fd, void *optval, int optlen) {
  int rc;
  int buf = *(int *)optval;
  if (buf < 0) {
    errno = EINVAL;
    return -1;
  }
  rc = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf, sizeof(buf));
  return rc;
}


x86 assembly (clang, -O0):
<set_rcvbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1153 <set_rcvbuf+0x43>
mov    0x2e8c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <set_rcvbuf+0x70>
mov    -0x8(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rcvbuf>:
push   %rax
mov    (%rsi),%eax
mov    %eax,0x4(%rsp)
test   %eax,%eax
js     113f <set_rcvbuf+0x2f>
mov    0x2ec6(%rip),%rax
mov    (%rax),%esi
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
pop    %rcx
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    0x2e81(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
define i32 @set_rcvbuf(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i32 -1, i32* %4
br label %23
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_RCVBUF
%21 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %9, i32 4)
store i32 %21, i32* %8
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %23
23: ; preds = %17, %15
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
define i32 @set_rcvbuf(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = bitcast i8* %1 to i32*
%7 = load i32, i32* %6
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %15
11: ; preds = %3
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_RCVBUF
%14 = call i32 @setsockopt(i32 %0, i32 %12, i32 %13, i32* %4, i32 4)
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ -1, %9 ], [ %14, %11 ]
ret i32 %16
}