#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;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int server_init(int port) {
  int s, s1;
  socklen_t clen;
  struct sockaddr_in serv, client;
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket:");
    exit(EXIT_FAILURE);
  }
  serv.sin_family = AF_INET;
  serv.sin_port = htons(port);
  serv.sin_addr.s_addr = htonl(INADDR_ANY);
  int enable = 1;
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
    perror("setsockopt(SO_REUSEADDR):");
    exit(EXIT_FAILURE);
  }
  if ((bind(s, (struct sockaddr *)&serv, sizeof(struct sockaddr_in))) < 0) {
    perror("bind:");
    exit(EXIT_FAILURE);
  }
  if ((listen(s, 10)) < 0) {
    perror("listen:");
    exit(EXIT_FAILURE);
  }
  clen = sizeof(struct sockaddr_in);
  if ((s1 = accept(s, (struct sockaddr *)&client, &clen)) < 0) {
    perror("accept:");
    exit(EXIT_FAILURE);
  }
  return s1;
}


x86 assembly (clang, -O0):
<server_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11da <server_init+0x4a>
lea    0xe39(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1251 <server_init+0xc1>
lea    0xdca(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1286 <server_init+0xf6>
lea    0xdaf(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    12b7 <server_init+0x127>
lea    0xd84(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12f4 <server_init+0x164>
lea    0xd4f(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebp
mov    0x2e3f(%rip),%r14
mov    (%r14),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1260 <server_init+0xd0>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1269 <server_init+0xd9>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     1272 <server_init+0xe2>
mov    %ebx,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
test   %rax,%rax
js     127b <server_init+0xeb>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
test   %eax,%eax
js     1284 <server_init+0xf4>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd99(%rip),%rdi
jmp    128b <server_init+0xfb>
lea    0xd98(%rip),%rdi
jmp    128b <server_init+0xfb>
lea    0xda9(%rip),%rdi
jmp    128b <server_init+0xfb>
lea    0xda6(%rip),%rdi
jmp    128b <server_init+0xfb>
lea    0xda5(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

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 = [8 x i8] c"socket:\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [26 x i8] c"setsockopt(SO_REUSEADDR):\00"
@.str.2 = [6 x i8] c"bind:\00"
@.str.3 = [8 x i8] c"listen:\00"
@.str.4 = [8 x i8] c"accept:\00"
define i32 @server_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
store i32 1, i32* %8
%27 = load i32, i32* %3
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i64 @setsockopt(i32 %27, i32 %28, i32 %29, i32* %8, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %17
%33 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %17
%37 = load i32, i32* %3
%38 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%39 = call i64 @bind(i32 %37, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
%46 = load i32, i32* %3
%47 = call i64 @listen(i32 %46, i32 10)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45
store i32 12, i32* %5
%54 = load i32, i32* %3
%55 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%56 = call i32 @accept(i32 %54, %struct.sockaddr* %55, i32* %5)
store i32 %56, i32* %4
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %53
%63 = load i32, i32* %4
ret i32 %63
}

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 = [8 x i8] c"socket:\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [26 x i8] c"setsockopt(SO_REUSEADDR):\00"
@.str.2 = [6 x i8] c"bind:\00"
@.str.3 = [8 x i8] c"listen:\00"
@.str.4 = [8 x i8] c"accept:\00"
define i32 @server_init(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%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 slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 %0)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = tail call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %23, i32* %24
%25 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = call i64 @setsockopt(i32 %11, i32 %26, i32 %27, i32* %5, i32 4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %17
%31 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %17
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i64 @bind(i32 %11, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
%43 = call i64 @listen(i32 %11, i32 10)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
store i32 12, i32* %2
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i32 @accept(i32 %11, %struct.sockaddr* %50, i32* %2)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
ret i32 %51
}