#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ aMayusculas(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  int sockfd;
  struct sockaddr_in yo;
  struct sockaddr_in cliente;
  int addr_len, numbytes;
  char buffer[80];
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  yo.sin_family = AF_INET;
  yo.sin_port = htons(4950);
  yo.sin_addr.s_addr = INADDR_ANY;
  memset(&(yo.sin_zero), '\0', 8);
  if (bind(sockfd, (struct sockaddr *)&yo, sizeof(struct sockaddr)) == -1) {
    perror("Error en el bind");
    exit(1);
  }
  addr_len = sizeof(struct sockaddr);
  printf("Servidor escuchando en el puerto 5000\n");
  do {
    if ((numbytes = recvfrom(sockfd, buffer, 80 - 1, 0,
                             (struct sockaddr *)&cliente, &addr_len)) == -1) {
      perror("Error en el recvfrom");
      exit(1);
    }
    buffer[numbytes] = '\0';
    printf("Recibo de %s/%d: %s\n", inet_ntoa(cliente.sin_addr),
           ntohs(cliente.sin_port), buffer);
    aMayusculas(buffer);
    if ((numbytes = sendto(sockfd, buffer, strlen(buffer), 0,
                           (struct sockaddr *)&cliente,
                           sizeof(struct sockaddr))) == -1) {
      perror("sendto");
      exit(1);
    }
  } while (1);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    122d <main+0x4d>
lea    0xde2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1356,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1296 <main+0xb6>
lea    0xd80(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movl   $0x4,-0x2c(%rbp)
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x4f,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    12e8 <main+0x108>
lea    0xd66(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movslq -0x30(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x24(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x98(%rbp)
mov    -0x28(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
lea    -0x80(%rbp),%rcx
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
call   10f0 <aMayusculas@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    138b <main+0x1ab>
lea    0xced(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1390 <main+0x1b0>
mov    $0x1,%al
test   $0x1,%al
jne    12ab <main+0xcb>
jmp    139f <main+0x1bf>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2df0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    121b <main+0x3b>
lea    0xdea(%rip),%rdi
jmp    1328 <main+0x148>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1356,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1273 <main+0x93>
lea    0xd99(%rip),%rdi
jmp    1328 <main+0x148>
movl   $0x4,0xc(%rsp)
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xd90(%rip),%r12
nopl   (%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x4f,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1321 <main+0x141>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    0x24(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10f0 <aMayusculas@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1090 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0xc0>
lea    0xd23(%rip),%rdi
jmp    1328 <main+0x148>
lea    0xcf0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"Error en el bind\00"
@.str.2 = [39 x i8] c"Servidor escuchando en el puerto 5000\0A\00"
@.str.3 = [21 x i8] c"Error en el recvfrom\00"
@.str.4 = [21 x i8] c"Recibo de %s/%d: %s\0A\00"
@.str.5 = [7 x i8] c"sendto\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca [80 x i8]
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 3
store i32 %16, i32* %17
%18 = call i32 @htons(i32 4950)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
%24 = call i32 @memset(i32* %23, i8 signext 0, i32 8)
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %15
store i32 4, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %69, %32
%35 = load i32, i32* %2
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i32 @recvfrom(i32 %35, i8* %36, i32 79, i32 0, %struct.sockaddr* %37, i32* %5)
store i32 %38, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %34
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @inet_ntoa(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @ntohs(i32 %52)
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %50, i32 %53, i8* %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%57 = call i32 @aMayusculas(i8* %56)
%58 = load i32, i32* %2
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%63 = call i32 @sendto(i32 %58, i8* %59, i32 %61, i32 0, %struct.sockaddr* %62, i32 4)
store i32 %63, i32* %6
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %43
%66 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %43
br label %69
69: ; preds = %68
br i1 true, label %34, label %70
70: ; preds = %69
%71 = load i32, i32* %2
%72 = call i32 @close(i32 %71)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"Error en el bind\00"
@.str.3 = [21 x i8] c"Error en el recvfrom\00"
@.str.4 = [21 x i8] c"Recibo de %s/%d: %s\0A\00"
@.str.5 = [7 x i8] c"sendto\00"
@str = [38 x i8] c"Servidor escuchando en el puerto 5000\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [80 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 4950)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
%24 = call i32 @memset(i32* %23, i8 signext 0, i32 8)
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = call i32 @bind(i32 %11, %struct.sockaddr* %25, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %16
store i32 4, i32* %3
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%33 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %36
36: ; preds = %42, %31
%37 = call i32 @recvfrom(i32 %11, i8* %8, i32 79, i32 0, %struct.sockaddr* %33, i32* %3)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %36
%43 = sext i32 %37 to i64
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %34
%46 = call i8* @inet_ntoa(i32 %45)
%47 = load i32, i32* %35
%48 = call i32 @ntohs(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %46, i32 %48, i8* %8)
%50 = call i32 @aMayusculas(i8* %8)
%51 = call i32 @strlen(i8* %8)
%52 = call i32 @sendto(i32 %11, i8* %8, i32 %51, i32 0, %struct.sockaddr* %33, i32 4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %36
54: ; preds = %42
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
}