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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SO_SNDBUF;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(short);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int create_server() {
  int list_s;
  extern short int serv_port;
  short int port = serv_port;
  struct sockaddr_in servaddr;
  int optval = 1;
  int ret = 0;
  int sndsize = 1024 * 1024;
  if ((list_s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "SERV: Error creating listening socket.\n");
    exit(-1);
  }
  optval = 1;
  setsockopt(list_s, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
  ret =
      setsockopt(list_s, SOL_SOCKET, SO_SNDBUF, (char *)&sndsize, sizeof(int));
  sndsize = 1024 * 1024;
  ret =
      setsockopt(list_s, SOL_SOCKET, SO_RCVBUF, (char *)&sndsize, sizeof(int));
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(port);
  if (bind(list_s, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    fprintf(stderr, "SERV: Error calling bind()\n");
    exit(-1);
  }
  if (listen(list_s, (10)) < 0) {
    fprintf(stderr, "SERV: Error calling listen()\n");
    exit(-1);
  }
  return list_s;
}


x86 assembly (clang, -O0):
<create_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e09(%rip),%rax
mov    (%rax),%ax
mov    %ax,-0x6(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x100000,-0x24(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11ff <create_server+0x6f>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    %eax,-0x20(%rbp)
movl   $0x100000,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x14(%rbp)
movswl -0x6(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    12f8 <create_server+0x168>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    132e <create_server+0x19e>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd25(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_server>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2e05(%rip),%rax
movzwl (%rax),%r12d
movl   $0x100000,0x8(%rsp)
mov    0x2e2a(%rip),%r15
mov    (%r15),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     12b9 <create_server+0x129>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2e06(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
mov    0x0(%rbp),%esi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%r14
mov    $0x4,%r8d
mov    %ebx,%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <setsockopt@plt>
movl   $0x100000,0x8(%rsp)
mov    0x0(%rbp),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%r8d
mov    %ebx,%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <setsockopt@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
movswl %r12w,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     12cb <create_server+0x13b>
mov    %ebx,%edi
mov    $0xa,%esi
call   1080 <listen@plt>
test   %rax,%rax
js     12dd <create_server+0x14d>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
jmp    12ed <create_server+0x15d>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
jmp    12ed <create_server+0x15d>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@serv_port = external global i16
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"SERV: Error creating listening socket.\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c"SERV: Error calling bind()\0A\00"
@.str.2 = [30 x i8] c"SERV: Error calling listen()\0A\00"
define i32 @create_server() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i16, i16* @serv_port
store i16 %7, i16* %2
store i32 1, i32* %4
store i32 0, i32* %5
store i32 1048576, i32* %6
%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* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
store i32 1, i32* %4
%17 = load i32, i32* %1
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %17, i32 %18, i32 %19, i32* %4, i64 4)
%21 = load i32, i32* %1
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_SNDBUF
%24 = bitcast i32* %6 to i8*
%25 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %21, i32 %22, i32 %23, i8* %24, i64 4)
store i32 %25, i32* %5
store i32 1048576, i32* %6
%26 = load i32, i32* %1
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_RCVBUF
%29 = bitcast i32* %6 to i8*
%30 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %26, i32 %27, i32 %28, i8* %29, i64 4)
store i32 %30, i32* %5
%31 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i16, i16* %2
%39 = call i32 @htons(i16 signext %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %1
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%43 = call i64 @bind(i32 %41, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %16
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %16
%50 = load i32, i32* %1
%51 = call i64 @listen(i32 %50, i32 10)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %49
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@serv_port = external global i16
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"SERV: Error creating listening socket.\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_SNDBUF = global i32 0
@SO_RCVBUF = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [28 x i8] c"SERV: Error calling bind()\0A\00"
@.str.2 = [30 x i8] c"SERV: Error calling listen()\0A\00"
define i32 @create_server() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = load i16, i16* @serv_port
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 1048576, i32* %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
store i32 1, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %10, i32 %17, i32 %18, i32* %2, i64 4)
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_SNDBUF
%22 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %10, i32 %20, i32 %21, i32* %3, i64 4)
store i32 1048576, i32* %3
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_RCVBUF
%25 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %10, i32 %23, i32 %24, i32* %3, i64 4)
%26 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %30, i32* %31
%32 = call i32 @htons(i16 signext %4)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%35 = call i64 @bind(i32 %10, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %16
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %16
%42 = call i64 @listen(i32 %10, i32 10)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %41
ret i32 %10
}