// File: /workspace/github_c_makefile_star2_O1/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 0x2240
leaq -0xc8(%rbp), %rsi
movl %ebx, %edi
movl $0x90, %edx
callq 0x4154
movq %r15, %rdi
xorl %esi, %esi
callq 0x2270
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
leaq -0x2c(%rbp), %rsi
cmpl $-0x1, %eax
je 0x432b
movl $0x0, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl -0xb0(%rbp), %edx
movq %r15, %rdi
movl $0xc2, %esi
xorl %eax, %eax
callq 0x20f0
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x43c6
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
leaq -0xc8(%rbp), %r13
movl %r14d, %edi
movq %r13, %rsi
callq 0x2280
movl $0x90, %edx
movl %ebx, %edi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x20c0
leaq -0x120(%rbp), %r12
xorl %eax, %eax
movb %al, 0x20(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movl %r14d, -0x34(%rbp)
leaq -0xf0(%rbp), %r14
movb %al, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movl 0x30(%r13), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2ac0
movl %ebx, %edi
movq %r14, %rsi
movl $0x20, %edx
callq 0x3e58
movq %r12, %rdi
callq 0x2240
movq %r14, %rdi
callq 0x2240
movl $0x0, -0x30(%rbp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x21e0
testl %eax, %eax
jne 0x42eb
movl -0x98(%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 -0x98(%rbp), %edx
movl (%r14), %ecx
movl %ebx, %edi
movl -0x34(%rbp), %r14d
movl %r14d, %esi
callq 0x4000
movl %r14d, %edi
callq 0x22c0
leaq -0x2c(%rbp), %rsi
movl $0x4, (%rsi)
jmp 0x4397
movl $0x1, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl -0xb0(%rbp), %edx
movq %r15, %rdi
movl $0xc2, %esi
xorl %eax, %eax
callq 0x20f0
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x43da
leaq -0x2c(%rbp), %rsi
movl $0x2, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
movl -0x98(%rbp), %edx
movl %ebx, %edi
movl %r14d, %esi
callq 0x3eb0
movl %r14d, %edi
callq 0x22c0
movl $0x4, %eax
leaq -0x2c(%rbp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20c0
cmpl $-0x1, %r14d
je 0x43af
xorl %eax, %eax
jmp 0x43b4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2120
leaq -0x2c(%rbp), %rsi
movl $0x3, (%rsi)
jmp 0x4397
movq %r15, %rdi
callq 0x2120
movl $0x3, %eax
jmp 0x4391
nopl (%rax)