#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*/ srv_sockaddr;
typedef int /*<<< orphan*/ socket_optval;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ *memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int start_server() {
  struct sockaddr_in srv_sockaddr;
  const char *socket_optval = "yes";
  int srv_socket;
  int ret = 0;
  if (memset(&srv_sockaddr, 0, sizeof(srv_sockaddr)) == NULL) {
    perror("memset() failed");
  }
  srv_sockaddr.sin_family = AF_INET;
  srv_sockaddr.sin_port = htons(5432);
  srv_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  srv_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (srv_socket == -1) {
    perror("socket() failed");
    ret = -1;
  }
  if (setsockopt(srv_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&socket_optval,
                 sizeof(socket_optval)) == -1) {
    perror("setsockopt() failed");
    ret = -1;
  }
  if (fcntl(srv_socket, F_SETFL, O_NONBLOCK) == -1) {
    perror("fcntl() failed");
    ret = -1;
  }
  if (bind(srv_socket, (struct sockaddr *)&srv_sockaddr,
           sizeof(srv_sockaddr)) == -1) {
    perror("bind() failed");
    ret = -1;
  }
  if (listen(srv_socket, 10) == -1) {
    perror("listen() failed");
    ret = -1;
  }
  printf("(Socket %d): Server listening on... %s:%d\n", srv_socket,
         inet_ntoa(srv_sockaddr.sin_addr), ntohs(srv_sockaddr.sin_port));
  return srv_socket;
}


x86 assembly (clang, -O0):
<start_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe31(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
cmp    $0x0,%rax
jne    1200 <start_server+0x40>
lea    0xe09(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1538,%edi
call   1060 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1263 <start_server+0xa3>
lea    0xdbd(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12a3 <start_server+0xe3>
lea    0xd8d(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d13(%rip),%rax
mov    (%rax),%esi
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12d9 <start_server+0x119>
lea    0xd6b(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1306 <start_server+0x146>
lea    0xd4d(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    132f <start_server+0x16f>
lea    0xd32(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
lea    0xd0c(%rip),%rdi
call   1070 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_server>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe32(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
test   %rax,%rax
je     12e1 <start_server+0x121>
mov    0x2dee(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x1538,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12f2 <start_server+0x132>
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1303 <start_server+0x143>
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1314 <start_server+0x154>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     1325 <start_server+0x165>
mov    %ebx,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     1336 <start_server+0x176>
mov    0x4(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%r14
mov    (%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xd9a(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1070 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd1c(%rip),%rdi
call   10d0 <perror@plt>
jmp    11eb <start_server+0x2b>
lea    0xd1b(%rip),%rdi
call   10d0 <perror@plt>
jmp    1234 <start_server+0x74>
lea    0xd1a(%rip),%rdi
call   10d0 <perror@plt>
jmp    1261 <start_server+0xa1>
lea    0xd1d(%rip),%rdi
call   10d0 <perror@plt>
jmp    1283 <start_server+0xc3>
lea    0xd1b(%rip),%rdi
call   10d0 <perror@plt>
jmp    129b <start_server+0xdb>
lea    0xd18(%rip),%rdi
call   10d0 <perror@plt>
jmp    12b0 <start_server+0xf0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"yes\00"
@.str.1 = [16 x i8] c"memset() failed\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [15 x i8] c"fcntl() failed\00"
@.str.5 = [14 x i8] c"bind() failed\00"
@.str.6 = [16 x i8] c"listen() failed\00"
@.str.7 = [43 x i8] c"(Socket %d): Server listening on... %s:%d\0A\00"
define i32 @start_server() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 0, i32* %4
%5 = call i32* @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 5432)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %9
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %25
25: ; preds = %23, %9
%26 = load i32, i32* %3
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_REUSEADDR
%29 = bitcast i8** %2 to i8*
%30 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, i8* %29, i32 8)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %34
34: ; preds = %32, %25
%35 = load i32, i32* %3
%36 = load i32, i32* @F_SETFL
%37 = load i32, i32* @O_NONBLOCK
%38 = call i32 @fcntl(i32 %35, i32 %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %42
42: ; preds = %40, %34
%43 = load i32, i32* %3
%44 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %4
br label %49
49: ; preds = %47, %42
%50 = load i32, i32* %3
%51 = call i32 @listen(i32 %50, i32 10)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %3
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i8* @inet_ntoa(i32 %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @ntohs(i32 %62)
%64 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %56, i8* %60, i32 %63)
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"yes\00"
@.str.1 = [16 x i8] c"memset() failed\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [15 x i8] c"fcntl() failed\00"
@.str.5 = [14 x i8] c"bind() failed\00"
@.str.6 = [16 x i8] c"listen() failed\00"
@.str.7 = [43 x i8] c"(Socket %d): Server listening on... %s:%d\0A\00"
define i32 @start_server() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8*
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast i8** %2 to i8*
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = call i32* @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 5432)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %9
%22 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %9
%24 = load i32, i32* @SOL_SOCKET
%25 = load i32, i32* @SO_REUSEADDR
%26 = call i32 @setsockopt(i32 %19, i32 %24, i32 %25, i8* %4, i32 8)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = load i32, i32* @F_SETFL
%32 = load i32, i32* @O_NONBLOCK
%33 = call i32 @fcntl(i32 %19, i32 %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
%38 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%39 = call i32 @bind(i32 %19, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = call i32 @listen(i32 %19, i32 10)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = load i32, i32* %16
%50 = call i8* @inet_ntoa(i32 %49)
%51 = load i32, i32* %13
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i32 %19, i8* %50, i32 %52)
ret i32 %19
}