#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 socklen_t;
typedef int /*<<< orphan*/ rcvbufSize;
typedef int int32_t;

/* Variables and functions */
int INT_MAX;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
scalar_t__ debug(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *, int /*<<< orphan*/);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int /*<<< orphan*/ info(char *, ...);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
void set_rcv_buffer(int32_t *sock) {
  int32_t rcvbufSize;
  rcvbufSize = -1;
  socklen_t int32_tsizeof = sizeof(rcvbufSize);
  getsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &rcvbufSize, &int32_tsizeof);
  if (debug(6))
    info("set_rcv_buffer(): current receive buffer size: %d", rcvbufSize);
  rcvbufSize = INT_MAX / 2;
  if ((setsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &rcvbufSize, sizeof(int32_t))) <
      0) {
    error("set_rcv_buffer(): setsockopt(): errno %d", errno);
  } else {
    rcvbufSize = -1;
    if (getsockopt(*sock, SOL_SOCKET, SO_RCVBUF, &rcvbufSize, &int32_tsizeof) ==
        0) {
      if (debug(6)) {
        info("set_rcv_buffer(): new receive buffer size: %d", rcvbufSize);
        info("set_rcv_buffer(): Buffer maximum size value may be improved "
             "modifying net.core.rmem_max value!");
      }
    } else {
      error("set_rcv_buffer(): getsockopt(): error getting receive buffer "
            "value, errno %d",
            errno);
    }
  }
}


x86 assembly (clang, -O0):
<set_rcv_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1050 <getsockopt@plt>
mov    $0x6,%edi
call   1040 <debug@plt>
cmp    $0x0,%rax
je     11b4 <set_rcv_buffer+0x64>
mov    -0xc(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1070 <info@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1213 <set_rcv_buffer+0xc3>
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
call   1060 <error@plt>
jmp    129b <set_rcv_buffer+0x14b>
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1050 <getsockopt@plt>
cmp    $0x0,%rax
jne    1281 <set_rcv_buffer+0x131>
mov    $0x6,%edi
call   1040 <debug@plt>
cmp    $0x0,%rax
je     127c <set_rcv_buffer+0x12c>
mov    -0xc(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1070 <info@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1070 <info@plt>
jmp    1296 <set_rcv_buffer+0x146>
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1060 <error@plt>
jmp    129b <set_rcv_buffer+0x14b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rcv_buffer>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0x4,0xc(%rsp)
mov    (%rdi),%edi
mov    0x2e73(%rip),%r14
mov    (%r14),%esi
mov    0x2e51(%rip),%r15
mov    (%r15),%edx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <getsockopt@plt>
mov    $0x6,%edi
call   1040 <debug@plt>
test   %rax,%rax
je     11b2 <set_rcv_buffer+0x62>
mov    0x8(%rsp),%esi
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1070 <info@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,0x8(%rsp)
mov    (%rbx),%edi
mov    (%r14),%esi
mov    (%r15),%edx
lea    0x8(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     121b <set_rcv_buffer+0xcb>
movl   $0xffffffff,0x8(%rsp)
ff
mov    (%rbx),%edi
mov    (%r14),%esi
mov    (%r15),%edx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <getsockopt@plt>
test   %rax,%rax
je     123a <set_rcv_buffer+0xea>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    0xecf(%rip),%rdi
jmp    122b <set_rcv_buffer+0xdb>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   1060 <error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x6,%edi
call   1040 <debug@plt>
test   %rax,%rax
je     1230 <set_rcv_buffer+0xe0>
mov    0x8(%rsp),%esi
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1070 <info@plt>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1070 <info@plt>
jmp    1230 <set_rcv_buffer+0xe0>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [50 x i8] c"set_rcv_buffer(): current receive buffer size: %d\00"
@INT_MAX = global i32 0
@.str.1 = [41 x i8] c"set_rcv_buffer(): setsockopt(): errno %d\00"
@errno = global i32 0
@.str.2 = [46 x i8] c"set_rcv_buffer(): new receive buffer size: %d\00"
@.str.3 = [95 x i8] c"set_rcv_buffer(): Buffer maximum size value may be improved modifying net.core.rmem_max value!\00"
@.str.4 = [77 x i8] c"set_rcv_buffer(): getsockopt(): error getting receive buffer value, errno %d\00"
define void @set_rcv_buffer(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 -1, i32* %3
store i32 4, i32* %4
%5 = load i32*, i32** %2
%6 = load i32, i32* %5
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_RCVBUF
%9 = call i64 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %3, i32* %4)
%10 = call i64 @debug(i32 6)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %1
%16 = load i32, i32* @INT_MAX
%17 = sdiv i32 %16, 2
store i32 %17, i32* %3
%18 = load i32*, i32** %2
%19 = load i32, i32* %18
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_RCVBUF
%22 = call i64 @setsockopt(i32 %19, i32 %20, i32 %21, i32* %3, i32 4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i32, i32* @errno
%26 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %46
27: ; preds = %15
store i32 -1, i32* %3
%28 = load i32*, i32** %2
%29 = load i32, i32* %28
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_RCVBUF
%32 = call i64 @getsockopt(i32 %29, i32 %30, i32 %31, i32* %3, i32* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %27
%35 = call i64 @debug(i32 6)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %37, %34
br label %45
42: ; preds = %27
%43 = load i32, i32* @errno
%44 = call i32 @error(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %41
br label %46
46: ; preds = %45, %24
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [50 x i8] c"set_rcv_buffer(): current receive buffer size: %d\00"
@INT_MAX = global i32 0
@.str.1 = [41 x i8] c"set_rcv_buffer(): setsockopt(): errno %d\00"
@errno = global i32 0
@.str.2 = [46 x i8] c"set_rcv_buffer(): new receive buffer size: %d\00"
@.str.3 = [95 x i8] c"set_rcv_buffer(): Buffer maximum size value may be improved modifying net.core.rmem_max value!\00"
@.str.4 = [77 x i8] c"set_rcv_buffer(): getsockopt(): error getting receive buffer value, errno %d\00"
define void @set_rcv_buffer(i32* nocapture %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 4, i32* %3
%6 = load i32, i32* %0
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_RCVBUF
%9 = call i64 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %2, i32* %3)
%10 = call i64 @debug(i32 6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %1
%16 = load i32, i32* @INT_MAX
%17 = sdiv i32 %16, 2
store i32 %17, i32* %2
%18 = load i32, i32* %0
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_RCVBUF
%21 = call i64 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %2, i32 4)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* @errno
%25 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %42
26: ; preds = %15
store i32 -1, i32* %2
%27 = load i32, i32* %0
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_RCVBUF
%30 = call i64 @getsockopt(i32 %27, i32 %28, i32 %29, i32* %2, i32* %3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %26
%33 = call i64 @debug(i32 6)
%34 = icmp eq i64 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %32
%36 = load i32, i32* %2
%37 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.3, i64 0, i64 0))
br label %42
39: ; preds = %26
%40 = load i32, i32* @errno
%41 = call i32 @error(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %35, %32, %23
ret void
}