#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int open_listener(int *listener) {
  struct sockaddr_in addr = {.sin_family = AF_INET,
                             .sin_port = htons(2121),
                             .sin_addr.s_addr = INADDR_ANY};
  *listener = socket(AF_INET, SOCK_DGRAM, 0);
  if (listener < 0) {
    return -1;
  }
  if (bind(*listener, (struct sockaddr *)&addr, sizeof(addr))) {
    return -1;
  }
  printf("UDP dash listener started\n");
  return 0;
}


x86 assembly (clang, -O0):
<open_listener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x849,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
jae    11a9 <open_listener+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <open_listener+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
je     11d3 <open_listener+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <open_listener+0xa6>
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_listener>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    $0x849,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,(%rbx)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1050 <bind@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11ab <open_listener+0x6b>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [27 x i8] c"UDP dash listener started\0A\00"
define i32 @open_listener(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.sockaddr_in
store i32* %0, i32** %3
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%6 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %5, i32 0, i32 0
%7 = load i32, i32* @INADDR_ANY
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%9 = call i32 @htons(i32 2121)
store i32 %9, i32* %8
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
%11 = load i32, i32* @AF_INET
store i32 %11, i32* %10
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = load i32*, i32** %3
store i32 %14, i32* %15
%16 = load i32*, i32** %3
%17 = icmp ult i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 -1, i32* %2
br label %28
19: ; preds = %1
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%23 = call i64 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 -1, i32* %2
br label %28
26: ; preds = %19
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %28
28: ; preds = %26, %25, %18
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@str = [26 x i8] c"UDP dash listener started\00"
define i32 @open_listener(i32* nocapture writeonly %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
%5 = load i32, i32* @INADDR_ANY
store i32 %5, i32* %4
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%7 = tail call i32 @htons(i32 2121)
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%9 = load i32, i32* @AF_INET
store i32 %9, i32* %8
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %0
%12 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%13 = call i64 @bind(i32 %11, %struct.sockaddr* %12, i32 12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %1, %15
%18 = phi i32 [ 0, %15 ], [ -1, %1 ]
ret i32 %18
}