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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void server_init(int *sock_desc, struct sockaddr_in *sock_addr) {
  *sock_desc = socket(AF_INET, SOCK_STREAM, 0);
  if (*sock_desc == -1)
    exit(EXIT_FAILURE);
  sock_addr->sin_family = AF_INET;
  sock_addr->sin_addr.s_addr = INADDR_ANY;
  sock_addr->sin_port = htons(8583);
  if (bind(*sock_desc, (struct sockaddr *)sock_addr, sizeof(*sock_addr)) < 0)
    exit(EXIT_FAILURE);
  if (listen(*sock_desc, 10))
    exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<server_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    119c <server_init+0x4c>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x2187,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    11fa <server_init+0xaa>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0xa,%esi
call   1040 <listen@plt>
cmp    $0x0,%rax
je     1222 <server_init+0xd2>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_init>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e86(%rip),%r15
mov    (%r15),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     11c8 <server_init+0x78>
mov    (%r15),%eax
mov    %eax,0x8(%rbx)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    $0x2187,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1050 <bind@plt>
test   %rax,%rax
js     11c8 <server_init+0x78>
mov    (%r14),%edi
mov    $0xa,%esi
call   1040 <listen@plt>
test   %rax,%rax
jne    11c8 <server_init+0x78>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
define void @server_init(i32* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32*
%4 = alloca %struct.sockaddr_in*
store i32* %0, i32** %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32*, i32** %3
store i32 %7, i32* %8
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %16, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = call i32 @htons(i32 8583)
%24 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32*, i32** %3
%27 = load i32, i32* %26
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%29 = bitcast %struct.sockaddr_in* %28 to %struct.sockaddr*
%30 = call i64 @bind(i32 %27, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %15
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %15
%36 = load i32*, i32** %3
%37 = load i32, i32* %36
%38 = call i64 @listen(i32 %37, i32 10)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
define void @server_init(i32* nocapture %0, %struct.sockaddr_in* %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %0
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 8583)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* %0
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%19 = tail call i64 @bind(i32 %17, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = load i32, i32* %0
%26 = tail call i64 @listen(i32 %25, i32 10)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %24
ret void
}