// File: /workspace/github_c_makefile_star2_O3/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 0x2250
leaq -0xc0(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x4118
movq %r15, %rdi
xorl %esi, %esi
callq 0x2280
leaq -0x2c(%rbp), %rsi
cmpl $-0x1, %eax
je 0x42f8
movl $0x0, (%rsi)
movl $0x4, %edx
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 0x438d
movl %eax, %r12d
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
leaq -0xc0(%rbp), %r14
movl %r12d, %edi
movq %r14, %rsi
callq 0x2290
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 0x2a8c
movl %ebx, %edi
movq %r14, %rsi
movl $0x20, %edx
callq 0x3e10
movq %r13, %rdi
callq 0x2250
movq %r14, %rdi
callq 0x2250
movl $0x0, -0x30(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x21f0
testl %eax, %eax
jne 0x42a8
movl -0x90(%rbp), %eax
movl %eax, -0x30(%rbp)
leaq -0x30(%rbp), %r14
movl $0x4, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl -0x90(%rbp), %edx
movl (%r14), %ecx
movl %ebx, %edi
movl %r12d, %esi
callq 0x3fc0
movl %r12d, %edi
callq 0x22d0
leaq -0x2c(%rbp), %rsi
movl $0x4, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
xorl %r14d, %r14d
jmp 0x4378
movl $0x1, (%rsi)
xorl %r14d, %r14d
movl $0x4, %edx
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 0x438d
movl %eax, %r12d
leaq -0x2c(%rbp), %r15
movl $0x2, (%r15)
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl -0x90(%rbp), %edx
movl %ebx, %edi
movl %r12d, %esi
callq 0x3e68
movl %r12d, %edi
callq 0x22d0
movl $0x4, (%r15)
movl $0x4, %edx
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20c0
movl %r14d, %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)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x4378
nopl (%rax)