#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 timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ error;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int is_listened(int socketfd) {
  int nRet = -1;
  if (socketfd > 0) {
    return 1;
    fd_set fdread;
    fd_set fderror;
    FD_ZERO(&fdread);
    FD_ZERO(&fderror);
    FD_SET(socketfd, &fdread);
    FD_SET(socketfd, &fderror);
    struct timeval tvSelect;
    tvSelect.tv_sec = 0;
    tvSelect.tv_usec = 1;
    int nSelectRet = select(socketfd + 1, &fdread, NULL, &fderror, &tvSelect);
    if (nSelectRet > 0) {
      if (FD_ISSET(socketfd, &fdread)) {
        int error = 0;
        int errlen = sizeof(error);
        getsockopt(socketfd, SOL_SOCKET, SO_ERROR, &error,
                   (socklen_t *)&errlen);
        if (0 == error) {
          nRet = 1;
        } else {
          printf("is_acceptable.select some error! error:%d\n", error);
          nRet = -5;
        }
      } else if (FD_ISSET(socketfd, &fderror)) {
        printf("is_acceptable.select with error fd!\n");
        nRet = -4;
      } else {
        printf("is_acceptable.select CANNOT understand!\n");
      }
    } else if (nSelectRet < 0) {
      printf("is_acceptable.select fail!\n");
      nRet = -3;
    } else if (nSelectRet == 0) {
      nRet = 0;
    }
  } else {
    printf("is_acceptable.select socketfd must be > 0!\n");
  }
  return nRet;
}


x86 assembly (clang, -O0):
<is_listened>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1138 <is_listened+0x28>
movl   $0x1,-0x4(%rbp)
jmp    114c <is_listened+0x3c>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_listened>:
mov    $0x1,%eax
test   %edi,%edi
jle    111a <is_listened+0xa>
ret
push   %rax
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [44 x i8] c"is_acceptable.select socketfd must be > 0!\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
define i32 @is_listened(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i32
store i32 %0, i32* %3
store i32 -1, i32* %4
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %16
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@str = [43 x i8] c"is_acceptable.select socketfd must be > 0!\00"
define i32 @is_listened(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %1, %3
%6 = phi i32 [ -1, %3 ], [ 1, %1 ]
ret i32 %6
}