#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;
  short int port = (55005);
  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
movw   $0xd6dd,-0x6(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x100000,-0x24(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11f7 <create_server+0x67>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%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    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%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    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d30(%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    12f0 <create_server+0x160>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%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    1326 <create_server+0x196>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%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   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x100000,(%rsp)
mov    0x2e37(%rip),%r15
mov    (%r15),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     12ac <create_server+0x11c>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2e13(%rip),%r12
mov    (%r12),%esi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
mov    (%r12),%esi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    $0x4,%r8d
mov    %ebx,%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <setsockopt@plt>
movl   $0x100000,(%rsp)
mov    (%r12),%esi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%r8d
mov    %ebx,%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <setsockopt@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0xffffd6dd,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     12be <create_server+0x12e>
mov    %ebx,%edi
mov    $0xa,%esi
call   1080 <listen@plt>
test   %rax,%rax
js     12d0 <create_server+0x140>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
jmp    12e0 <create_server+0x150>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
jmp    12e0 <create_server+0x150>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%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 }
@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
store i16 -10531, i16* %2
store i32 1, i32* %4
store i32 0, i32* %5
store i32 1048576, i32* %6
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
store i32 1, i32* %4
%16 = load i32, i32* %1
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %16, i32 %17, i32 %18, i32* %4, i64 4)
%20 = load i32, i32* %1
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_SNDBUF
%23 = bitcast i32* %6 to i8*
%24 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %20, i32 %21, i32 %22, i8* %23, i64 4)
store i32 %24, i32* %5
store i32 1048576, i32* %6
%25 = load i32, i32* %1
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_RCVBUF
%28 = bitcast i32* %6 to i8*
%29 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %25, i32 %26, i32 %27, i8* %28, i64 4)
store i32 %29, i32* %5
%30 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i16, i16* %2
%38 = call i32 @htons(i16 signext %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* %1
%41 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%42 = call i64 @bind(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %15
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %15
%49 = load i32, i32* %1
%50 = call i64 @listen(i32 %49, i32 10)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %48
%57 = load i32, i32* %1
ret i32 %57
}

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
@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 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 1048576, i32* %3
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
store i32 1, i32* %2
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_REUSEADDR
%18 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %9, i32 %16, i32 %17, i32* %2, i64 4)
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_SNDBUF
%21 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %9, i32 %19, i32 %20, i32* %3, i64 4)
store i32 1048576, i32* %3
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_RCVBUF
%24 = call i32 (i32, i32, i32, ...) @setsockopt(i32 %9, i32 %22, i32 %23, i32* %3, i64 4)
%25 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = call i32 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = call i32 @htons(i16 signext -10531)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%34 = call i64 @bind(i32 %9, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %15
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %15
%41 = call i64 @listen(i32 %9, i32 10)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %40
ret i32 %9
}