// File: /workspace/github_c_makefile_star2_O1/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 0x2310
movl $0x90, %edx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x4b45
leaq -0x2c(%rbp), %rsi
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4b45
cmpl $0x1, -0x2c(%rbp)
jne 0x4a38
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4b45
cmpl $0x3, -0x2c(%rbp)
je 0x4b45
movq -0x98(%rbp), %rcx
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x22c0
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
xorl %r15d, %r15d
cmpl $0x0, -0x2c(%rbp)
jne 0x4b45
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4b3f
cmpl $0x3, -0x2c(%rbp)
je 0x4b3f
leaq -0xc8(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x481c
cmpl $-0x1, %eax
je 0x4b3f
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 0x3444
movq %r15, %rdi
callq 0x22e0
movl $0x20, %edx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x4b3f
leaq -0x30(%rbp), %rsi
movl $0x0, (%rsi)
xorl %r15d, %r15d
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4b3f
movslq -0x30(%rbp), %rax
leaq -0x38(%rbp), %r12
movq %rax, (%r12)
leaq -0xc8(%rbp), %r13
movl %r14d, %edi
movq %r13, %rsi
callq 0x2310
movq (%r12), %rsi
movl %r14d, %edi
xorl %edx, %edx
callq 0x2340
movq 0x30(%r13), %rcx
movl %ebx, %edi
movl %r14d, %esi
movq %r12, %rdx
callq 0x22c0
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
jmp 0x4b45
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop