#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;
};

/* 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 const *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int i, connector, connector2, readBytes;
  struct sockaddr_in server;
  char buffer[512], args[512];
  if (argc >= 3) {
    args[0] = '\0';
    for (i = 2; i < argc; i++) {
      if (i == 2)
        sprintf(args, "%s%s", args, argv[i]);
      else
        sprintf(args, "%s %s", args, argv[i]);
    }
    printf("CMD: %s\n", args);
    if ((connector = socket(AF_INET, SOCK_STREAM, 0)) > 0) {
      puts("SOCKET OK");
      server.sin_family = AF_INET;
      server.sin_port = htons(9999);
      server.sin_addr.s_addr = inet_addr(argv[1]);
      if ((connector2 = connect(connector, (struct sockaddr *)&server,
                                sizeof(struct sockaddr))) != -1) {
        puts("CONECTADO AL SERVIDOR");
        write(connector, args, 512);
        puts("LEYENDO RESPUESTA DEL SERVIDOR");
        do {
          readBytes = read(connector, buffer, 512);
          buffer[readBytes] = '\0';
          printf("%s", buffer);
        } while (readBytes > 0);
        close(connector2);
      } else
        puts("ERROR AL CONECTAR AL SERVIDOR");
      shutdown(connector, 2);
      close(connector);
    } else
      puts("ERROR AL CREAR EL SOCKET");
  } else
    puts("INTRODUCE UNA IP Y UN COMANDO");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1395 <main+0x1e5>
movb   $0x0,-0x430(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125b <main+0xab>
cmpl   $0x2,-0x14(%rbp)
jne    1222 <main+0x72>
lea    -0x430(%rbp),%rdi
lea    -0x430(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xde8(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    1248 <main+0x98>
lea    -0x430(%rbp),%rdi
lea    -0x430(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdc2(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    124d <main+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <main+0x31>
lea    -0x430(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1384 <main+0x1d4>
lea    0xd7a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     135e <main+0x1ae>
lea    0xd32(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x200,%edx
call   1040 <write@plt>
lea    0xd28(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
lea    -0x230(%rbp),%rsi
lea    0xcc6(%rip),%rdi
call   1070 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jg     1311 <main+0x161>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
jmp    136a <main+0x1ba>
lea    0xcee(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    1390 <main+0x1e0>
lea    0xce6(%rip),%rdi
call   1030 <puts@plt>
jmp    13a1 <main+0x1f1>
lea    0xcee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
cmp    $0x3,%edi
jl     1324 <main+0x174>
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0x0,0x10(%rsp)
mov    0x10(%rsi),%rcx
lea    0xe23(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rdi,%rdx
call   10b0 <sprintf@plt>
cmp    $0x3,%ebp
je     122b <main+0x7b>
mov    %ebp,%r12d
mov    $0x3,%ebp
lea    0xe07(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbp,8),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1210 <main+0x60>
lea    0xdd9(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <printf@plt>
mov    0x2da5(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jle    132d <main+0x17d>
mov    %eax,%r15d
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
je     133b <main+0x18b>
mov    %eax,%r14d
lea    0xd6f(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x200,%edx
call   1040 <write@plt>
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
lea    0x210(%rsp),%rbx
lea    0xd27(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
movslq %eax,%rbp
movb   $0x0,0x210(%rsp,%rbp,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
test   %ebp,%ebp
jg     12f0 <main+0x140>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    1347 <main+0x197>
lea    0xd5f(%rip),%rdi
jmp    1334 <main+0x184>
lea    0xd3d(%rip),%rdi
call   1030 <puts@plt>
jmp    135c <main+0x1ac>
lea    0xd11(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    %r15d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
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 = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [9 x i8] c"CMD: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [10 x i8] c"SOCKET OK\00"
@.str.4 = [22 x i8] c"CONECTADO AL SERVIDOR\00"
@.str.5 = [31 x i8] c"LEYENDO RESPUESTA DEL SERVIDOR\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [30 x i8] c"ERROR AL CONECTAR AL SERVIDOR\00"
@.str.8 = [25 x i8] c"ERROR AL CREAR EL SOCKET\00"
@.str.9 = [30 x i8] c"INTRODUCE UNA IP Y UN COMANDO\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 [512 x i8]
%12 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 3
br i1 %14, label %15, label %100
15: ; preds = %2
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
store i8 0, i8* %16
store i32 2, i32* %6
br label %17
17: ; preds = %43, %15
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %46
21: ; preds = %17
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %31)
br label %42
33: ; preds = %21
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %40)
br label %42
42: ; preds = %33, %24
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %17
46: ; preds = %17
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%48 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @AF_INET
%50 = load i32, i32* @SOCK_STREAM
%51 = call i32 @socket(i32 %49, i32 %50, i32 0)
store i32 %51, i32* %7
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %97
53: ; preds = %46
%54 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %55, i32* %56
%57 = call i32 @htons(i32 9999)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %57, i32* %58
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @inet_addr(i8* %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 0
store i32 %62, i32* %64
%65 = load i32, i32* %7
%66 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%67 = call i32 @connect(i32 %65, %struct.sockaddr* %66, i32 4)
store i32 %67, i32* %8
%68 = icmp ne i32 %67, -1
br i1 %68, label %69, label %90
69: ; preds = %53
%70 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%71 = load i32, i32* %7
%72 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%73 = call i32 @write(i32 %71, i8* %72, i32 512)
%74 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %84, %69
%76 = load i32, i32* %7
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 512)
store i32 %78, i32* %9
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 %80
store i8 0, i8* %81
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%83 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %75
%85 = load i32, i32* %9
%86 = icmp sgt i32 %85, 0
br i1 %86, label %75, label %87
87: ; preds = %84
%88 = load i32, i32* %8
%89 = call i32 @close(i32 %88)
br label %92
90: ; preds = %53
%91 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
%93 = load i32, i32* %7
%94 = call i32 @shutdown(i32 %93, i32 2)
%95 = load i32, i32* %7
%96 = call i32 @close(i32 %95)
br label %99
97: ; preds = %46
%98 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %99
99: ; preds = %97, %92
br label %102
100: ; preds = %2
%101 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
br label %102
102: ; preds = %100, %99
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [9 x i8] c"CMD: %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [10 x i8] c"SOCKET OK\00"
@.str.4 = [22 x i8] c"CONECTADO AL SERVIDOR\00"
@.str.5 = [31 x i8] c"LEYENDO RESPUESTA DEL SERVIDOR\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [30 x i8] c"ERROR AL CONECTAR AL SERVIDOR\00"
@.str.8 = [25 x i8] c"ERROR AL CREAR EL SOCKET\00"
@.str.9 = [30 x i8] c"INTRODUCE UNA IP Y UN COMANDO\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %0, 2
br i1 %9, label %10, label %61
10: ; preds = %2
store i8 0, i8* %8
%11 = zext i32 %0 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %13)
%15 = icmp eq i32 %0, 3
br i1 %15, label %23, label %16
16: ; preds = %10, %16
%17 = phi i64 [ %21, %16 ], [ 3, %10 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %16
23: ; preds = %16, %10
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %59
29: ; preds = %23
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = call i32 @htons(i32 9999)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @inet_addr(i8* %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i32 @connect(i32 %27, %struct.sockaddr* %39, i32 4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %54, label %42
42: ; preds = %29
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @write(i32 %27, i8* %8, i32 512)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %46, %42
%47 = call i32 @read(i32 %27, i8* %7, i32 512)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %48
store i8 0, i8* %49
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%51 = icmp sgt i32 %47, 0
br i1 %51, label %46, label %52
52: ; preds = %46
%53 = call i32 @close(i32 %40)
br label %56
54: ; preds = %29
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = call i32 @shutdown(i32 %27, i32 2)
%58 = call i32 @close(i32 %27)
br label %63
59: ; preds = %23
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %63
61: ; preds = %2
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
br label %63
63: ; preds = %56, %59, %61
ret i32 0
}