#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 stat {
  int dummy;
};

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ close(int);
int creat(char const *, int);
int /*<<< orphan*/ printf(char *, double, double, int);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void receiveFile(const char fileName[], int socketDescriptor) {
  char buffer[512];
  struct stat st;
  int fileDescriptor, readBytes, percent, oldpercent;
  double fileSize, totalBytes, remainData;
  totalBytes = percent = oldpercent = 0;
  fileDescriptor = creat(fileName, 0666);
  if (fileDescriptor != -1) {
    read(socketDescriptor, buffer, 512);
    write(socketDescriptor, "1", strlen("1"));
    fileSize = atof(buffer);
    remainData = fileSize;
    do {
      readBytes = read(socketDescriptor, buffer, 512);
      totalBytes += readBytes;
      remainData -= readBytes;
      percent = (totalBytes * 100 / fileSize);
      if (percent % 5 == 0 && percent > oldpercent) {
        oldpercent = percent;
        if (fileSize < 20000000)
          printf("[CLIENTE] %g/%gKB RECIBIDOS (%d%%)\n", totalBytes / 1024,
                 fileSize / 1024, percent);
        else
          printf("[CLIENTE] %g/%gMB RECIBIDOS (%d%%)\n",
                 (totalBytes / 1024) / 1024, (fileSize / 1024) / 1024, percent);
      }
      if (readBytes > 0)
        write(fileDescriptor, buffer, readBytes);
    } while (readBytes > 0);
    puts("[CLIENTE] TERMINADO DE RECIBIR Y ESCRIBIR EL ARCHIVO");
    close(fileDescriptor);
    close(socketDescriptor);
  } else
    puts("[CLIENTE] NO SE HA PODIDO CREAR EL ARCHIVO");
}


