#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*/ server_address;
typedef int /*<<< orphan*/ i;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ TCP_NODELAY;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int create_server_socket() {
  int server_sockfd;
  struct sockaddr_in server_address;
  int i = 1;
  if ((server_sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Server: Unable to create server socket.");
    return -1;
  }
  memset(&server_address, 0, sizeof(server_address));
  server_address.sin_family = AF_INET;
  server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  server_address.sin_port = htons(4070);
  if (setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) ==
      -1) {
    perror("Server: Unable to inform kernel to reuse server socket.");
    return -1;
  }
  if (setsockopt(server_sockfd, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i)) ==
      -1) {
    perror("Server: Problem with TCP setting.");
    return -1;
  }
  if (bind(server_sockfd, (struct sockaddr *)&server_address,
           sizeof(server_address)) == -1) {
    perror("Server: Unable to bind socket to server.");
    return -1;
  }
  if (listen(server_sockfd, 10) == -1) {
    perror("Server: Unable to listen on server socket.");
    return -1;
  }
  return server_sockfd;
}


x86 assembly (clang, -O0):
<create_server_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x1c(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11cc <create_server_socket+0x4c>
lea    0xe45(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <create_server_socket+0x176>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    $0xfe6,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    124b <create_server_socket+0xcb>
lea    0xdee(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <create_server_socket+0x176>
mov    -0x8(%rbp),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1290 <create_server_socket+0x110>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <create_server_socket+0x176>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    12c2 <create_server_socket+0x142>
lea    0xdd1(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <create_server_socket+0x176>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    12f0 <create_server_socket+0x170>
lea    0xdcc(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <create_server_socket+0x176>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_server_socket>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x1,0x4(%rsp)
mov    0x2e42(%rip),%r14
mov    (%r14),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     126e <create_server_socket+0xee>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0xfe6,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1277 <create_server_socket+0xf7>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1280 <create_server_socket+0x100>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     1289 <create_server_socket+0x109>
mov    %ebx,%edi
mov    $0xa,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    129a <create_server_socket+0x11a>
lea    0xe3f(%rip),%rdi
jmp    1290 <create_server_socket+0x110>
lea    0xd8b(%rip),%rdi
jmp    1290 <create_server_socket+0x110>
lea    0xdaa(%rip),%rdi
jmp    1290 <create_server_socket+0x110>
lea    0xdd9(%rip),%rdi
jmp    1290 <create_server_socket+0x110>
lea    0xdf2(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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
@.str = [40 x i8] c"Server: Unable to create server socket.\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [56 x i8] c"Server: Unable to inform kernel to reuse server socket.\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.2 = [34 x i8] c"Server: Problem with TCP setting.\00"
@.str.3 = [41 x i8] c"Server: Unable to bind socket to server.\00"
@.str.4 = [43 x i8] c"Server: Unable to listen on server socket.\00"
define i32 @create_server_socket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
store i32 1, i32* %4
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %51
11: ; preds = %0
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 4070)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %4, i32 4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %11
%27 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %51
28: ; preds = %11
%29 = load i32, i32* %2
%30 = load i32, i32* @IPPROTO_TCP
%31 = load i32, i32* @TCP_NODELAY
%32 = call i32 @setsockopt(i32 %29, i32 %30, i32 %31, i32* %4, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %51
36: ; preds = %28
%37 = load i32, i32* %2
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%39 = call i32 @bind(i32 %37, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %51
43: ; preds = %36
%44 = load i32, i32* %2
%45 = call i32 @listen(i32 %44, i32 10)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %51
49: ; preds = %43
%50 = load i32, i32* %2
store i32 %50, i32* %1
br label %51
51: ; preds = %49, %47, %41, %34, %26, %9
%52 = load i32, i32* %1
ret i32 %52
}

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
@.str = [40 x i8] c"Server: Unable to create server socket.\00"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [56 x i8] c"Server: Unable to inform kernel to reuse server socket.\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.2 = [34 x i8] c"Server: Problem with TCP setting.\00"
@.str.3 = [41 x i8] c"Server: Unable to bind socket to server.\00"
@.str.4 = [43 x i8] c"Server: Unable to listen on server socket.\00"
define i32 @create_server_socket() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %44
11: ; preds = %0
%12 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = call i32 @htons(i32 4070)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_REUSEADDR
%22 = call i32 @setsockopt(i32 %7, i32 %20, i32 %21, i32* %2, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %44
26: ; preds = %11
%27 = load i32, i32* @IPPROTO_TCP
%28 = load i32, i32* @TCP_NODELAY
%29 = call i32 @setsockopt(i32 %7, i32 %27, i32 %28, i32* %2, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %44
33: ; preds = %26
%34 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%35 = call i32 @bind(i32 %7, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %44
39: ; preds = %33
%40 = call i32 @listen(i32 %7, i32 10)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %39, %42, %37, %31, %24, %9
%45 = phi i32 [ -1, %9 ], [ -1, %24 ], [ -1, %31 ], [ -1, %37 ], [ -1, %42 ], [ %7, %39 ]
ret i32 %45
}