// File: /workspace/github_c_makefile_star2_O2/VeeeectorPan[P]MyNetdisk/clientSrc/recv_server_file.c
// Function: recv_server_file
int recv_server_file(int sock_fd,char* path)
{
    puts(path);
    struct stat st;
    recv_n_bytes(sock_fd,&st,sizeof(struct stat));
    int ret = access(path,F_OK);
    int ctl_num = -1;
    if(ret == -1)
    {
        ctl_num = GETS_NOT_EXIST;
        send(sock_fd,&ctl_num,sizeof(int),0);
        int file_fd = open(path,O_RDWR|O_CREAT|O_EXCL,st.st_mode); 
        if(file_fd == -1)
        {
            perror(path);
            ctl_num = GETS_STOP_RECV;
            send(sock_fd,&ctl_num,sizeof(int),0);
            return -1;
        }
        else
        {
            ctl_num = GETS_START_RECV;
            send(sock_fd,&ctl_num,sizeof(int),0);
            recv_file(sock_fd,file_fd,st.st_size);
            close(file_fd);
            ctl_num = GETS_OVER;
            send(sock_fd,&ctl_num,sizeof(int),0);
        }

    }
    else
    {
        ctl_num = GETS_EXIST;
        send(sock_fd,&ctl_num,sizeof(int),0);
        int file_fd = open(path,O_RDWR|O_CREAT|O_EXCL,st.st_mode); 
        if(file_fd == -1)
        {
            perror(path);
            ctl_num = GETS_STOP_RECV;
            send(sock_fd,&ctl_num,sizeof(int),0);
            return -1;
        }
        else
        {
            ctl_num = GETS_START_RECV;
            send(sock_fd,&ctl_num,sizeof(int),0);
            fstat(file_fd,&st);
            send(sock_fd,&st,sizeof(struct stat),0);
            char md5[33] = {0};
            char server_md5[33] = {0};
            compute_file_md5(path,md5,st.st_size);
            recv_client_all(sock_fd,server_md5,32);
            puts(md5);
            puts(server_md5);
            int offset = 0;
            if(strcmp(md5,server_md5) == 0)
            {
                offset = st.st_size;
            }
            send(sock_fd,&offset,sizeof(int),0);
            recv_file_from_offset(sock_fd,file_fd,st.st_size,offset);
            close(file_fd);
            ctl_num = GETS_OVER;
            send(sock_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 $0xf8, %rsp
movq %rsi, %r15
movl %edi, %ebx
movq %rsi, %rdi
callq 0x2260
leaq -0xc0(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x3f14
movq %r15, %rdi
xorl %esi, %esi
callq 0x2290
leaq -0x2c(%rbp), %rsi
cmpl $-0x1, %eax
je 0x40e1
andl $0x0, (%rsi)
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl -0xa8(%rbp), %edx
movq %r15, %rdi
movl $0xc2, %esi
xorl %eax, %eax
callq 0x2100
cmpl $-0x1, %eax
je 0x4174
movl %eax, %r12d
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
leaq -0xc0(%rbp), %r14
movl %r12d, %edi
movq %r14, %rsi
callq 0x22a0
movl $0x90, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq -0x120(%rbp), %r13
xorl %eax, %eax
movb %al, 0x20(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
leaq -0xf0(%rbp), %r14
movb %al, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq -0xc0(%rbp), %rax
movl 0x30(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2a60
pushq $0x20
popq %rdx
movl %ebx, %edi
movq %r14, %rsi
callq 0x3c68
movq %r13, %rdi
callq 0x2260
movq %r14, %rdi
callq 0x2260
andl $0x0, -0x30(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x2200
testl %eax, %eax
jne 0x4094
movl -0x90(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq -0x30(%rbp), %r14
pushq $0x4
popq %r15
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl -0x90(%rbp), %edx
movl (%r14), %ecx
movl %ebx, %edi
movl %r12d, %esi
callq 0x3de8
movl %r12d, %edi
callq 0x22e0
leaq -0x2c(%rbp), %rsi
movl $0x4, (%rsi)
movl %ebx, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x20c0
xorl %r13d, %r13d
jmp 0x415f
movl $0x1, (%rsi)
pushq $0x4
popq %rdx
xorl %r13d, %r13d
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl -0xa8(%rbp), %edx
movq %r15, %rdi
movl $0xc2, %esi
xorl %eax, %eax
callq 0x2100
cmpl $-0x1, %eax
je 0x4174
movl %eax, %r14d
leaq -0x2c(%rbp), %r15
movl $0x2, (%r15)
pushq $0x4
popq %r12
movl %ebx, %edi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl -0x90(%rbp), %edx
movl %ebx, %edi
movl %r14d, %esi
callq 0x3cc0
movl %r14d, %edi
callq 0x22e0
movl $0x4, (%r15)
movl %ebx, %edi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x20c0
movl %r13d, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2130
leaq -0x2c(%rbp), %rsi
movl $0x3, (%rsi)
pushq $0x4
popq %rdx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
pushq $-0x1
popq %r13
jmp 0x415f