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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
mainso2() {
  int client;
  struct sockaddr_in scli;
  int lenstru = sizeof(scli);
  client = socket(AF_INET, SOCK_STREAM, 0);
  scli.sin_family = AF_INET;
  scli.sin_port = htons(8006);
  scli.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(client, (struct sockaddr *)&scli, lenstru) != -1) {
    char buf[30];
    int nb;
    write(client, "Hola Servidor", 30);
    nb = read(client, buf, 30);
    buf[nb] = '\0';
    printf("%s\n", buf);
    close(client);
  }
}


x86 assembly (clang, -O0):
<mainso2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0xc,-0x1c(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1f46,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe35(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     1234 <mainso2+0xb4>
mov    -0x8(%rbp),%edi
lea    0xe15(%rip),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1e,%edx
call   1070 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainso2>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e5a(%rip),%r14
mov    (%r14),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x1f46,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe41(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     121f <mainso2+0x9f>
lea    0xe28(%rip),%rsi
mov    %ebx,%edi
mov    $0x1e,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1e,%edx
call   1070 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe08(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"Hola Servidor\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @mainso2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = alloca i32
store i32 12, i32* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 8006)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %2
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = load i32, i32* %4
%20 = call i32 @connect(i32 %17, %struct.sockaddr* %18, i32 %19)
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %35
22: ; preds = %0
%23 = load i32, i32* %2
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 30)
%25 = load i32, i32* %2
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 30)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %22, %0
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"Hola Servidor\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @mainso2() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [30 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @htons(i32 8006)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %9, i32* %10
%11 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%14 = call i32 @connect(i32 %6, %struct.sockaddr* %13, i32 12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %24, label %16
16: ; preds = %0
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%18 = call i32 @write(i32 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 30)
%19 = call i32 @read(i32 %6, i8* %17, i32 30)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%23 = call i32 @close(i32 %6)
br label %24
24: ; preds = %16, %0
ret i32 undef
}