#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 */
typedef int evutil_socket_t;

/* Variables and functions */
int /*<<< orphan*/ evutil_closesocket(int);
int evutil_make_socket_nonblocking(int);
int /*<<< orphan*/ neubot_info(char *);
int /*<<< orphan*/ neubot_warn(char *);
int socket(int, int, int);
evutil_socket_t neubot_socket_create(int domain, int type, int protocol) {
  evutil_socket_t filedesc;
  int result;
  neubot_info("utils:neubot_socket - enter");
  filedesc = socket(domain, type, protocol);
  if (filedesc == -1) {
    neubot_warn("utils:neubot_socket: cannot create socket");
    return (-1);
  }
  result = evutil_make_socket_nonblocking(filedesc);
  if (result != 0) {
    neubot_warn("utils:neubot_socket: cannot make nonblocking");
    (void)evutil_closesocket(filedesc);
    return (-1);
  }
  neubot_info("utils:neubot_socket - ok");
  return (filedesc);
}


x86 assembly (clang, -O0):
<neubot_socket_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe98(%rip),%rdi
call   1040 <neubot_info@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a0 <neubot_socket_create+0x50>
lea    0xe8d(%rip),%rdi
call   1060 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <neubot_socket_create+0x97>
mov    -0x14(%rbp),%edi
call   1050 <evutil_make_socket_nonblocking@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11d5 <neubot_socket_create+0x85>
lea    0xe8a(%rip),%rdi
call   1060 <neubot_warn@plt>
mov    -0x14(%rbp),%edi
call   1030 <evutil_closesocket@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <neubot_socket_create+0x97>
lea    0xe97(%rip),%rdi
call   1040 <neubot_info@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neubot_socket_create>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xe9e(%rip),%rdi
call   1040 <neubot_info@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     119f <neubot_socket_create+0x4f>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <evutil_make_socket_nonblocking@plt>
test   %eax,%eax
je     11b2 <neubot_socket_create+0x62>
lea    0xeba(%rip),%rdi
call   1060 <neubot_warn@plt>
mov    %ebx,%edi
call   1030 <evutil_closesocket@plt>
mov    $0xffffffff,%ebx
jmp    11be <neubot_socket_create+0x6e>
lea    0xe76(%rip),%rdi
call   1060 <neubot_warn@plt>
mov    $0xffffffff,%ebx
jmp    11be <neubot_socket_create+0x6e>
lea    0xeba(%rip),%rdi
call   1040 <neubot_info@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"utils:neubot_socket - enter\00"
@.str.1 = [42 x i8] c"utils:neubot_socket: cannot create socket\00"
@.str.2 = [45 x i8] c"utils:neubot_socket: cannot make nonblocking\00"
@.str.3 = [25 x i8] c"utils:neubot_socket - ok\00"
define i32 @neubot_socket_create(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = call i32 @neubot_info(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @neubot_warn(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %31
19: ; preds = %3
%20 = load i32, i32* %8
%21 = call i32 @evutil_make_socket_nonblocking(i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 @neubot_warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %8
%27 = call i32 @evutil_closesocket(i32 %26)
store i32 -1, i32* %4
br label %31
28: ; preds = %19
%29 = call i32 @neubot_info(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* %8
store i32 %30, i32* %4
br label %31
31: ; preds = %28, %24, %17
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [28 x i8] c"utils:neubot_socket - enter\00"
@.str.1 = [42 x i8] c"utils:neubot_socket: cannot create socket\00"
@.str.2 = [45 x i8] c"utils:neubot_socket: cannot make nonblocking\00"
@.str.3 = [25 x i8] c"utils:neubot_socket - ok\00"
define i32 @neubot_socket_create(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @neubot_info(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @neubot_warn(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %17
9: ; preds = %3
%10 = tail call i32 @evutil_make_socket_nonblocking(i32 %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @neubot_warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @evutil_closesocket(i32 %5)
br label %17
15: ; preds = %9
%16 = tail call i32 @neubot_info(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %12, %7
%18 = phi i32 [ -1, %7 ], [ -1, %12 ], [ %5, %15 ]
ret i32 %18
}