#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 {
  double st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double, double, int);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, double);
int /*<<< orphan*/ stat(char const *, struct stat *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void sendFile(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 = open(fileName, O_RDONLY);
  if (fileDescriptor != -1) {
    stat(fileName, &st);
    fileSize = st.st_size;
    remainData = fileSize;
    snprintf(buffer, 512, "%g", fileSize);
    write(socketDescriptor, buffer, strlen(buffer));
    read(socketDescriptor, buffer, 512);
    do {
      readBytes = read(fileDescriptor, buffer, 512);
      totalBytes += readBytes;
      remainData -= readBytes;
      percent = (totalBytes * 100 / fileSize);
      if (percent % 5 == 0 && percent > oldpercent) {
        oldpercent = percent;
        if (fileSize < 20000000)
          printf("[SERVIDOR] %g%gKB ENVIADOS (%d%%)\n", totalBytes / 1024,
                 fileSize / 1024, percent);
        else
          printf("[SERVIDOR] %g/%gMB ENVIADOS (%d%%)\n",
                 (totalBytes / 1024) / 1024, (fileSize / 1024) / 1024, percent);
      }
      if (readBytes > 0)
        write(socketDescriptor, buffer, readBytes);
    } while (readBytes > 0);
    puts("[SERVIDOR] TERMINADO DE LEER Y ENVIAR EL ARCHIVO");
    close(fileDescriptor);
    close(socketDescriptor);
  } else
    puts("[SERVIDOR] NO SE HA PODIDO ABRIR EL ARCHIVO");
}


x86 assembly (clang, -O0):
<sendFile>:
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    0x2e1c(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0xffffffff,-0x21c(%rbp)
je     142d <sendFile+0x29d>
mov    -0x8(%rbp),%rdi
lea    -0x218(%rbp),%rsi
call   10a0 <stat@plt>
movsd  -0x218(%rbp),%xmm0
ff
movsd  %xmm0,-0x230(%rbp)
ff
movsd  -0x230(%rbp),%xmm0
ff
movsd  %xmm0,-0x240(%rbp)
ff
lea    -0x210(%rbp),%rdi
movsd  -0x230(%rbp),%xmm0
ff
mov    $0x200,%esi
lea    0xde7(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    -0x21c(%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  0xd26(%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    13d5 <sendFile+0x245>
mov    -0x224(%rbp),%eax
cmp    -0x228(%rbp),%eax
jle    13d5 <sendFile+0x245>
mov    -0x224(%rbp),%eax
mov    %eax,-0x228(%rbp)
movsd  0xcd7(%rip),%xmm0
ucomisd -0x230(%rbp),%xmm0
ff
jbe    137e <sendFile+0x1ee>
movsd  -0x238(%rbp),%xmm0
ff
movsd  0xcc1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x230(%rbp),%xmm1
ff
movsd  0xcad(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x224(%rbp),%esi
lea    0xca7(%rip),%rdi
call   1060 <printf@plt>
jmp    13d0 <sendFile+0x240>
movsd  -0x238(%rbp),%xmm0
ff
movsd  0xc82(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xc76(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x230(%rbp),%xmm1
ff
movsd  0xc62(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xc56(%rip),%xmm2
divsd  %xmm2,%xmm1
mov    -0x224(%rbp),%esi
lea    0xc73(%rip),%rdi
call   1060 <printf@plt>
jmp    13d5 <sendFile+0x245>
cmpl   $0x0,-0x220(%rbp)
jle    13f7 <sendFile+0x267>
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x220(%rbp),%edx
call   1040 <write@plt>
jmp    13fc <sendFile+0x26c>
cmpl   $0x0,-0x220(%rbp)
jg     1281 <sendFile+0xf1>
lea    0xc52(%rip),%rdi
call   1030 <puts@plt>
mov    -0x21c(%rbp),%edi
call   1080 <close@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
jmp    1439 <sendFile+0x2a9>
lea    0xc5f(%rip),%rdi
call   1030 <puts@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1340 <sendFile+0x1b0>
mov    %eax,%r13d
lea    0x28(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <stat@plt>
movsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe37(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
movsd  0xde0(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xd8b(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%r15d
imul   $0xcccccccd,%r15d,%eax
add    $0x19999999,%eax
cmp    $0x33333332,%eax
ja     12fc <sendFile+0x16c>
cmp    %r15d,%r12d
movsd  0xd5a(%rip),%xmm1
jge    12fc <sendFile+0x16c>
movsd  0xd60(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
jbe    12e0 <sendFile+0x150>
lea    0xd52(%rip),%rdi
movsd  0x20(%rsp),%xmm1
jmp    12f1 <sendFile+0x161>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm0
lea    0xd53(%rip),%rdi
movsd  0x18(%rsp),%xmm1
mov    %r15d,%esi
call   1060 <printf@plt>
mov    %r15d,%r12d
test   %ebp,%ebp
jle    1312 <sendFile+0x182>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
jmp    1250 <sendFile+0xc0>
lea    0xd49(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4c(%rip),%rdi
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

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