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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, short);
int /*<<< orphan*/ htonl(unsigned int);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int setup_receive(int usd, unsigned int interface, short port) {
  struct sockaddr_in sa_rcvr;
  bzero((char *)&sa_rcvr, sizeof(sa_rcvr));
  sa_rcvr.sin_family = AF_INET;
  sa_rcvr.sin_addr.s_addr = htonl(interface);
  sa_rcvr.sin_port = htons(port);
  if (bind(usd, (struct sockaddr *)&sa_rcvr, sizeof(sa_rcvr)) == -1) {
    fprintf(stderr, "Could not bind to udp port %d\n", port);
    perror("bind");
    return 0;
  }
  listen(usd, 3);
  return 1;
}


x86 assembly (clang, -O0):
<setup_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x1c(%rbp)
movswl -0xe(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1201 <setup_receive+0x91>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
movswl -0xe(%rbp),%edx
call   1050 <fprintf@plt>
lea    0xe2f(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1215 <setup_receive+0xa5>
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1060 <listen@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_receive>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     11e7 <setup_receive+0x77>
mov    %ebp,%edi
mov    $0x3,%esi
call   1060 <listen@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
movswl %r14w,%edx
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
jmp    11dc <setup_receive+0x6c>

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
@stderr = global i32 0
@.str = [31 x i8] c"Could not bind to udp port %d\0A\00"
@.str.1 = [5 x i8] c"bind\00"
define i32 @setup_receive(i32 %0, i32 %1, i16 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %5
store i32 %1, i32* %6
store i16 %2, i16* %7
%9 = bitcast %struct.sockaddr_in* %8 to i8*
%10 = call i32 @bzero(i8* %9, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* %6
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i16, i16* %7
%18 = call i32 @htons(i16 signext %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %5
%21 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = load i16, i16* %7
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i16 signext %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %32
29: ; preds = %3
%30 = load i32, i32* %5
%31 = call i32 @listen(i32 %30, i32 3)
store i32 1, i32* %4
br label %32
32: ; preds = %29, %24
%33 = load i32, i32* %4
ret i32 %33
}

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
@stderr = global i32 0
@.str = [31 x i8] c"Could not bind to udp port %d\0A\00"
@.str.1 = [5 x i8] c"bind\00"
define i32 @setup_receive(i32 %0, i32 %1, i16 signext %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = call i32 @bzero(i8* %5, i32 12)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @htonl(i32 %1)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @htons(i16 signext %2)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %11, i32* %12
%13 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%14 = call i32 @bind(i32 %0, %struct.sockaddr* %13, i32 12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i16 signext %2)
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %3
%21 = call i32 @listen(i32 %0, i32 3)
br label %22
22: ; preds = %20, %16
%23 = phi i32 [ 0, %16 ], [ 1, %20 ]
ret i32 %23
}