#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*/ puts(char *);
int /*<<< orphan*/ receiveFile(char const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char const *, int);
int main(int argc, char const *argv[]) {
  int connector, connector2;
  struct sockaddr_in server;
  if (argc == 4) {
    if ((connector = socket(AF_INET, SOCK_STREAM, 0)) > 0) {
      puts("[CLIENTE] 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("[CLIENTE] CONECTADO");
        write(connector, argv[2], 512);
        puts("[CLIENTE] RECIBIENDO ARCHIVO");
        receiveFile(argv[3], connector);
        close(connector2);
      } else
        puts("[CLIENTE] ERROR AL CONECTAR");
      close(connector);
    } else
      puts("[CLIENTE] ERROR AL CREAR EL SOCKET");
  } else
    puts("ARGUMENTOS: <DIRECCION IP> <ARCHIVO SOLICITADO> <NOMBRE ARCHIVO "
         "GUARDADO>");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    128b <main+0x10b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    127a <main+0xfa>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1261 <main+0xe1>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x200,%edx
call   1040 <write@plt>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1080 <receiveFile@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    126d <main+0xed>
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
jmp    1286 <main+0x106>
lea    0xde0(%rip),%rdi
call   1030 <puts@plt>
jmp    1297 <main+0x117>
lea    0xdf2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x4,%edi
jne    1237 <main+0xb7>
mov    %rsi,%r14
mov    0x2e4d(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
jle    1240 <main+0xc0>
mov    %eax,%ebx
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
call   1070 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     124e <main+0xce>
mov    %eax,%ebp
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%r14),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1040 <write@plt>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%r14),%rdi
mov    %ebx,%esi
call   1080 <receiveFile@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    125a <main+0xda>
lea    0xe46(%rip),%rdi
jmp    1247 <main+0xc7>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
jmp    1261 <main+0xe1>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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 = [20 x i8] c"[CLIENTE] SOCKET OK\00"
@.str.1 = [20 x i8] c"[CLIENTE] CONECTADO\00"
@.str.2 = [29 x i8] c"[CLIENTE] RECIBIENDO ARCHIVO\00"
@.str.3 = [28 x i8] c"[CLIENTE] ERROR AL CONECTAR\00"
@.str.4 = [35 x i8] c"[CLIENTE] ERROR AL CREAR EL SOCKET\00"
@.str.5 = [74 x i8] c"ARGUMENTOS: <DIRECCION IP> <ARCHIVO SOLICITADO> <NOMBRE ARCHIVO GUARDADO>\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 %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %55
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %52
16: ; preds = %11
%17 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 9999)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @inet_addr(i8* %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %6
%29 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%30 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 4)
store i32 %30, i32* %7
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %47
32: ; preds = %16
%33 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %6
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @write(i32 %34, i8* %37, i32 512)
%39 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = load i32, i32* %6
%44 = call i32 @receiveFile(i8* %42, i32 %43)
%45 = load i32, i32* %7
%46 = call i32 @close(i32 %45)
br label %49
47: ; preds = %16
%48 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %32
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
br label %54
52: ; preds = %11
%53 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
br label %57
55: ; preds = %2
%56 = call i32 @puts(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %54
ret i32 0
}

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 = [20 x i8] c"[CLIENTE] SOCKET OK\00"
@.str.1 = [20 x i8] c"[CLIENTE] CONECTADO\00"
@.str.2 = [29 x i8] c"[CLIENTE] RECIBIENDO ARCHIVO\00"
@.str.3 = [28 x i8] c"[CLIENTE] ERROR AL CONECTAR\00"
@.str.4 = [35 x i8] c"[CLIENTE] ERROR AL CREAR EL SOCKET\00"
@.str.5 = [74 x i8] c"ARGUMENTOS: <DIRECCION IP> <ARCHIVO SOLICITADO> <NOMBRE ARCHIVO GUARDADO>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %6, label %40
6: ; preds = %2
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %38
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 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 i32 @htons(i32 9999)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @inet_addr(i8* %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @connect(i32 %9, %struct.sockaddr* %21, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %34, label %24
24: ; preds = %11
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @write(i32 %9, i8* %27, i32 512)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @receiveFile(i8* %31, i32 %9)
%33 = call i32 @close(i32 %22)
br label %36
34: ; preds = %11
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
%37 = call i32 @close(i32 %9)
br label %42
38: ; preds = %6
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %42
40: ; preds = %2
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %36, %38, %40
ret i32 0
}