// File: /workspace/github_c_makefile_star2_O0/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
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %edi
leaq -0xa0(%rbp), %rsi
callq 0x2330
movl -0x8(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl $0x90, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
jne 0x5ee4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
movl $0xffffffff, -0xa8(%rbp) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jne 0x5f1f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
cmpl $0x1, -0xa8(%rbp)
jne 0x5f8b
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0x5f56
cmpl $0x3, -0xa8(%rbp)
jne 0x5f62
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
movq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x22e0
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
cmpl $0x0, -0xa8(%rbp)
jne 0x60fb
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0x5fc6
cmpl $0x3, -0xa8(%rbp)
jne 0x5fd2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
movl -0x8(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl $0x90, %edx
callq 0x5cb0
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
jne 0x6001
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
movl $0x21, %edx
callq 0x2140
movl -0xc(%rbp), %edi
leaq -0xd0(%rbp), %rsi
movq -0x70(%rbp), %rax
movl %eax, %edx
callq 0x3ae0
leaq -0xd0(%rbp), %rdi
callq 0x2300
movl -0x8(%rbp), %edi
leaq -0xd0(%rbp), %rsi
movl $0x20, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2110
movl %eax, -0xa4(%rbp)
cmpl $-0x1, -0xa4(%rbp)
jne 0x6069
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
movl $0x0, -0xd4(%rbp)
movl -0x8(%rbp), %edi
leaq -0xd4(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jne 0x60a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6102
movslq -0xd4(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl -0xc(%rbp), %edi
leaq -0xa0(%rbp), %rsi
callq 0x2330
movl -0xc(%rbp), %edi
movq -0xe0(%rbp), %rsi
xorl %edx, %edx
callq 0x2360
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
movq -0x70(%rbp), %rcx
leaq -0xe0(%rbp), %rdx
callq 0x22e0
movl -0x8(%rbp), %edi
leaq -0xa8(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x20b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop