#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, short);
int /*<<< orphan*/ htonl(unsigned int);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void setup_receive(int usd, unsigned int interface, short port) {
  struct sockaddr_in sa_rcvr;
  memset(&sa_rcvr, 0, 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) {
    perror("bind");
    fprintf(stderr, "could not bind to udp port %d\n", port);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<setup_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
movswl -0xa(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1201 <setup_receive+0x91>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
movswl -0xa(%rbp),%edx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
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,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1040 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     11d8 <setup_receive+0x68>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe21(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
movswl %r14w,%edx
lea    0xe0d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <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
@.str = [5 x i8] c"bind\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"could not bind to udp port %d\0A\00"
define void @setup_receive(i32 %0, i32 %1, i16 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i32 %1, i32* %5
store i16 %2, i16* %6
%8 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* %5
%12 = call i32 @htonl(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = load i16, i16* %6
%16 = call i32 @htons(i16 signext %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %4
%19 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%20 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %3
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i16, i16* %6
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i16 signext %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %3
ret void
}

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
@.str = [5 x i8] c"bind\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"could not bind to udp port %d\0A\00"
define void @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 @memset(%struct.sockaddr_in* %4, i32 0, 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 = 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 = 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 %21
16: ; preds = %3
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i16 signext %2)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
ret void
}