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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int BasSockUdpAlloc(void) {
  int fd;
  int val;
  int res;
  fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (fd < 0)
    return -1;
  val = 0xffff;
  res = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, sizeof(val));
  res = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, sizeof(val));
  return fd;
}


x86 assembly (clang, -O0):
<BasSockUdpAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1161 <BasSockUdpAlloc+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <BasSockUdpAlloc+0x9c>
movl   $0xffff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasSockUdpAlloc>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
call   1040 <socket@plt>
test   %eax,%eax
js     119d <BasSockUdpAlloc+0x7d>
mov    %eax,%ebx
movl   $0xffff,0xc(%rsp)
mov    0x2e8a(%rip),%r15
mov    (%r15),%esi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r15),%esi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
jmp    11a2 <BasSockUdpAlloc+0x82>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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