#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ temp;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int FXNewServerSocket(int port, int maxConnections) {
  int sock, error;
  struct sockaddr_in temp;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  temp.sin_family = AF_INET;
  temp.sin_addr.s_addr = INADDR_ANY;
  temp.sin_port = htons(port);
  error = fcntl(sock, F_SETFL, O_NONBLOCK);
  error = bind(sock, (struct sockaddr *)&temp, sizeof(temp));
  if (maxConnections) {
    error = listen(sock, maxConnections);
  }
  return sock;
}


x86 assembly (clang, -O0):
<FXNewServerSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11e6 <FXNewServerSocket+0x96>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <listen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FXNewServerSocket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
mov    0x2e82(%rip),%r15
mov    (%r15),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
test   %r14d,%r14d
je     11d3 <FXNewServerSocket+0x83>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <listen@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @FXNewServerSocket(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = load i32, i32* %3
%17 = call i32 @htons(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* %5
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* @O_NONBLOCK
%22 = call i32 @fcntl(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %5
%24 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
store i32 %25, i32* %6
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %2
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = call i32 @listen(i32 %29, i32 %30)
store i32 %31, i32* %6
br label %32
32: ; preds = %28, %2
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @FXNewServerSocket(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 %0)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* @O_NONBLOCK
%16 = tail call i32 @fcntl(i32 %7, i32 %14, i32 %15)
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @bind(i32 %7, %struct.sockaddr* %17, i32 12)
%19 = icmp eq i32 %1, 0
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = call i32 @listen(i32 %7, i32 %1)
br label %22
22: ; preds = %20, %2
ret i32 %7
}