#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ reuse_optval;
typedef int /*<<< orphan*/ myaddr;
typedef int /*<<< orphan*/ desired_rcv_buf_size;
typedef int /*<<< orphan*/ actual_rcv_buf_bytes;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              size_t *, unsigned int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, size_t);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int setupUDPSocketAndReturnFD() {
  int fd;
  struct sockaddr_in myaddr;
  int reuse_optval;
  unsigned int actual_rcv_buf_bytes_size;
  size_t desired_rcv_buf_size, actual_rcv_buf_bytes = 0;
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "ERROR CANNOT OPEN UDP SOCKET\n");
    exit(1);
  }
  reuse_optval = 1;
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_optval,
                 sizeof(reuse_optval)) != 0) {
    fprintf(stderr, "ERROR: Unable to set UDP socket to reuse\n");
  }
  desired_rcv_buf_size = (64 * 1024 * 1024);
  actual_rcv_buf_bytes_size = sizeof(actual_rcv_buf_bytes);
  setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &desired_rcv_buf_size,
             sizeof(desired_rcv_buf_size));
  getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &actual_rcv_buf_bytes,
             &actual_rcv_buf_bytes_size);
  printf("Setting up UDP socket RCVBUF size = %lu bytes\n",
         actual_rcv_buf_bytes);
  memset(&myaddr, 0, sizeof(struct sockaddr_in));
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  myaddr.sin_port = htons(4447);
  if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
    fprintf(stderr, "ERROR, CANNOT BIND UDP\n");
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<setupUDPSocketAndReturnFD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x28(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11f4 <setupUDPSocketAndReturnFD+0x54>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1240 <setupUDPSocketAndReturnFD+0xa0>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1090 <fprintf@plt>
movq   $0x4000000,-0x20(%rbp)
04
movl   $0x8,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    0x2d5e(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x8,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1080 <getsockopt@plt>
mov    -0x28(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x115f,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    131b <setupUDPSocketAndReturnFD+0x17b>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupUDPSocketAndReturnFD>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e25(%rip),%r15
mov    (%r15),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12d7 <setupUDPSocketAndReturnFD+0x137>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2e01(%rip),%r14
mov    (%r14),%esi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
je     1221 <setupUDPSocketAndReturnFD+0x81>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1090 <fprintf@plt>
movq   $0x4000000,0x20(%rsp)
movl   $0x8,(%rsp)
mov    (%r14),%esi
mov    0x2d85(%rip),%r12
mov    (%r12),%edx
lea    0x20(%rsp),%rcx
mov    $0x8,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
mov    (%r14),%esi
mov    (%r12),%edx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edi
call   1080 <getsockopt@plt>
mov    0x8(%rsp),%rsi
lea    0xdd3(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x115f,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
js     12e9 <setupUDPSocketAndReturnFD+0x149>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
jmp    12f9 <setupUDPSocketAndReturnFD+0x159>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"ERROR CANNOT OPEN UDP SOCKET\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [42 x i8] c"ERROR: Unable to set UDP socket to reuse\0A\00"
@SO_RCVBUF = global i32 0
@.str.2 = [47 x i8] c"Setting up UDP socket RCVBUF size = %lu bytes\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [24 x i8] c"ERROR, CANNOT BIND UDP\0A\00"
define i32 @setupUDPSocketAndReturnFD() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i64 0, i64* %6
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
store i32 1, i32* %3
%16 = load i32, i32* %1
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %16, i32 %17, i32 %18, i32* %3, i64 4)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %15
store i64 67108864, i64* %5
store i32 8, i32* %4
%25 = load i32, i32* %1
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_RCVBUF
%28 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %25, i32 %26, i32 %27, i64* %5, i64 8)
%29 = load i32, i32* %1
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_RCVBUF
%32 = call i32 @getsockopt(i32 %29, i32 %30, i32 %31, i64* %6, i32* %4)
%33 = load i64, i64* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = call i32 @htonl(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i32 %39, i32* %41
%42 = call i32 @htons(i32 4447)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* %1
%45 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%46 = call i64 @bind(i32 %44, %struct.sockaddr* %45, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %24
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %24
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"ERROR CANNOT OPEN UDP SOCKET\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [42 x i8] c"ERROR: Unable to set UDP socket to reuse\0A\00"
@SO_RCVBUF = global i32 0
@.str.2 = [47 x i8] c"Setting up UDP socket RCVBUF size = %lu bytes\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [24 x i8] c"ERROR, CANNOT BIND UDP\0A\00"
define i32 @setupUDPSocketAndReturnFD() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %0
store i32 1, i32* %2
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_REUSEADDR
%22 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %13, i32 %20, i32 %21, i32* %2, i64 4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %24, %19
store i64 67108864, i64* %4
store i32 8, i32* %3
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_RCVBUF
%30 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %13, i32 %28, i32 %29, i64* %4, i64 8)
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_RCVBUF
%33 = call i32 @getsockopt(i32 %13, i32 %31, i32 %32, i64* %5, i32* %3)
%34 = load i64, i64* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i64 %34)
%36 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* @INADDR_ANY
%40 = call i32 @htonl(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %40, i32* %41
%42 = call i32 @htons(i32 4447)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %42, i32* %43
%44 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%45 = call i64 @bind(i32 %13, %struct.sockaddr* %44, i32 12)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %27
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %27
ret i32 %13
}