x86 assembly (clang, -O0):
<receiveFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x228(%rbp)
movl   $0x0,-0x224(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x238(%rbp)
ff
mov    -0x8(%rbp),%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0xffffffff,-0x21c(%rbp)
je     13df <receiveFile+0x25f>
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x244(%rbp)
lea    0xe22(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    %eax,%edx
lea    0xe0e(%rip),%rsi
call   1050 <write@plt>
lea    -0x210(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x230(%rbp)
ff
movsd  -0x230(%rbp),%xmm0
ff
movsd  %xmm0,-0x240(%rbp)
ff
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x220(%rbp)
cvtsi2sdl -0x220(%rbp),%xmm0
ff
addsd  -0x238(%rbp),%xmm0
ff
movsd  %xmm0,-0x238(%rbp)
ff
cvtsi2sdl -0x220(%rbp),%xmm1
ff
movsd  -0x240(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x240(%rbp)
ff
movsd  0xd77(%rip),%xmm0
mulsd  -0x238(%rbp),%xmm0
ff
divsd  -0x230(%rbp),%xmm0
ff
cvttsd2si %xmm0,%eax
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1384 <receiveFile+0x204>
mov    -0x224(%rbp),%eax
cmp    -0x228(%rbp),%eax
jle    1384 <receiveFile+0x204>
mov    -0x224(%rbp),%eax
mov    %eax,-0x228(%rbp)
movsd  0xd28(%rip),%xmm0
ucomisd -0x230(%rbp),%xmm0
ff
jbe    132d <receiveFile+0x1ad>
movsd  -0x238(%rbp),%xmm0
ff
movsd  0xd12(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x230(%rbp),%xmm1
ff
movsd  0xcfe(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x224(%rbp),%esi
lea    0xcf7(%rip),%rdi
call   1070 <printf@plt>
jmp    137f <receiveFile+0x1ff>
movsd  -0x238(%rbp),%xmm0
ff
movsd  0xcd3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xcc7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x230(%rbp),%xmm1
ff
movsd  0xcb3(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xca7(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x224(%rbp),%esi
lea    0xcc4(%rip),%rdi
call   1070 <printf@plt>
jmp    1384 <receiveFile+0x204>
cmpl   $0x0,-0x220(%rbp)
jle    13a9 <receiveFile+0x229>
mov    -0x21c(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x220(%rbp),%edx
call   1050 <write@plt>
jmp    13ae <receiveFile+0x22e>
cmpl   $0x0,-0x220(%rbp)
jg     1233 <receiveFile+0xb3>
lea    0xca0(%rip),%rdi
call   1030 <puts@plt>
mov    -0x21c(%rbp),%edi
call   1080 <close@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    13eb <receiveFile+0x26b>
lea    0xcb1(%rip),%rdi
call   1030 <puts@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %esi,%r14d
mov    $0x1b6,%esi
call   10a0 <creat@plt>
cmp    $0xffffffff,%eax
je     12ff <receiveFile+0x17f>
mov    %eax,%r13d
lea    0x20(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
lea    0xe52(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
call   1040 <atof@plt>
movsd  0xe15(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mulsd  0xdbd(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%r15d
imul   $0xcccccccd,%r15d,%eax
add    $0x19999999,%eax
cmp    $0x33333332,%eax
ja     12bc <receiveFile+0x13c>
cmp    %r15d,%r12d
movsd  0xd8c(%rip),%xmm1
jge    12bc <receiveFile+0x13c>
movsd  0xd92(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
jbe    12a0 <receiveFile+0x120>
lea    0xd84(%rip),%rdi
movsd  0x18(%rsp),%xmm1
jmp    12b1 <receiveFile+0x131>
xchg   %ax,%ax
mulsd  %xmm1,%xmm0
lea    0xd93(%rip),%rdi
movsd  0x10(%rsp),%xmm1
mov    %r15d,%esi
call   1070 <printf@plt>
mov    %r15d,%r12d
test   %ebp,%ebp
jle    12d2 <receiveFile+0x152>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
jmp    1220 <receiveFile+0xa0>
lea    0xd89(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,%edi
call   1080 <close@plt>
mov    %r14d,%edi
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <close@plt>
lea    0xd91(%rip),%rdi
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"1\00"
@.str.1 = [36 x i8] c"[CLIENTE] %g/%gKB RECIBIDOS (%d%%)\0A\00"
@.str.2 = [36 x i8] c"[CLIENTE] %g/%gMB RECIBIDOS (%d%%)\0A\00"
@.str.3 = [53 x i8] c"[CLIENTE] TERMINADO DE RECIBIR Y ESCRIBIR EL ARCHIVO\00"
@.str.4 = [43 x i8] c"[CLIENTE] NO SE HA PODIDO CREAR EL ARCHIVO\00"
define void @receiveFile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %10
store i32 0, i32* %9
store double 0.000000e+00, double* %12
%14 = load i8*, i8** %3
%15 = call i32 @creat(i8* %14, i32 438)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %91
18: ; preds = %2
%19 = load i32, i32* %4
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 512)
%22 = load i32, i32* %4
%23 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @write(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%26 = call double @atof(i8* %25)
store double %26, double* %11
%27 = load double, double* %11
store double %27, double* %13
br label %28
28: ; preds = %82, %18
%29 = load i32, i32* %4
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 512)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to double
%34 = load double, double* %12
%35 = fadd double %34, %33
store double %35, double* %12
%36 = load i32, i32* %8
%37 = sitofp i32 %36 to double
%38 = load double, double* %13
%39 = fsub double %38, %37
store double %39, double* %13
%40 = load double, double* %12
%41 = fmul double %40, 1.000000e+02
%42 = load double, double* %11
%43 = fdiv double %41, %42
%44 = fptosi double %43 to i32
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = srem i32 %45, 5
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %73
48: ; preds = %28
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %73
52: ; preds = %48
%53 = load i32, i32* %9
store i32 %53, i32* %10
%54 = load double, double* %11
%55 = fcmp olt double %54, 2.000000e+07
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load double, double* %12
%58 = fdiv double %57, 1.024000e+03
%59 = load double, double* %11
%60 = fdiv double %59, 1.024000e+03
%61 = load i32, i32* %9
%62 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %58, double %60, i32 %61)
br label %72
63: ; preds = %52
%64 = load double, double* %12
%65 = fdiv double %64, 1.024000e+03
%66 = fdiv double %65, 1.024000e+03
%67 = load double, double* %11
%68 = fdiv double %67, 1.024000e+03
%69 = fdiv double %68, 1.024000e+03
%70 = load i32, i32* %9
%71 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %66, double %69, i32 %70)
br label %72
72: ; preds = %63, %56
br label %73
73: ; preds = %72, %48, %28
%74 = load i32, i32* %8
%75 = icmp sgt i32 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %73
%77 = load i32, i32* %7
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%79 = load i32, i32* %8
%80 = call i32 @write(i32 %77, i8* %78, i32 %79)
br label %81
81: ; preds = %76, %73
br label %82
82: ; preds = %81
%83 = load i32, i32* %8
%84 = icmp sgt i32 %83, 0
br i1 %84, label %28, label %85
85: ; preds = %82
%86 = call i32 @puts(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
%89 = load i32, i32* %4
%90 = call i32 @close(i32 %89)
br label %93
91: ; preds = %2
%92 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %93
93: ; preds = %91, %85
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [36 x i8] c"[CLIENTE] %g/%gKB RECIBIDOS (%d%%)\0A\00"
@.str.2 = [36 x i8] c"[CLIENTE] %g/%gMB RECIBIDOS (%d%%)\0A\00"
@.str.3 = [53 x i8] c"[CLIENTE] TERMINADO DE RECIBIR Y ESCRIBIR EL ARCHIVO\00"
@.str.4 = [43 x i8] c"[CLIENTE] NO SE HA PODIDO CREAR EL ARCHIVO\00"
define void @receiveFile(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @creat(i8* %0, i32 438)
%6 = icmp eq i32 %5, -1
br i1 %6, label %44, label %7
7: ; preds = %2
%8 = call i32 @read(i32 %1, i8* %4, i32 512)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call double @atof(i8* %4)
%12 = fcmp olt double %11, 2.000000e+07
%13 = fmul double %11, 0x3F50000000000000
%14 = fmul double %13, 0x3F50000000000000
br label %15
15: ; preds = %38, %7
%16 = phi i32 [ 0, %7 ], [ %36, %38 ]
%17 = phi double [ 0.000000e+00, %7 ], [ %20, %38 ]
%18 = call i32 @read(i32 %1, i8* %4, i32 512)
%19 = sitofp i32 %18 to double
%20 = fadd double %17, %19
%21 = fmul double %20, 1.000000e+02
%22 = fdiv double %21, %11
%23 = fptosi double %22 to i32
%24 = srem i32 %23, 5
%25 = icmp eq i32 %24, 0
%26 = icmp slt i32 %16, %23
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %35
28: ; preds = %15
%29 = fmul double %20, 0x3F50000000000000
br i1 %12, label %30, label %32
30: ; preds = %28
%31 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %29, double %13, i32 %23)
br label %35
32: ; preds = %28
%33 = fmul double %29, 0x3F50000000000000
%34 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %33, double %14, i32 %23)
br label %35
35: ; preds = %30, %32, %15
%36 = phi i32 [ %23, %30 ], [ %23, %32 ], [ %16, %15 ]
%37 = icmp sgt i32 %18, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @write(i32 %5, i8* %4, i32 %18)
br label %15
40: ; preds = %35
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%42 = tail call i32 @close(i32 %5)
%43 = tail call i32 @close(i32 %1)
br label %46
44: ; preds = %2
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
ret void
}