#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*/ ops;

/* 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 *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int server_init(int port) {
  socklen_t clen;
  struct sockaddr_in serv, client;
  int s, s1;
  int ops = 1;
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket:");
    exit(EXIT_FAILURE);
  }
  setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &ops, sizeof(ops));
  serv.sin_family = AF_INET;
  serv.sin_port = htons(port);
  serv.sin_addr.s_addr = htonl(INADDR_ANY);
  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)
movl   $0x1,-0x34(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    11e1 <server_init+0x51>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1262 <server_init+0xd2>
lea    0xdb9(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    1293 <server_init+0x103>
lea    0xd8e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0xc,-0x8(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    12d0 <server_init+0x140>
lea    0xd59(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x30(%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
movl   $0x1,0x8(%rsp)
mov    0x2e37(%rip),%r14
mov    (%r14),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     125b <server_init+0xcb>
mov    %eax,%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
js     1264 <server_init+0xd4>
mov    %ebx,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
test   %rax,%rax
js     126d <server_init+0xdd>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1090 <accept@plt>
test   %eax,%eax
js     1276 <server_init+0xe6>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd9e(%rip),%rdi
jmp    127d <server_init+0xed>
lea    0xd9d(%rip),%rdi
jmp    127d <server_init+0xed>
lea    0xd9a(%rip),%rdi
jmp    127d <server_init+0xed>
lea    0xd99(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d37(%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
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [6 x i8] c"bind:\00"
@.str.2 = [8 x i8] c"listen:\00"
@.str.3 = [8 x i8] c"accept:\00"
define i32 @server_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %8
%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* %6
%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* %6
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %8, i32 4)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* %2
%25 = call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 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* %4, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %17
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %17
%40 = load i32, i32* %6
%41 = call i64 @listen(i32 %40, i32 10)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %39
store i32 12, i32* %3
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %3)
store i32 %50, i32* %7
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %47
%57 = load i32, i32* %7
ret i32 %57
}

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