#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 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 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);
  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    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ca <server_init+0x4a>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    1227 <server_init+0xa7>
lea    0xdf4(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1050 <listen@plt>
cmp    $0x0,%rax
jge    1258 <server_init+0xd8>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1295 <server_init+0x115>
lea    0xd94(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebp
mov    0x2e57(%rip),%r14
mov    (%r14),%edi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     121b <server_init+0x9b>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     1224 <server_init+0xa4>
mov    %ebx,%edi
mov    $0xa,%esi
call   1050 <listen@plt>
test   %rax,%rax
js     122d <server_init+0xad>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1080 <accept@plt>
test   %eax,%eax
js     1236 <server_init+0xb6>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdde(%rip),%rdi
jmp    123d <server_init+0xbd>
lea    0xddd(%rip),%rdi
jmp    123d <server_init+0xbd>
lea    0xdda(%rip),%rdi
jmp    123d <server_init+0xbd>
lea    0xdd9(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1090 <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
@.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 i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
%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* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* %2
%20 = call i32 @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %3
%27 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %16
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %16
%35 = load i32, i32* %3
%36 = call i64 @listen(i32 %35, i32 10)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
store i32 12, i32* %5
%43 = load i32, i32* %3
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = call i32 @accept(i32 %43, %struct.sockaddr* %44, i32* %5)
store i32 %45, i32* %4
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %42
%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 = %42
%52 = load i32, i32* %4
ret i32 %52
}

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