// File: /workspace/github_c_makefile_star2_O3/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
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x4afa
leaq -0x2c(%rbp), %rsi
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4afa
movl -0x2c(%rbp), %eax
cmpl $0x1, %eax
jne 0x49f0
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4afa
cmpl $0x3, -0x2c(%rbp)
je 0x4afa
movq -0x98(%rbp), %rcx
movl %ebx, %edi
movl %r14d, %esi
xorl %edx, %edx
callq 0x22d0
leaq -0x2c(%rbp), %r15
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20a0
movl (%r15), %eax
xorl %r15d, %r15d
testl %eax, %eax
jne 0x4afa
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x4af4
cmpl $0x3, -0x2c(%rbp)
je 0x4af4
leaq -0xc8(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x47cc
cmpl $-0x1, %eax
je 0x4af4
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 0x33fc
movq %r15, %rdi
callq 0x22f0
movl $0x20, %edx
movl %ebx, %edi
movq %r15, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x4af4
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 0x4af4
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
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
jmp 0x4afa
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