#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 socklen_t;
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ in_port_t;
typedef int /*<<< orphan*/ client_name;
typedef int /*<<< orphan*/ client_address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ die_with_sys_msg(char *);
int /*<<< orphan*/ die_with_user_msg(char *, char *);
int /*<<< orphan*/ handle_tcp_client(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                              int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    die_with_user_msg("Parameter(s)", "[Server Port]");
  }
  in_port_t server_port = atoi(argv[1]);
  int server_sock = 0;
  if ((server_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    die_with_sys_msg("socket() Failed !!!");
  }
  struct sockaddr_in server_address;
  memset(&server_address, 0, sizeof(server_address));
  server_address.sin_family = AF_INET;
  server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  server_address.sin_port = htons(server_port);
  if (bind(server_sock, (struct sockaddr *)&server_address,
           sizeof(server_address)) < 0) {
    die_with_sys_msg("bind() Failed !!!");
  }
  if (listen(server_sock, 5) < 0) {
    die_with_sys_msg("listen() Failed !!!");
  }
  for (;;) {
    struct sockaddr_in client_address;
    socklen_t client_address_length = sizeof(client_address);
    int client_sock = accept(server_sock, (struct sockaddr *)&client_address,
                             &client_address_length);
    if (client_sock < 0) {
      die_with_sys_msg("accept() Failed !!!");
    }
    char client_name[INET_ADDRSTRLEN];
    if (inet_ntop(AF_INET, &client_address.sin_addr.s_addr, client_name,
                  sizeof(client_name)) != NULL) {
      printf("Handling Client %s:%d\n", client_name,
             ntohs(client_address.sin_port));
    } else {
      printf("Unable To Retrieve The Client's Address !!!\n");
    }
    handle_tcp_client(client_sock);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1213 <main+0x33>
lea    0xdf9(%rip),%rdi
lea    0xdff(%rip),%rsi
call   10c0 <die_with_user_msg@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1262 <main+0x82>
lea    0xdbe(%rip),%rdi
call   1040 <die_with_sys_msg@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    12c1 <main+0xe1>
lea    0xd73(%rip),%rdi
call   1040 <die_with_sys_msg@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jge    12e4 <main+0x104>
lea    0xd62(%rip),%rdi
call   1040 <die_with_sys_msg@plt>
jmp    12e9 <main+0x109>
movl   $0xc,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1319 <main+0x139>
lea    0xd41(%rip),%rdi
call   1040 <die_with_sys_msg@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x50(%rbp)
mov    0x2c9c(%rip),%rcx
mov    (%rcx),%edi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
je     1388 <main+0x1a8>
mov    -0x38(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1396 <main+0x1b6>
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%edi
call   10f0 <handle_tcp_client@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
jmp    12e9 <main+0x109>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     121c <main+0x2c>
lea    0xdf0(%rip),%rdi
lea    0xdf6(%rip),%rsi
call   10d0 <die_with_user_msg@plt>
mov    0x8(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r14d
mov    0x2db9(%rip),%r12
mov    (%r12),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    125c <main+0x6c>
lea    0xdc4(%rip),%rdi
call   1050 <die_with_sys_msg@plt>
lea    -0x38(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    (%r12),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    12b2 <main+0xc2>
lea    0xd82(%rip),%rdi
call   1050 <die_with_sys_msg@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jns    12cf <main+0xdf>
lea    0xd77(%rip),%rdi
call   1050 <die_with_sys_msg@plt>
mov    0x2cea(%rip),%r15
jmp    12f7 <main+0x107>
nopl   0x0(%rax,%rax,1)
lea    0xd99(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   1100 <handle_tcp_client@plt>
mov    %r12,%rsp
movl   $0xc,-0x2c(%rbp)
mov    %ebx,%edi
lea    -0x48(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1320 <main+0x130>
lea    0xd3a(%rip),%rdi
call   1050 <die_with_sys_msg@plt>
mov    %rsp,%r12
mov    (%r15),%ecx
mov    %rsp,%r14
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    -0x44(%rbp),%rsi
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     12e0 <main+0xf0>
mov    -0x48(%rbp),%edi
call   10b0 <ntohs@plt>
lea    0xd06(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12ec <main+0xfc>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"Parameter(s)\00"
@.str.1 = [14 x i8] c"[Server Port]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [20 x i8] c"socket() Failed !!!\00"
@INADDR_ANY = global i32 0
@.str.3 = [18 x i8] c"bind() Failed !!!\00"
@.str.4 = [20 x i8] c"listen() Failed !!!\00"
@.str.5 = [20 x i8] c"accept() Failed !!!\00"
@INET_ADDRSTRLEN = global i32 0
@.str.6 = [23 x i8] c"Handling Client %s:%d\0A\00"
@.str.7 = [45 x i8] c"Unable To Retrieve The Client's Address !!!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @die_with_user_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
store i32 0, i32* %7
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = load i32, i32* @IPPROTO_TCP
%26 = call i32 @socket(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %18
%31 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i32, i32* %6
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %7
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = call i64 @bind(i32 %41, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %30
%46 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %30
%48 = load i32, i32* %7
%49 = call i64 @listen(i32 %48, i32 5)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
br label %54
54: ; preds = %80, %53
store i32 12, i32* %10
%55 = load i32, i32* %7
%56 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%57 = call i32 @accept(i32 %55, %struct.sockaddr* %56, i32* %10)
store i32 %57, i32* %11
%58 = load i32, i32* %11
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
%63 = load i32, i32* @INET_ADDRSTRLEN
%64 = zext i32 %63 to i64
%65 = call i8* @llvm.stacksave()
store i8* %65, i8** %12
%66 = alloca i8, i64 %64
store i64 %64, i64* %13
%67 = load i32, i32* @AF_INET
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
%70 = trunc i64 %64 to i32
%71 = call i32* @inet_ntop(i32 %67, i32* %69, i8* %66, i32 %70)
%72 = icmp ne i32* %71, null
br i1 %72, label %73, label %78
73: ; preds = %62
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i32 @ntohs(i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %66, i32 %76)
br label %80
78: ; preds = %62
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
%81 = load i32, i32* %11
%82 = call i32 @handle_tcp_client(i32 %81)
%83 = load i8*, i8** %12
br label %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"Parameter(s)\00"
@.str.1 = [14 x i8] c"[Server Port]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [20 x i8] c"socket() Failed !!!\00"
@INADDR_ANY = global i32 0
@.str.3 = [18 x i8] c"bind() Failed !!!\00"
@.str.4 = [20 x i8] c"listen() Failed !!!\00"
@.str.5 = [20 x i8] c"accept() Failed !!!\00"
@INET_ADDRSTRLEN = global i32 0
@.str.6 = [23 x i8] c"Handling Client %s:%d\0A\00"
@str = [44 x i8] c"Unable To Retrieve The Client's Address !!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @die_with_user_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = load i32, i32* @IPPROTO_TCP
%16 = tail call i32 @socket(i32 %13, i32 %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %9
%21 = bitcast %struct.sockaddr_in* %3 to i8*
%22 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = call i32 @htons(i32 %12)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i64 @bind(i32 %16, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %20
%36 = call i64 @listen(i32 %16, i32 5)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = bitcast %struct.sockaddr_in* %4 to i8*
%42 = bitcast i32* %5 to i8*
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %46
46: ; preds = %65, %40
store i32 12, i32* %5
%47 = call i32 @accept(i32 %16, %struct.sockaddr* %43, i32* %5)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @die_with_sys_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = load i32, i32* @INET_ADDRSTRLEN
%53 = zext i32 %52 to i64
%54 = call i8* @llvm.stacksave()
%55 = alloca i8, i64 %53
%56 = load i32, i32* @AF_INET
%57 = call i32* @inet_ntop(i32 %56, i32* %44, i8* %55, i32 %52)
%58 = icmp eq i32* %57, null
br i1 %58, label %63, label %59
59: ; preds = %51
%60 = load i32, i32* %45
%61 = call i32 @ntohs(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %55, i32 %61)
br label %65
63: ; preds = %51
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = call i32 @handle_tcp_client(i32 %47)
br label %46
}