#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, 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;
int strlen(char *);
void fclient(int socketfd, struct sockaddr *pserv_addr, int servlen,
             char *fname) {
  int tam;
  char sendline[512], recvline[512 + 1];
  FILE *ftext, *fcipher, *fdecipher;
  ftext = fopen(fname, "r");
  fgets(sendline, 512, ftext);
  tam = strlen(sendline);
  printf("mensaje original: %s\n", sendline);
  if (sendto(socketfd, sendline, tam, 0, pserv_addr, servlen) != tam) {
    perror("fclient: sendto mensaje error");
  }
  tam = recvfrom(socketfd, recvline, 512, 0, (struct sockaddr *)0,
                 (socklen_t *)0);
  if (tam < 0) {
    perror("fclient: recvfrom error");
  }
  recvline[tam - 1] = '\0';
  fprintf(stdout, "client:\n   mensaje cifrado: %s\n\n", recvline);
  fcipher = fopen("cifrado.txt", "w");
  fprintf(fcipher, "%s", recvline);
  tam = recvfrom(socketfd, recvline, 512, 0, (struct sockaddr *)0,
                 (socklen_t *)0);
  if (tam < 0) {
    perror("fclient: recvfrom error");
  }
  recvline[tam - 1] = '\0';
  fprintf(stdout, "client:\n   mensaje descifrado: %s\n\n", recvline);
  fdecipher = fopen("descifrado.txt", "w");
  fprintf(fdecipher, "%s", recvline);
  fclose(ftext);
  fclose(fcipher);
  fclose(fdecipher);
}


x86 assembly (clang, -O0):
<fclient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x448(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x448(%rbp),%rdx
mov    $0x200,%esi
call   1070 <fgets@plt>
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    -0x230(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    -0x24(%rbp),%eax
je     122b <fclient+0x9b>
lea    0xdf0(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x4(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1262 <fclient+0xd2>
lea    0xdd7(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x440(%rbp,%rax,1)
mov    0x2d67(%rip),%rax
mov    (%rax),%rdi
lea    -0x440(%rbp),%rdx
lea    0xdc2(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe03(%rip),%rdi
lea    0xdd0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rdi
lea    -0x440(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12fa <fclient+0x16a>
lea    0xd3f(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x440(%rbp,%rax,1)
mov    0x2ccf(%rip),%rax
mov    (%rax),%rdi
lea    -0x440(%rbp),%rdx
lea    0xd50(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd68(%rip),%rdi
lea    0xd38(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rdi
lea    -0x440(%rbp),%rdx
lea    0xd19(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x448(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x450(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x458(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fclient>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r12d
mov    %rsi,%r13
mov    %edi,%r15d
lea    0xe71(%rip),%rsi
mov    %rcx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe10(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    %r12d,%r9d
call   1070 <sendto@plt>
cmp    %ebp,%eax
jne    130a <fclient+0x16a>
lea    0x200(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
js     131b <fclient+0x17b>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x2d92(%rip),%r13
mov    0x0(%r13),%rdi
lea    0xdf3(%rip),%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
lea    0xe2e(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
js     132c <fclient+0x18c>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x0(%r13),%rdi
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
lea    0xdcd(%rip),%rdi
lea    0xda0(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd05(%rip),%rdi
call   10c0 <perror@plt>
jmp    1215 <fclient+0x75>
lea    0xd12(%rip),%rdi
call   10c0 <perror@plt>
jmp    123f <fclient+0x9f>
lea    0xd01(%rip),%rdi
call   10c0 <perror@plt>
jmp    12a4 <fclient+0x104>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"mensaje original: %s\0A\00"
@.str.2 = [30 x i8] c"fclient: sendto mensaje error\00"
@.str.3 = [24 x i8] c"fclient: recvfrom error\00"
@stdout = global i32* null
@.str.4 = [33 x i8] c"client:\0A mensaje cifrado: %s\0A\0A\00"
@.str.5 = [12 x i8] c"cifrado.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [36 x i8] c"client:\0A mensaje descifrado: %s\0A\0A\00"
@.str.9 = [15 x i8] c"descifrado.txt\00"
define void @fclient(i32 %0, %struct.sockaddr* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca [513 x i8]
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
store i32 %0, i32* %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%15 = load i8*, i8** %8
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %12
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%18 = load i32*, i32** %12
%19 = call i32 @fgets(i8* %17, i32 512, i32* %18)
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %9
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %5
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%26 = load i32, i32* %9
%27 = load %struct.sockaddr*, %struct.sockaddr** %6
%28 = load i32, i32* %7
%29 = call i32 @sendto(i32 %24, i8* %25, i32 %26, i32 0, %struct.sockaddr* %27, i32 %28)
%30 = load i32, i32* %9
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %4
%33 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %4
%35 = load i32, i32* %5
%36 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%37 = call i32 @recvfrom(i32 %35, i8* %36, i32 512, i32 0, %struct.sockaddr* null, i32* null)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
%43 = load i32, i32* %9
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 %45
store i8 0, i8* %46
%47 = load i32*, i32** @stdout
%48 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%49 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %50, i32** %13
%51 = load i32*, i32** %13
%52 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%53 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %5
%55 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%56 = call i32 @recvfrom(i32 %54, i8* %55, i32 512, i32 0, %struct.sockaddr* null, i32* null)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %42
%60 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %42
%62 = load i32, i32* %9
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 %64
store i8 0, i8* %65
%66 = load i32*, i32** @stdout
%67 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%68 = call i32 @fprintf(i32* %66, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %67)
%69 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %69, i32** %14
%70 = load i32*, i32** %14
%71 = getelementptr inbounds [513 x i8], [513 x i8]* %11, i64 0, i64 0
%72 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = load i32*, i32** %12
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %13
%76 = call i32 @fclose(i32* %75)
%77 = load i32*, i32** %14
%78 = call i32 @fclose(i32* %77)
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"mensaje original: %s\0A\00"
@.str.2 = [30 x i8] c"fclient: sendto mensaje error\00"
@.str.3 = [24 x i8] c"fclient: recvfrom error\00"
@stdout = global i32* null
@.str.4 = [33 x i8] c"client:\0A mensaje cifrado: %s\0A\0A\00"
@.str.5 = [12 x i8] c"cifrado.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.8 = [36 x i8] c"client:\0A mensaje descifrado: %s\0A\0A\00"
@.str.9 = [15 x i8] c"descifrado.txt\00"
define void @fclient(i32 %0, %struct.sockaddr* %1, i32 %2, i8* nocapture %3) {
%5 = alloca [512 x i8]
%6 = alloca [513 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @fgets(i8* %7, i32 512, i32* %9)
%11 = call i32 @strlen(i8* %7)
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%13 = call i32 @sendto(i32 %0, i8* %7, i32 %11, i32 0, %struct.sockaddr* %1, i32 %2)
%14 = icmp eq i32 %13, %11
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = call i32 @recvfrom(i32 %0, i8* %8, i32 512, i32 0, %struct.sockaddr* null, i32* null)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = add nsw i32 %18, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32*, i32** @stdout
%27 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%28 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @fputs(i8* %8, i32* %28)
%30 = call i32 @recvfrom(i32 %0, i8* %8, i32 512, i32 0, %struct.sockaddr* null, i32* null)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %22
%35 = add nsw i32 %30, -1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i32*, i32** @stdout
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%40 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @fputs(i8* %8, i32* %40)
%42 = call i32 @fclose(i32* %9)
%43 = call i32 @fclose(i32* %28)
%44 = call i32 @fclose(i32* %40)
ret void
}