#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 scalar_t__ evutil_socket_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
scalar_t__ connect(scalar_t__, struct sockaddr const *, int);
scalar_t__ evutil_parse_sockaddr_port(char *, struct sockaddr *, int *);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
evutil_socket_t create_connectfd() {
  struct sockaddr_in servaddr;
  int addrlen = sizeof(servaddr);
  evutil_socket_t connectfd;
  assert(evutil_parse_sockaddr_port(
             "127.0.0.1:30003", (struct sockaddr *)&servaddr, &addrlen) == 0);
  assert(addrlen == (int)sizeof(servaddr));
  connectfd = socket(AF_INET, SOCK_STREAM, 0);
  assert(connectfd >= 0);
  assert(connect(connectfd, (const struct sockaddr *)&servaddr, addrlen) == 0);
  return connectfd;
}


x86 assembly (clang, -O0):
<create_connectfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x4,-0xc(%rbp)
lea    -0x8(%rbp),%rsi
lea    0xea6(%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    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_connectfd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x4,0xc(%rsp)
lea    0xeaa(%rip),%rdi
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%rdx
mov    %r14,%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    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1040 <assert@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <connect@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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
define i64 @create_connectfd() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i64
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 i64 @socket(i32 %13, i32 %14, i32 0)
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp sge i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i64, i64* %3
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = load i32, i32* %2
%23 = call i64 @connect(i64 %20, %struct.sockaddr* %21, i32 %22)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i64, i64* %3
ret i64 %27
}

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
define i64 @create_connectfd() {
%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 i64 @socket(i32 %14, i32 %15, i32 0)
%17 = lshr i64 %16, 63
%18 = trunc i64 %17 to i32
%19 = xor i32 %18, 1
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %2
%22 = call i64 @connect(i64 %16, %struct.sockaddr* %5, i32 %21)
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
ret i64 %16
}