#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 u_long;

/* Variables and functions */
int /*<<< orphan*/ FIONBIO;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ WINS_ErrorMessage(int /*<<< orphan*/);
int /*<<< orphan*/ WSAGetLastError();
int /*<<< orphan*/ WinPrint(char *, int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, int *);
int listen(int, int /*<<< orphan*/);
int WINS_Listen(int socket) {
  u_long _true = 1;
  if (ioctl(socket, FIONBIO, &_true) == -1) {
    WinPrint("WINS_Listen: %s\n", WINS_ErrorMessage(WSAGetLastError()));
    return -1;
  }
  if (listen(socket, SOMAXCONN) == -1) {
    WinPrint("WINS_Listen: %s\n", WINS_ErrorMessage(WSAGetLastError()));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<WINS_Listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11a8 <WINS_Listen+0x58>
mov    $0x0,%al
call   1070 <WSAGetLastError@plt>
mov    %eax,%edi
call   1030 <WINS_ErrorMessage@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
call   1050 <WinPrint@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <WINS_Listen+0xa1>
mov    -0x8(%rbp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    11ea <WINS_Listen+0x9a>
mov    $0x0,%al
call   1070 <WSAGetLastError@plt>
mov    %eax,%edi
call   1030 <WINS_ErrorMessage@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
call   1050 <WinPrint@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <WINS_Listen+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WINS_Listen>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1190 <WINS_Listen+0x40>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <listen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11b1 <WINS_Listen+0x61>
xor    %eax,%eax
call   1070 <WSAGetLastError@plt>
mov    %eax,%edi
call   1030 <WINS_ErrorMessage@plt>
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
call   1050 <WinPrint@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@FIONBIO = global i32 0
@.str = [17 x i8] c"WINS_Listen: %s\0A\00"
@SOMAXCONN = global i32 0
define i32 @WINS_Listen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @FIONBIO
%7 = call i32 @ioctl(i32 %5, i32 %6, i32* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = call i32 (...) @WSAGetLastError()
%11 = call i32 @WINS_ErrorMessage(i32 %10)
%12 = call i32 @WinPrint(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %23
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @SOMAXCONN
%16 = call i32 @listen(i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 (...) @WSAGetLastError()
%20 = call i32 @WINS_ErrorMessage(i32 %19)
%21 = call i32 @WinPrint(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 -1, i32* %2
br label %23
22: ; preds = %13
store i32 0, i32* %2
br label %23
23: ; preds = %22, %18, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@FIONBIO = global i32 0
@.str = [17 x i8] c"WINS_Listen: %s\0A\00"
@SOMAXCONN = global i32 0
define i32 @WINS_Listen(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = load i32, i32* @FIONBIO
%5 = call i32 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @SOMAXCONN
%9 = call i32 @listen(i32 %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %7, %1
%12 = call i32 (...) @WSAGetLastError()
%13 = call i32 @WINS_ErrorMessage(i32 %12)
%14 = call i32 @WinPrint(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ 0, %7 ], [ -1, %11 ]
ret i32 %16
}