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

/* Type definitions */
struct sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ cliente;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int udp_socket;
  struct addrinfo hints;
  struct addrinfo *res;
  char buffer[80];
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = 0;
  if (argc < 3) {
    perror("Error de argumentos.\n");
  }
  getaddrinfo(argv[1], argv[2], &hints, &res);
  udp_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  struct sockaddr_storage cliente;
  socklen_t cliente_len = sizeof(cliente);
  sendto(udp_socket, argv[3], strlen(argv[3]), 0,
         (struct sockaddr *)res->ai_addr, res->ai_addrlen);
  int recv = recvfrom(udp_socket, buffer, 80, 0, (struct sockaddr *)&cliente,
                      &cliente_len);
  buffer[recv] = '\0';
  printf("Mensaje recibido: %s\n", buffer);
  freeaddrinfo(res);
  close(udp_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11eb <main+0x5b>
lea    0xe1a(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    -0x48(%rbp),%rax
mov    0x1c(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rdx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
movl   $0x4,-0xac(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x48(%rbp),%rax
mov    (%rax),%r9d
xor    %ecx,%ecx
call   1050 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0xa8(%rbp),%r8
mov    $0x50,%edx
xor    %ecx,%ecx
lea    -0xac(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0xb0(%rbp)
movslq -0xb0(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xd55(%rip),%rdi
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
movq   $0x0,0x28(%rsp)
cmp    $0x2,%edi
jle    127e <main+0xee>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x18(%rsp),%rdx
mov    %rsp,%rcx
call   1090 <getaddrinfo@plt>
mov    (%rsp),%rax
mov    0x1c(%rax),%edi
mov    0x18(%rax),%esi
mov    0x10(%rax),%rdx
call   10b0 <socket@plt>
mov    %eax,%ebp
movl   $0x4,0xc(%rsp)
mov    0x18(%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    (%rsp),%rcx
mov    0x8(%rcx),%r8
mov    (%rcx),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <sendto@plt>
lea    0x40(%rsp),%rbx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
lea    0xdbc(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd7b(%rip),%rdi
call   1080 <perror@plt>
jmp    11d5 <main+0x45>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.1 = [22 x i8] c"Mensaje recibido: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca [80 x i8]
%10 = alloca %struct.sockaddr_storage
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AI_PASSIVE
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 5
store i32 %13, i32* %14
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i64 0, i64* %19
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @getaddrinfo(i8* %27, i8* %30, %struct.addrinfo* %7, %struct.addrinfo** %8)
%32 = load %struct.addrinfo*, %struct.addrinfo** %8
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 4
%34 = load i32, i32* %33
%35 = load %struct.addrinfo*, %struct.addrinfo** %8
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %8
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 2
%40 = load i64, i64* %39
%41 = call i32 @socket(i32 %34, i32 %37, i64 %40)
store i32 %41, i32* %6
store i32 4, i32* %11
%42 = load i32, i32* %6
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32 @strlen(i8* %48)
%50 = load %struct.addrinfo*, %struct.addrinfo** %8
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to %struct.sockaddr*
%54 = load %struct.addrinfo*, %struct.addrinfo** %8
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @sendto(i32 %42, i8* %45, i32 %49, i32 0, %struct.sockaddr* %53, i32 %56)
%58 = load i32, i32* %6
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%60 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%61 = call i32 @recvfrom(i32 %58, i8* %59, i32 80, i32 0, %struct.sockaddr* %60, i32* %11)
store i32 %61, i32* %12
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 %63
store i8 0, i8* %64
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%66 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = load %struct.addrinfo*, %struct.addrinfo** %8
%68 = call i32 @freeaddrinfo(%struct.addrinfo* %67)
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.1 = [22 x i8] c"Mensaje recibido: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [80 x i8]
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @AI_PASSIVE
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %11, i32* %12
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_DGRAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %17
%18 = icmp slt i32 %0, 3
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %23, i8* %25, %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = load %struct.addrinfo*, %struct.addrinfo** %4
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 3
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 2
%33 = load i64, i64* %32
%34 = call i32 @socket(i32 %29, i32 %31, i64 %33)
%35 = bitcast %struct.sockaddr_storage* %6 to i8*
%36 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @strlen(i8* %38)
%40 = load %struct.addrinfo*, %struct.addrinfo** %4
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to %struct.sockaddr*
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @sendto(i32 %34, i8* %38, i32 %39, i32 0, %struct.sockaddr* %43, i32 %45)
%47 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%48 = call i32 @recvfrom(i32 %34, i8* %10, i32 80, i32 0, %struct.sockaddr* %47, i32* %7)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%52 = load %struct.addrinfo*, %struct.addrinfo** %4
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
%54 = call i32 @close(i32 %34)
ret i32 0
}