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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ assert(int);
int setsockopt(int, int /*<<< orphan*/, int, char *, int);
int set_tcp_windowsize(int sock, int bufsize, int dir) {
  int rc;
  int newbufsize;
  assert(sock >= 0);
  if (bufsize > 0) {
    newbufsize = bufsize;
    rc = setsockopt(sock, SOL_SOCKET, dir, (char *)&newbufsize,
                    sizeof(newbufsize));
    if (rc < 0) {
      return rc;
    }
  } else {
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_tcp_windowsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
jle    118d <set_tcp_windowsize+0x6d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1188 <set_tcp_windowsize+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <set_tcp_windowsize+0x79>
jmp    1192 <set_tcp_windowsize+0x72>
jmp    1192 <set_tcp_windowsize+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tcp_windowsize>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
test   %ebx,%ebx
jle    1163 <set_tcp_windowsize+0x43>
mov    %ebx,0xc(%rsp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    %r14d,%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1165 <set_tcp_windowsize+0x45>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
define i32 @set_tcp_windowsize(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %3
%17 = load i32, i32* %6
store i32 %17, i32* %9
%18 = load i32, i32* %5
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* %7
%21 = bitcast i32* %9 to i8*
%22 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i8* %21, i32 4)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %30
27: ; preds = %16
br label %29
28: ; preds = %3
br label %29
29: ; preds = %28, %27
store i32 0, i32* %4
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %4
ret i32 %31
}

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