#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ option_value;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int start_server() {
  int listen_socket, client_socket;
  int option_value;
  struct sockaddr_in server_address, client_address;
  socklen_t address_length;
  address_length = sizeof(struct sockaddr_in);
  listen_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (listen_socket == -1) {
    perror("Error creating socket");
    return -1;
  }
  option_value = 1;
  if (setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &option_value,
                 sizeof(option_value)) == -1) {
    perror("Error setting socket option");
    return -1;
  }
  server_address.sin_family = AF_INET;
  server_address.sin_port = htons(2342);
  server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(listen_socket, (struct sockaddr *)&server_address, address_length) ==
      -1) {
    perror("Error binding to socket");
    return -1;
  }
  if (listen(listen_socket, 5) == -1) {
    perror("Error setting connection to server mode");
    return -1;
  }
  client_socket = accept(listen_socket, (struct sockaddr *)&client_address,
                         &address_length);
  if (client_socket == -1) {
    perror("Connection error");
    return -1;
  }
  return client_socket;
}


x86 assembly (clang, -O0):
<start_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0xc,-0x34(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cd <start_server+0x4d>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <start_server+0x15c>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1219 <start_server+0x99>
lea    0xe0e(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <start_server+0x15c>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x926,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1273 <start_server+0xf3>
lea    0xdd0(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <start_server+0x15c>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    12a1 <start_server+0x121>
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <start_server+0x15c>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12d6 <start_server+0x156>
lea    0xdad(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <start_server+0x15c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_server>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movl   $0xc,(%rsp)
mov    0x2e4b(%rip),%r14
mov    (%r14),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     124f <start_server+0xcf>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1258 <start_server+0xd8>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    $0x926,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     1261 <start_server+0xe1>
mov    %ebx,%edi
mov    $0x5,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
je     126a <start_server+0xea>
lea    0x18(%rsp),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
cmp    $0xffffffff,%eax
jne    127b <start_server+0xfb>
lea    0xe25(%rip),%rdi
jmp    1271 <start_server+0xf1>
lea    0xdaa(%rip),%rdi
jmp    1271 <start_server+0xf1>
lea    0xdb7(%rip),%rdi
jmp    1271 <start_server+0xf1>
lea    0xdca(%rip),%rdi
jmp    1271 <start_server+0xf1>
lea    0xdd9(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error creating socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [28 x i8] c"Error setting socket option\00"
@INADDR_ANY = global i32 0
@.str.2 = [24 x i8] c"Error binding to socket\00"
@.str.3 = [40 x i8] c"Error setting connection to server mode\00"
@.str.4 = [17 x i8] c"Connection error\00"
define i32 @start_server() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 12, i32* %7
%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* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
15: ; preds = %0
store i32 1, i32* %4
%16 = load i32, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %4, i32 4)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
23: ; preds = %15
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 2342)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
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* %5, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = load i32, i32* %2
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = load i32, i32* %7
%35 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
39: ; preds = %23
%40 = load i32, i32* %2
%41 = call i32 @listen(i32 %40, i32 5)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
45: ; preds = %39
%46 = load i32, i32* %2
%47 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%48 = call i32 @accept(i32 %46, %struct.sockaddr* %47, i32* %7)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
53: ; preds = %45
%54 = load i32, i32* %3
store i32 %54, i32* %1
br label %55
55: ; preds = %53, %51, %43, %37, %21, %13
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error creating socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [28 x i8] c"Error setting socket option\00"
@INADDR_ANY = global i32 0
@.str.2 = [24 x i8] c"Error binding to socket\00"
@.str.3 = [40 x i8] c"Error setting connection to server mode\00"
@.str.4 = [17 x i8] c"Connection error\00"
define i32 @start_server() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %46
15: ; preds = %0
store i32 1, i32* %1
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_REUSEADDR
%18 = call i32 @setsockopt(i32 %11, i32 %16, i32 %17, i32* %1, i32 4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %46
22: ; preds = %15
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 2342)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%31 = call i32 @bind(i32 %11, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %46
35: ; preds = %22
%36 = call i32 @listen(i32 %11, i32 5)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %46
40: ; preds = %35
%41 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%42 = call i32 @accept(i32 %11, %struct.sockaddr* %41, i32* %4)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %40, %44, %38, %33, %20, %13
%47 = phi i32 [ -1, %13 ], [ -1, %20 ], [ -1, %33 ], [ -1, %38 ], [ -1, %44 ], [ %42, %40 ]
ret i32 %47
}