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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int /*<<< orphan*/, struct sockaddr *, int /*<<< orphan*/);
int listen(int /*<<< orphan*/, int);
int /*<<< orphan*/ neubot_info(char *);
int /*<<< orphan*/ neubot_warn(char *);
int setsockopt(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *, int);
int neubot_socket_listen(evutil_socket_t filedesc,
                         struct sockaddr_storage *storage, socklen_t salen) {
  int result, activate;
  neubot_info("utils:neubot_socket_listen - enter");
  activate = 1;
  result = setsockopt(filedesc, SOL_SOCKET, SO_REUSEADDR, &activate,
                      sizeof(activate));
  if (result != 0) {
    neubot_warn("utils:neubot_socket_listen - setsockopt() failed");
    return (-1);
  }
  result = bind(filedesc, (struct sockaddr *)storage, salen);
  if (result != 0) {
    neubot_warn("utils:neubot_socket_listen - bind() failed");
    return (-1);
  }
  result = listen(filedesc, 10);
  if (result != 0) {
    neubot_warn("utils:neubot_socket_listen - listen() failed");
    return (-1);
  }
  neubot_info("utils:neubot_socket_listen - ok");
  return (0);
}


x86 assembly (clang, -O0):
<neubot_socket_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe97(%rip),%rdi
call   1060 <neubot_info@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11be <neubot_socket_listen+0x6e>
lea    0xe76(%rip),%rdi
call   1070 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <neubot_socket_listen+0xe7>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <bind@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f2 <neubot_socket_listen+0xa2>
lea    0xe73(%rip),%rdi
call   1070 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <neubot_socket_listen+0xe7>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1040 <listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1224 <neubot_socket_listen+0xd4>
lea    0xe6c(%rip),%rdi
call   1070 <neubot_warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <neubot_socket_listen+0xe7>
lea    0xe81(%rip),%rdi
call   1060 <neubot_info@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neubot_socket_listen>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe99(%rip),%rdi
call   1060 <neubot_info@plt>
movl   $0x1,0xc(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
je     11a5 <neubot_socket_listen+0x55>
lea    0xe80(%rip),%rdi
jmp    11d6 <neubot_socket_listen+0x86>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <bind@plt>
test   %eax,%eax
je     11bf <neubot_socket_listen+0x6f>
lea    0xe97(%rip),%rdi
jmp    11d6 <neubot_socket_listen+0x86>
mov    %ebx,%edi
mov    $0xa,%esi
call   1040 <listen@plt>
test   %eax,%eax
je     11e9 <neubot_socket_listen+0x99>
lea    0xea9(%rip),%rdi
call   1070 <neubot_warn@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xebc(%rip),%rdi
call   1060 <neubot_info@plt>
xor    %eax,%eax
jmp    11e0 <neubot_socket_listen+0x90>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"utils:neubot_socket_listen - enter\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [49 x i8] c"utils:neubot_socket_listen - setsockopt() failed\00"
@.str.2 = [43 x i8] c"utils:neubot_socket_listen - bind() failed\00"
@.str.3 = [45 x i8] c"utils:neubot_socket_listen - listen() failed\00"
@.str.4 = [32 x i8] c"utils:neubot_socket_listen - ok\00"
define i32 @neubot_socket_listen(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
%9 = alloca i32
store i32 %0, i32* %5
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %6
store i32 %2, i32* %7
%10 = call i32 @neubot_info(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %9
%11 = load i32, i32* %5
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_REUSEADDR
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %9, i32 4)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @neubot_warn(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %38
19: ; preds = %3
%20 = load i32, i32* %5
%21 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %6
%22 = bitcast %struct.sockaddr_storage* %21 to %struct.sockaddr*
%23 = load i32, i32* %7
%24 = call i32 @bind(i32 %20, %struct.sockaddr* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @neubot_warn(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %38
29: ; preds = %19
%30 = load i32, i32* %5
%31 = call i32 @listen(i32 %30, i32 10)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @neubot_warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %38
36: ; preds = %29
%37 = call i32 @neubot_info(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %38
38: ; preds = %36, %34, %27, %17
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"utils:neubot_socket_listen - enter\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [49 x i8] c"utils:neubot_socket_listen - setsockopt() failed\00"
@.str.2 = [43 x i8] c"utils:neubot_socket_listen - bind() failed\00"
@.str.3 = [45 x i8] c"utils:neubot_socket_listen - listen() failed\00"
@.str.4 = [32 x i8] c"utils:neubot_socket_listen - ok\00"
define i32 @neubot_socket_listen(i32 %0, %struct.sockaddr_storage* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @neubot_info(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_REUSEADDR
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, i32* %4, i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 @neubot_warn(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %26
13: ; preds = %3
%14 = bitcast %struct.sockaddr_storage* %1 to %struct.sockaddr*
%15 = call i32 @bind(i32 %0, %struct.sockaddr* %14, i32 %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @neubot_warn(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %26
19: ; preds = %13
%20 = call i32 @listen(i32 %0, i32 10)
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @neubot_warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %26
24: ; preds = %19
%25 = call i32 @neubot_info(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %22, %17, %11
%27 = phi i32 [ -1, %11 ], [ -1, %17 ], [ -1, %22 ], [ 0, %24 ]
ret i32 %27
}