#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in servidor, si_me;
  struct hostent *he;
  int numbytes;
  char buffer[80];
  int addr_len = sizeof(struct sockaddr);
  if (argc != 2) {
    fprintf(stderr, "uso: clienteUDP dirIPServidor\n");
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    perror("gethostbyname");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  servidor.sin_family = AF_INET;
  servidor.sin_port = htons(60000);
  servidor.sin_addr = *((struct in_addr *)he->h_addr);
  memset(&(servidor.sin_zero), '\0', 8);
  printf("Teclea un mensaje: ");
  fgets(buffer, 80, stdin);
  buffer[strlen(buffer) - 1] = '\0';
  if ((numbytes = sendto(sockfd, buffer, strlen(buffer), 0,
                         (struct sockaddr *)&servidor,
                         sizeof(struct sockaddr))) == -1) {
    perror("sendto");
    exit(1);
  }
  printf("Envia %d bytes a %s\n", numbytes, inet_ntoa(servidor.sin_addr));
  close(sockfd);
  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)
movl   $0x4,-0xa4(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121c <main+0x4c>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    124d <main+0x7d>
lea    0xde1(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1288 <main+0xb8>
lea    0xdb4(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   10a0 <fgets@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    1367 <main+0x197>
lea    0xcf0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0xb8(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0xb8(%rbp),%esi
mov    %rax,%rdx
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
cmp    $0x2,%edi
jne    12d7 <main+0x107>
mov    0x8(%rsi),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     12f6 <main+0x126>
mov    %rax,%rbx
mov    0x2deb(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ff <main+0x12f>
mov    %eax,%r14d
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     1308 <main+0x138>
mov    %eax,%ebx
mov    (%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xd97(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd22(%rip),%rdi
jmp    130f <main+0x13f>
lea    0xd27(%rip),%rdi
jmp    130f <main+0x13f>
lea    0xd39(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"uso: clienteUDP dirIPServidor\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [20 x i8] c"Teclea un mensaje: \00"
@stdin = global i32 0
@.str.4 = [7 x i8] c"sendto\00"
@.str.5 = [21 x i8] c"Envia %d bytes a %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.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
%10 = alloca i32
%11 = alloca [80 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %9
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_DGRAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 3
store i32 %37, i32* %38
%39 = call i32 @htons(i32 60000)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%42 = load %struct.hostent*, %struct.hostent** %9
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = inttoptr i64 %44 to %struct.in_addr*
%46 = bitcast %struct.in_addr* %41 to i8*
%47 = bitcast %struct.in_addr* %45 to i8*
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%49 = call i32 @memset(i32* %48, i8 signext 0, i32 8)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%51 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%52 = load i32, i32* @stdin
%53 = call i32 @fgets(i8* %51, i32 80, i32 %52)
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 %57
store i8 0, i8* %58
%59 = load i32, i32* %6
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%64 = call i32 @sendto(i32 %59, i8* %60, i32 %62, i32 0, %struct.sockaddr* %63, i32 4)
store i32 %64, i32* %10
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %36
%67 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %36
%70 = load i32, i32* %10
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%72 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i8* @inet_ntoa(i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %70, i8* %74)
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"uso: clienteUDP dirIPServidor\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [20 x i8] c"Teclea un mensaje: \00"
@stdin = global i32 0
@.str.4 = [7 x i8] c"sendto\00"
@.str.5 = [21 x i8] c"Envia %d bytes a %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [80 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %29, i32* %30
%31 = tail call i32 @htons(i32 60000)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i32*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%37 = load i32, i32* %35
store i32 %37, i32* %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%39 = call i32 @memset(i32* %38, i8 signext 0, i32 8)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %6, i32 80, i32 %41)
%43 = call i32 @strlen(i8* %6)
%44 = add nsw i32 %43, -1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i32 @strlen(i8* %6)
%48 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%49 = call i32 @sendto(i32 %23, i8* %6, i32 %47, i32 0, %struct.sockaddr* %48, i32 4)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %28
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %28
%55 = load i32, i32* %36
%56 = call i8* @inet_ntoa(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %49, i8* %56)
%58 = call i32 @close(i32 %23)
ret i32 0
}