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

/* Variables and functions */
scalar_t__ EINPROGRESS;
int connect(int /*<<< orphan*/, struct sockaddr *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ neubot_info(char *);
int /*<<< orphan*/ neubot_warn(char *);
int neubot_socket_connect(evutil_socket_t filedesc,
                          struct sockaddr_storage *storage, socklen_t salen) {
  int result;
  neubot_info("utils:neubot_socket_connect - enter");
  result = connect(filedesc, (struct sockaddr *)storage, salen);
  if (result != 0) {
    if (errno == EINPROGRESS)
      goto looksgood;
    neubot_warn("utils:neubot_socket_connect - connect() failed");
    return (-1);
  }
looksgood:
  neubot_info("utils:neubot_socket_connect - ok");
  return (0);
}


x86 assembly (clang, -O0):
<neubot_socket_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <neubot_info@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a1 <neubot_socket_connect+0x71>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <neubot_socket_connect+0x59>
jmp    11a6 <neubot_socket_connect+0x76>
lea    0xe94(%rip),%rdi
call   1050 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <neubot_socket_connect+0x89>
jmp    11a6 <neubot_socket_connect+0x76>
lea    0xea6(%rip),%rdi
call   1030 <neubot_info@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neubot_socket_connect>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xebd(%rip),%rdi
call   1030 <neubot_info@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <connect@plt>
test   %eax,%eax
je     116f <neubot_socket_connect+0x3f>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    117f <neubot_socket_connect+0x4f>
lea    0xedd(%rip),%rdi
call   1030 <neubot_info@plt>
xor    %eax,%eax
jmp    1190 <neubot_socket_connect+0x60>
lea    0xe9e(%rip),%rdi
call   1050 <neubot_warn@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"utils:neubot_socket_connect - enter\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.1 = [47 x i8] c"utils:neubot_socket_connect - connect() failed\00"
@.str.2 = [33 x i8] c"utils:neubot_socket_connect - ok\00"
define i32 @neubot_socket_connect(i32 %0, %struct.sockaddr_storage* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %6
store i32 %2, i32* %7
%9 = call i32 @neubot_info(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %5
%11 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%12 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%13 = load i32, i32* %7
%14 = call i32 @connect(i32 %10, %struct.sockaddr* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINPROGRESS
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
br label %25
22: ; preds = %17
%23 = call i32 @neubot_warn(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %27
24: ; preds = %3
br label %25
25: ; preds = %24, %21
%26 = call i32 @neubot_info(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"utils:neubot_socket_connect - enter\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.1 = [47 x i8] c"utils:neubot_socket_connect - connect() failed\00"
@.str.2 = [33 x i8] c"utils:neubot_socket_connect - ok\00"
define i32 @neubot_socket_connect(i32 %0, %struct.sockaddr_storage* %1, i32 %2) {
%4 = tail call i32 @neubot_info(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = bitcast %struct.sockaddr_storage* %1 to %struct.sockaddr*
%6 = tail call i32 @connect(i32 %0, %struct.sockaddr* %5, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINPROGRESS
%11 = icmp eq i64 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @neubot_warn(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %16
14: ; preds = %3, %8
%15 = tail call i32 @neubot_info(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ 0, %14 ], [ -1, %12 ]
ret i32 %17
}