#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*/ sAddr;
typedef int /*<<< orphan*/ cAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
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) {
  int connectionSock, serverSock, i;
  socklen_t sockLen;
  struct sockaddr_in sAddr, cAddr;
  char str[100];
  if ((serverSock = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    printf("error al crear el socket\n");
    exit(-1);
  }
  sAddr.sin_family = AF_INET;
  sAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  sAddr.sin_port = htons(5000);
  if (bind(serverSock, (struct sockaddr *)&sAddr, sizeof(sAddr)) == -1) {
    perror("bind\n");
    exit(-1);
  }
  if (listen(serverSock, 5) == -1) {
    perror("listen\n");
    exit(-1);
  }
  sockLen = sizeof(cAddr);
  if ((connectionSock =
           accept(serverSock, (struct sockaddr *)&cAddr, &sockLen)) == -1) {
    perror("accept\n");
    exit(-1);
  }
  printf("Somebody connected from %s:%d\n", inet_ntoa(cAddr.sin_addr),
         ntohs(cAddr.sin_port));
  if ((i = recv(connectionSock, str, 100, 0)) == 0) {
    perror("recv");
    close(connectionSock);
    close(serverSock);
    exit(-1);
  }
  str[i] = '\0';
  printf("I received %d character: \"%s\"\n", i, str);
  printf("Your Answer ");
  gets(str);
  send(connectionSock, str, strlen(str), 0);
  close(connectionSock);
  close(serverSock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1256 <main+0x56>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xdb1(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ae <main+0xae>
lea    0xd85(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12da <main+0xda>
lea    0xd5f(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1313 <main+0x113>
lea    0xd2e(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x3c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x40(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1389 <main+0x189>
lea    0xcef(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0xb0(%rbp,%rax,1)
mov    -0x1c(%rbp),%esi
lea    -0xb0(%rbp),%rdx
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   10b0 <gets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc4(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0xb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     136d <main+0x15d>
mov    %eax,%r14d
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0xdac(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x1388,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
je     1383 <main+0x173>
mov    %r14d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
je     138c <main+0x17c>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     1395 <main+0x185>
mov    %eax,%ebp
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%edi
call   10e0 <ntohs@plt>
lea    0xd43(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     13ab <main+0x19b>
movslq %eax,%rcx
movb   $0x0,0x30(%rsp,%rcx,1)
lea    0xd31(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd38(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   10c0 <gets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcfc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
lea    0xc80(%rip),%rdi
jmp    139c <main+0x18c>
lea    0xc7d(%rip),%rdi
jmp    139c <main+0x18c>
lea    0xc7c(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
lea    0xc8d(%rip),%rdi
call   1100 <perror@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"error al crear el socket\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [6 x i8] c"bind\0A\00"
@.str.3 = [8 x i8] c"listen\0A\00"
@.str.4 = [8 x i8] c"accept\0A\00"
@.str.5 = [31 x i8] c"Somebody connected from %s:%d\0A\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [31 x i8] c"I received %d character: \22%s\22\0A\00"
@.str.8 = [13 x i8] c"Your Answer \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 i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = call i32 @htons(i32 5000)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %7
%29 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %20
%36 = load i32, i32* %7
%37 = call i32 @listen(i32 %36, i32 5)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %35
store i32 12, i32* %9
%43 = load i32, i32* %7
%44 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%45 = call i32 @accept(i32 %43, %struct.sockaddr* %44, i32* %9)
store i32 %45, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %42
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i8* @inet_ntoa(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @ntohs(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %54, i32 %57)
%59 = load i32, i32* %6
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%61 = call i32 @recv(i32 %59, i8* %60, i32 100, i32 0)
store i32 %61, i32* %8
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %50
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %50
%71 = load i32, i32* %8
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 %72
store i8 0, i8* %73
%74 = load i32, i32* %8
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %74, i8* %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%79 = call i32 @gets(i8* %78)
%80 = load i32, i32* %6
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = call i32 @send(i32 %80, i8* %81, i32 %83, i32 0)
%85 = load i32, i32* %6
%86 = call i32 @close(i32 %85)
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [6 x i8] c"bind\0A\00"
@.str.3 = [8 x i8] c"listen\0A\00"
@.str.4 = [8 x i8] c"accept\0A\00"
@.str.5 = [31 x i8] c"Somebody connected from %s:%d\0A\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [31 x i8] c"I received %d character: \22%s\22\0A\00"
@.str.8 = [13 x i8] c"Your Answer \00"
@str = [25 x i8] c"error al crear el socket\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [100 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 5000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @bind(i32 %13, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %18
%32 = call i32 @listen(i32 %13, i32 5)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %31
store i32 12, i32* %3
%38 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%39 = call i32 @accept(i32 %13, %struct.sockaddr* %38, i32* %3)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %37
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%46 = load i32, i32* %45
%47 = call i8* @inet_ntoa(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @ntohs(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %47, i32 %50)
%52 = call i32 @recv(i32 %39, i8* %10, i32 100, i32 0)
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %44
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @close(i32 %39)
%57 = call i32 @close(i32 %13)
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %44
%60 = sext i32 %52 to i64
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %60
store i8 0, i8* %61
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %52, i8* %10)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 @gets(i8* %10)
%65 = call i32 @strlen(i8* %10)
%66 = call i32 @send(i32 %39, i8* %10, i32 %65, i32 0)
%67 = call i32 @close(i32 %39)
%68 = call i32 @close(i32 %13)
ret i32 0
}