// File: /workspace/github_c_makefile_star2_O2/VeeeectorPan[P]MyNetdisk/SourceFile/send_file.c
// Function: send_file
int send_file(int client_fd,int file_fd)
{
    struct stat st;
    fstat(file_fd,&st);
    int ret = send(client_fd,&st,sizeof(struct stat),MSG_NOSIGNAL);
    if(ret == -1)
        return -1;
    int ctl_num = -1;
    ret = recv(client_fd,&ctl_num,sizeof(int),0);
    if(ret == 0)
        return -1;
    if(ctl_num == GETS_NOT_EXIST)
    {
        ret = recv(client_fd,&ctl_num,sizeof(int),0);
        if(ret == 0 || ctl_num == GETS_STOP_RECV)
            return -1;
        sendfile(client_fd,file_fd,NULL,st.st_size);
        recv(client_fd,&ctl_num,sizeof(int),0);
    }
    if(ctl_num == GETS_EXIST)
    {
        ret = recv(client_fd,&ctl_num,sizeof(int),0);
        if(ret == 0 || ctl_num == GETS_STOP_RECV)
            return -1;
        ret = recv_client_all(client_fd,&st,sizeof(struct stat)); 
        if(ret == -1) return -1;
        char md5[33] = {0};
        compute_file_md5_2(file_fd,md5,st.st_size);
        puts(md5);
        ret = send(client_fd,md5,32,MSG_NOSIGNAL);
        if(ret == -1) return -1;
        int offset_bak = 0;
        ret = recv(client_fd,&offset_bak,sizeof(int),0);
        if(ret == 0) return -1;
        off_t offset = offset_bak;
        fstat(file_fd,&st);
        lseek(file_fd,offset,SEEK_SET);
        sendfile(client_fd,file_fd,&offset,st.st_size);
        recv(client_fd,&ctl_num,sizeof(int),0);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %esi, %r14d
movl %edi, %ebx
leaq -0xc8(%rbp), %r15
movl %esi, %edi
movq %r15, %rsi
callq 0x2320
movl $0x90, %edx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
jne 0x4770
pushq $-0x1
popq %r15
jmp 0x48de
leaq -0x2c(%rbp), %rsi
orl $-0x1, (%rsi)
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
pushq $-0x1
popq %r12
testl %eax, %eax
je 0x48db
movl -0x2c(%rbp), %eax
cmpl $0x1, %eax
jne 0x47e2
leaq -0x2c(%rbp), %rsi
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x48db
cmpl $0x3, -0x2c(%rbp)
je 0x48db
movq -0x98(%rbp), %rcx
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x22d0
leaq -0x2c(%rbp), %r15
pushq $0x4
popq %rdx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20a0
movl (%r15), %eax
xorl %r15d, %r15d
testl %eax, %eax
jne 0x48de
leaq -0x2c(%rbp), %rsi
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x48db
cmpl $0x3, -0x2c(%rbp)
je 0x48db
leaq -0xc8(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x45cc
cmpl $-0x1, %eax
je 0x48db
xorps %xmm0, %xmm0
leaq -0xf0(%rbp), %r15
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movb $0x0, 0x20(%r15)
movl -0x98(%rbp), %edx
movl %r14d, %edi
movq %r15, %rsi
callq 0x3348
movq %r15, %rdi
callq 0x22f0
pushq $0x20
popq %rdx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x48db
leaq -0x30(%rbp), %rsi
andl $0x0, (%rsi)
pushq $0x4
popq %rdx
xorl %r15d, %r15d
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x48db
movslq -0x30(%rbp), %r12
leaq -0x38(%rbp), %rax
movq %r12, (%rax)
leaq -0xc8(%rbp), %r13
movl %r14d, %edi
movq %r13, %rsi
callq 0x2320
movl %r14d, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2350
movq 0x30(%r13), %rcx
movl %ebx, %edi
movl %r14d, %esi
leaq -0x38(%rbp), %rdx
callq 0x22d0
leaq -0x2c(%rbp), %rsi
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
jmp 0x48de
movl %r12d, %r15d
movl %r15d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop