#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ serv_loop(int *);
scalar_t__ setup_serv_con(int *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int listen_sock_fd = 0;
  int port = 0;
  if (argc != 1) {
    fprintf(stderr, "Syntax: server\n");
    exit(EXIT_FAILURE);
  }
  port = 15001;
  if ((setup_serv_con(&listen_sock_fd, &port)) < 0)
    exit(EXIT_FAILURE);
  if (listen(listen_sock_fd, 10) == -1) {
    perror("listen");
    exit(EXIT_FAILURE);
  }
  printf("server: waiting for connections...\n");
  serv_loop(&listen_sock_fd);
  close(listen_sock_fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11d1 <main+0x51>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x3a99,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <setup_serv_con@plt>
cmp    $0x0,%rax
jge    11fd <main+0x7d>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    122d <main+0xad>
lea    0xdf6(%rip),%rdi
call   1090 <perror@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1040 <serv_loop@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x0,(%rsp)
cmp    $0x1,%edi
jne    11c7 <main+0x47>
movl   $0x3a99,0x4(%rsp)
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   1050 <setup_serv_con@plt>
test   %rax,%rax
js     11dc <main+0x5c>
mov    (%rsp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    11ea <main+0x6a>
lea    0xe50(%rip),%rdi
call   1090 <perror@plt>
jmp    11dc <main+0x5c>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <serv_loop@plt>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Syntax: server\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@.str.2 = [36 x i8] c"server: waiting for connections...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
store i32 15001, i32* %7
%16 = call i64 @setup_serv_con(i32* %6, i32* %7)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %15
%22 = load i32, i32* %6
%23 = call i32 @listen(i32 %22, i32 10)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %21
%30 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @serv_loop(i32* %6)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Syntax: server\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@EXIT_SUCCESS = global i32 0
@str = [35 x i8] c"server: waiting for connections...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 1
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
store i32 15001, i32* %4
%14 = call i64 @setup_serv_con(i32* %3, i32* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %13
%20 = load i32, i32* %3
%21 = call i32 @listen(i32 %20, i32 10)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%29 = call i32 @serv_loop(i32* %3)
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
%33 = call i32 @exit(i32 %32)
unreachable
}