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

/* Type definitions */
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int atoi(char *const);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
struct hostent *gethostbyname(char const *const);
int /*<<< orphan*/ htons(int const);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int server(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *const);
int main(int argc, char *const argv[]) {
  const char *const socket_host = "192.168.11.244";
  const int port = atoi(argv[1]);
  struct hostent *hostinfo;
  int socket_fd;
  struct sockaddr_in name;
  int client_sent_quit_message;
  socket_fd = socket(PF_INET, SOCK_STREAM, 0);
  name.sin_family = AF_INET;
  hostinfo = gethostbyname(socket_host);
  if (hostinfo == NULL)
    return 1;
  else
    name.sin_addr = *((struct in_addr *)hostinfo->h_addr);
  name.sin_port = htons(port);
  if (bind(socket_fd, (struct sockaddr *)&name, sizeof(struct sockaddr_in)) < 0)
    printf("ERRO NO BIND \n");
  listen(socket_fd, 5);
  do {
    struct sockaddr_in client_name;
    socklen_t client_name_len;
    int client_socket_fd;
    client_socket_fd =
        accept(socket_fd, (struct sockaddr *)&client_name, &client_name_len);
    client_sent_quit_message = server(client_socket_fd);
    close(client_socket_fd);
  } while (!client_sent_quit_message);
  close(socket_fd);
  unlink(socket_host);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    0xdf0(%rip),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1230 <main+0x80>
movl   $0x1,-0x4(%rbp)
jmp    12cd <main+0x11d>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    126e <main+0xbe>
lea    0xda6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
mov    -0x2c(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
call   1080 <server@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x50(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x3c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    127b <main+0xcb>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
lea    0xd3f(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r12d
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe09(%rip),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     128c <main+0xdc>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    1239 <main+0x89>
lea    0xddb(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <server@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
test   %ebx,%ebx
je     1250 <main+0xa0>
mov    %r12d,%edi
call   1060 <close@plt>
lea    0xd7d(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
jmp    1291 <main+0xe1>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"192.168.11.244\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [15 x i8] c"ERRO NO BIND \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.hostent*
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %9
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %22, i32* %23
%24 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0))
store %struct.hostent* %24, %struct.hostent** %8
%25 = load %struct.hostent*, %struct.hostent** %8
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %27, label %28
27: ; preds = %2
store i32 1, i32* %3
br label %65
28: ; preds = %2
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%30 = load %struct.hostent*, %struct.hostent** %8
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = inttoptr i64 %32 to %struct.in_addr*
%34 = bitcast %struct.in_addr* %29 to i8*
%35 = bitcast %struct.in_addr* %33 to i8*
br label %36
36: ; preds = %28
%37 = load i32, i32* %7
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* %9
%41 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%42 = call i64 @bind(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %36
%47 = load i32, i32* %9
%48 = call i32 @listen(i32 %47, i32 5)
br label %49
49: ; preds = %57, %46
%50 = load i32, i32* %9
%51 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%52 = call i32 @accept(i32 %50, %struct.sockaddr* %51, i32* %13)
store i32 %52, i32* %14
%53 = load i32, i32* %14
%54 = call i32 @server(i32 %53)
store i32 %54, i32* %11
%55 = load i32, i32* %14
%56 = call i32 @close(i32 %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %11
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br i1 %60, label %49, label %61
61: ; preds = %57
%62 = load i32, i32* %9
%63 = call i32 @close(i32 %62)
%64 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0))
store i32 0, i32* %3
br label %65
65: ; preds = %61, %27
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"192.168.11.244\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@str = [14 x i8] c"ERRO NO BIND \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %43, label %17
17: ; preds = %2
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i32*
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%22 = load i32, i32* %20
store i32 %22, i32* %21
%23 = tail call i32 @htons(i32 %8)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @bind(i32 %12, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %17
%31 = call i32 @listen(i32 %12, i32 5)
%32 = bitcast %struct.sockaddr_in* %4 to i8*
%33 = bitcast i32* %5 to i8*
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %35
35: ; preds = %35, %30
%36 = call i32 @accept(i32 %12, %struct.sockaddr* %34, i32* %5)
%37 = call i32 @server(i32 %36)
%38 = call i32 @close(i32 %36)
%39 = icmp eq i32 %37, 0
br i1 %39, label %35, label %40
40: ; preds = %35
%41 = call i32 @close(i32 %12)
%42 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %2, %40
%44 = phi i32 [ 0, %40 ], [ 1, %2 ]
ret i32 %44
}