#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 {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ cifrar(char *, char **, int);
int /*<<< orphan*/ descifrar(char *, char **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ stdout;
void fserver(int sockfd, struct sockaddr *pcli_addr, int maxclilen) {
  int tam, clilen;
  char mesg[2048];
  char msg_c[2048], msg_d[2048];
  for (;;) {
    clilen = maxclilen;
    tam = recvfrom(sockfd, mesg, 2048, 0, pcli_addr, (socklen_t *)&clilen);
    if (tam < 0) {
      perror("fserver: recvfrom error");
    }
    mesg[tam] = '\0';
    fprintf(stdout, "server:\n   mensaje original: %s", mesg);
    cifrar(mesg, &msg_c, tam);
    fprintf(stdout, "server:\n   mensaje cifrado: %s", msg_c);
    if (sendto(sockfd, msg_c, tam, 0, pcli_addr, clilen) != tam) {
      perror("fserver: sendto cifrado error");
    }
    descifrar(msg_c, &msg_d, tam);
    fprintf(stdout, "server:\n   mensaje descifrado: %s", msg_d);
    if (sendto(sockfd, mesg, tam, 0, pcli_addr, clilen) != tam) {
      perror("fserver: sendto descifrado error");
    }
  }
}


x86 assembly (clang, -O0):
<fserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1820,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x800,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b2 <fserver+0x52>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    -0x820(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x820(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <cifrar@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rdx
lea    0xe31(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1030 <sendto@plt>
cmp    -0x18(%rbp),%eax
je     123d <fserver+0xdd>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1820(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1080 <descifrar@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    -0x1820(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1030 <sendto@plt>
cmp    -0x18(%rbp),%eax
je     12a0 <fserver+0x140>
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
jmp    1175 <fserver+0x15>

x86 assembly (clang, -O2):
<fserver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1818,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,%rbx
mov    %edi,%r12d
lea    0x810(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
mov    %rbx,%r13
mov    %rbx,%r8
lea    0x8(%rsp),%r9
call   1060 <recvfrom@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11c8 <fserver+0x68>
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
movslq %r14d,%rax
movb   $0x0,0x810(%rsp,%rax,1)
mov    0x2e06(%rip),%rbx
mov    (%rbx),%edi
lea    0xe35(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    %rbp,%r15
mov    %rbp,%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <cifrar@plt>
mov    (%rbx),%edi
lea    0xe2e(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    0x8(%rsp),%r9d
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r13,%rbx
mov    %r13,%r8
call   1030 <sendto@plt>
cmp    %r14d,%eax
je     123e <fserver+0xde>
lea    0xe1e(%rip),%rdi
call   1070 <perror@plt>
lea    0x10(%rsp),%rdi
lea    0x1010(%rsp),%r13
mov    %r13,%rsi
mov    %r14d,%edx
call   1080 <descifrar@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
mov    %r13,%rdx
call   1050 <fprintf@plt>
mov    0x8(%rsp),%r9d
mov    %r12d,%edi
mov    %r15,%rbp
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1030 <sendto@plt>
cmp    %r14d,%eax
je     1190 <fserver+0x30>
lea    0xdfe(%rip),%rdi
call   1070 <perror@plt>
jmp    1190 <fserver+0x30>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"fserver: recvfrom error\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"server:\0A mensaje original: %s\00"
@.str.2 = [31 x i8] c"server:\0A mensaje cifrado: %s\00"
@.str.3 = [30 x i8] c"fserver: sendto cifrado error\00"
@.str.4 = [34 x i8] c"server:\0A mensaje descifrado: %s\00"
@.str.5 = [33 x i8] c"fserver: sendto descifrado error\00"
define void @fserver(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2048 x i8]
%10 = alloca [2048 x i8]
%11 = alloca [2048 x i8]
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
br label %12
12: ; preds = %64, %3
%13 = load i32, i32* %6
store i32 %13, i32* %8
%14 = load i32, i32* %4
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%16 = load %struct.sockaddr*, %struct.sockaddr** %5
%17 = call i32 @recvfrom(i32 %14, i8* %15, i32 2048, i32 0, %struct.sockaddr* %16, i32* %8)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* @stdout
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%30 = bitcast [2048 x i8]* %10 to i8**
%31 = load i32, i32* %7
%32 = call i32 @cifrar(i8* %29, i8** %30, i32 %31)
%33 = load i32, i32* @stdout
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %4
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%38 = load i32, i32* %7
%39 = load %struct.sockaddr*, %struct.sockaddr** %5
%40 = load i32, i32* %8
%41 = call i32 @sendto(i32 %36, i8* %37, i32 %38, i32 0, %struct.sockaddr* %39, i32 %40)
%42 = load i32, i32* %7
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %22
%45 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %22
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%48 = bitcast [2048 x i8]* %11 to i8**
%49 = load i32, i32* %7
%50 = call i32 @descifrar(i8* %47, i8** %48, i32 %49)
%51 = load i32, i32* @stdout
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %4
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%56 = load i32, i32* %7
%57 = load %struct.sockaddr*, %struct.sockaddr** %5
%58 = load i32, i32* %8
%59 = call i32 @sendto(i32 %54, i8* %55, i32 %56, i32 0, %struct.sockaddr* %57, i32 %58)
%60 = load i32, i32* %7
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %46
%63 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %46
br label %12
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"fserver: recvfrom error\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"server:\0A mensaje original: %s\00"
@.str.2 = [31 x i8] c"server:\0A mensaje cifrado: %s\00"
@.str.3 = [30 x i8] c"fserver: sendto cifrado error\00"
@.str.4 = [34 x i8] c"server:\0A mensaje descifrado: %s\00"
@.str.5 = [33 x i8] c"fserver: sendto descifrado error\00"
define void @fserver(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%12 = bitcast [2048 x i8]* %6 to i8**
%13 = bitcast [2048 x i8]* %7 to i8**
br label %14
14: ; preds = %41, %3
store i32 %2, i32* %4
%15 = call i32 @recvfrom(i32 %0, i8* %9, i32 2048, i32 0, %struct.sockaddr* %1, i32* %4)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = sext i32 %15 to i64
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* @stdout
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%24 = call i32 @cifrar(i8* %9, i8** %12, i32 %15)
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%27 = load i32, i32* %4
%28 = call i32 @sendto(i32 %0, i8* %10, i32 %15, i32 0, %struct.sockaddr* %1, i32 %27)
%29 = icmp eq i32 %28, %15
br i1 %29, label %32, label %30
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %19
%33 = call i32 @descifrar(i8* %10, i8** %13, i32 %15)
%34 = load i32, i32* @stdout
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%36 = load i32, i32* %4
%37 = call i32 @sendto(i32 %0, i8* %9, i32 %15, i32 0, %struct.sockaddr* %1, i32 %36)
%38 = icmp eq i32 %37, %15
br i1 %38, label %41, label %39
39: ; preds = %32
%40 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %39, %32
br label %14
}