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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char *msg = "Hola mundo!!!";
  struct sockaddr_in dest;
  struct sockaddr_in serv;
  int server;
  socklen_t socksize = sizeof(struct sockaddr_in);
  memset(&serv, 0, sizeof(serv));
  serv.sin_family = AF_INET;
  serv.sin_addr.s_addr = htonl(INADDR_ANY);
  serv.sin_port = htons(9999);
  server = socket(AF_INET, SOCK_STREAM, 0);
  if (server < 0) {
    printf("Error: Socket()\n");
    return -1;
  }
  bind(server, (struct sockaddr *)&serv, sizeof(struct sockaddr));
  listen(server, 1);
  int client = accept(server, (struct sockaddr *)&dest, &socksize);
  if (client < 0) {
    printf("Error: Accept()\n");
    return -1;
  }
  while (client) {
    printf("IP %s - envía un hola\n", inet_ntoa(dest.sin_addr));
    send(client, msg, strlen(msg), 0);
    close(client);
    client = accept(server, (struct sockaddr *)&dest, &socksize);
  }
  close(server);
  return EXIT_SUCCESS;
}


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)
lea    0xe23(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xc,-0x40(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x38(%rbp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1262 <main+0xa2>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133a <main+0x17a>
mov    -0x3c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
mov    -0x3c(%rbp),%edi
mov    $0x1,%esi
call   10b0 <listen@plt>
mov    -0x3c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12b7 <main+0xf7>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133a <main+0x17a>
jmp    12bc <main+0xfc>
cmpl   $0x0,-0x44(%rbp)
je     1326 <main+0x166>
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
mov    -0x3c(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x44(%rbp)
jmp    12bc <main+0xfc>
mov    -0x3c(%rbp),%edi
call   10a0 <close@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0xc,0x4(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2dea(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     12fa <main+0x12a>
mov    %eax,%r15d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   10d0 <bind@plt>
mov    %r15d,%edi
mov    $0x1,%esi
call   10c0 <listen@plt>
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r15d,%edi
call   10e0 <accept@plt>
test   %eax,%eax
js     1303 <main+0x133>
je     12e7 <main+0x117>
mov    %eax,%ebp
lea    0xd8a(%rip),%r14
lea    0xd75(%rip),%rbx
lea    0x18(%rsp),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x18(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   10e0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    12a0 <main+0xd0>
mov    %r15d,%edi
call   10b0 <close@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
jmp    1314 <main+0x144>
lea    0xd35(%rip),%rdi
jmp    130a <main+0x13a>
lea    0xd1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"Hola mundo!!!\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"Error: Socket()\0A\00"
@.str.2 = [17 x i8] c"Error: Accept()\0A\00"
@.str.3 = [24 x i8] c"IP %s - env\C3\ADa un hola\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 12, i32* %10
%12 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 9999)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
28: ; preds = %2
%29 = load i32, i32* %9
%30 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 4)
%32 = load i32, i32* %9
%33 = call i32 @listen(i32 %32, i32 1)
%34 = load i32, i32* %9
%35 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%36 = call i32 @accept(i32 %34, %struct.sockaddr* %35, i32* %10)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %28
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
41: ; preds = %28
br label %42
42: ; preds = %45, %41
%43 = load i32, i32* %11
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i8* @inet_ntoa(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = load i32, i32* %11
%52 = load i8*, i8** %6
%53 = load i8*, i8** %6
%54 = call i32 @strlen(i8* %53)
%55 = call i32 @send(i32 %51, i8* %52, i32 %54, i32 0)
%56 = load i32, i32* %11
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %9
%59 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%60 = call i32 @accept(i32 %58, %struct.sockaddr* %59, i32* %10)
store i32 %60, i32* %11
br label %42
61: ; preds = %42
%62 = load i32, i32* %9
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* @EXIT_SUCCESS
store i32 %64, i32* %3
br label %65
65: ; preds = %61, %39, %26
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"Hola mundo!!!\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [24 x i8] c"IP %s - env\C3\ADa un hola\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [16 x i8] c"Error: Accept()\00"
@str.4 = [16 x i8] c"Error: Socket()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%9 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 9999)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %49
23: ; preds = %2
%24 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%25 = call i32 @bind(i32 %19, %struct.sockaddr* %24, i32 4)
%26 = call i32 @listen(i32 %19, i32 1)
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @accept(i32 %19, %struct.sockaddr* %27, i32* %5)
%29 = icmp slt i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %23
%31 = icmp eq i32 %28, 0
br i1 %31, label %46, label %32
32: ; preds = %30
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
br label %36
34: ; preds = %23
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %49
36: ; preds = %32, %36
%37 = phi i32 [ %28, %32 ], [ %44, %36 ]
%38 = load i32, i32* %33
%39 = call i8* @inet_ntoa(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @send(i32 %37, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %41, i32 0)
%43 = call i32 @close(i32 %37)
%44 = call i32 @accept(i32 %19, %struct.sockaddr* %27, i32* %5)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %36
46: ; preds = %36, %30
%47 = call i32 @close(i32 %19)
%48 = load i32, i32* @EXIT_SUCCESS
br label %49
49: ; preds = %34, %46, %21
%50 = phi i32 [ -1, %21 ], [ -1, %34 ], [ %48, %46 ]
ret i32 %50
}