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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
void socket_tryreservein(int s, int size) {
  while (size >= 1024) {
    if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof size) == 0)
      return;
    size -= (size >> 5);
  }
}


x86 assembly (clang, -O0):
<socket_tryreservein>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jl     1171 <socket_tryreservein+0x61>
mov    -0x4(%rbp),%edi
mov    0x2eb3(%rip),%rax
mov    (%rax),%esi
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jne    115e <socket_tryreservein+0x4e>
jmp    1171 <socket_tryreservein+0x61>
mov    -0x8(%rbp),%ecx
sar    $0x5,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    111e <socket_tryreservein+0xe>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_tryreservein>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
cmp    $0x400,%esi
jl     1172 <socket_tryreservein+0x62>
mov    %edi,%ebx
mov    0x2ebb(%rip),%r15
mov    0x2ea4(%rip),%r12
lea    0x4(%rsp),%r14
nopl   0x0(%rax)
mov    (%r15),%esi
mov    (%r12),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     1172 <socket_tryreservein+0x62>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
sar    $0x5,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
cmp    $0x3ff,%eax
jg     1140 <socket_tryreservein+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
define void @socket_tryreservein(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %5
5: ; preds = %15, %2
%6 = load i32, i32* %4
%7 = icmp sge i32 %6, 1024
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %3
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_RCVBUF
%12 = call i64 @setsockopt(i32 %9, i32 %10, i32 %11, i32* %4, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8
br label %20
15: ; preds = %8
%16 = load i32, i32* %4
%17 = ashr i32 %16, 5
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, %17
store i32 %19, i32* %4
br label %5
20: ; preds = %14, %5
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
define void @socket_tryreservein(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = icmp sgt i32 %1, 1023
br i1 %4, label %5, label %15
5: ; preds = %2, %10
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_RCVBUF
%8 = call i64 @setsockopt(i32 %0, i32 %6, i32 %7, i32* %3, i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = load i32, i32* %3
%12 = ashr i32 %11, 5
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %3
%14 = icmp sgt i32 %13, 1023
br i1 %14, label %5, label %15
15: ; preds = %10, %5, %2
ret void
}