#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 */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ evutil_socket_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ assert(int);
scalar_t__ bind(int /*<<< orphan*/, struct sockaddr *, int);
scalar_t__ evutil_make_listen_socket_reuseable(int /*<<< orphan*/);
scalar_t__ evutil_parse_sockaddr_port(char *, struct sockaddr *, int *);
scalar_t__ listen(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ socket(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
evutil_socket_t create_listenfd() {
  struct sockaddr_in servaddr;
  int addr_len = (int)sizeof(servaddr);
  evutil_socket_t listenfd;
  assert(evutil_parse_sockaddr_port(
             "127.0.0.1:30003", (struct sockaddr *)&servaddr, &addr_len) == 0);
  assert(addr_len == (int)sizeof(servaddr));
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  assert(evutil_make_listen_socket_reuseable(listenfd) == 0);
  assert(bind(listenfd, (struct sockaddr *)&servaddr, addr_len) == 0);
  assert(listen(listenfd, SOMAXCONN) == 0);
  return listenfd;
}


x86 assembly (clang, -O0):
<create_listenfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x4,-0xc(%rbp)
lea    -0x8(%rbp),%rsi
lea    0xe86(%rip),%rdi
lea    -0xc(%rbp),%rdx
call   1030 <evutil_parse_sockaddr_port@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x4,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <evutil_make_listen_socket_reuseable@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
call   1050 <listen@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_listenfd>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movl   $0x4,0xc(%rsp)
lea    0xe8b(%rip),%rdi
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <evutil_parse_sockaddr_port@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0x4,0xc(%rsp)
sete   %dil
call   1040 <assert@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <evutil_make_listen_socket_reuseable@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <bind@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <listen@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"127.0.0.1:30003\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOMAXCONN = global i32 0
define i32 @create_listenfd() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
store i32 4, i32* %2
%4 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%5 = call i64 @evutil_parse_sockaddr_port(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.sockaddr* %4, i32* %2)
%6 = icmp eq i64 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 4
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i64 @evutil_make_listen_socket_reuseable(i32 %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %3
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = load i32, i32* %2
%24 = call i64 @bind(i32 %21, %struct.sockaddr* %22, i32 %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* %3
%29 = load i32, i32* @SOMAXCONN
%30 = call i64 @listen(i32 %28, i32 %29)
%31 = icmp eq i64 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"127.0.0.1:30003\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOMAXCONN = global i32 0
define i32 @create_listenfd() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%5 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%6 = call i64 @evutil_parse_sockaddr_port(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.sockaddr* %5, i32* %2)
%7 = icmp eq i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 4
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = call i64 @evutil_make_listen_socket_reuseable(i32 %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %2
%22 = call i64 @bind(i32 %16, %struct.sockaddr* %5, i32 %21)
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* @SOMAXCONN
%27 = call i64 @listen(i32 %16, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
ret i32 %16
}