// File: /workspace/github_c_makefile_star2_O3/VeeeectorPan[P]MyNetdisk/clientSrc/client.c
// Function: main
int main(int argc,char* argv[])
{
    // link to server
    ARGS_CHECK(argc,3);
    int sfd = socket(AF_INET,SOCK_STREAM,0);
    ERROR_CHECK(sfd,-1,"socket");
    struct sockaddr_in server_addr;
    server_addr.sin_addr.s_addr = inet_addr(argv[1]);
    server_addr.sin_port = htons(atoi(argv[2]));
    server_addr.sin_family = AF_INET;
    int ret = connect(sfd,(struct sockaddr*)&server_addr,sizeof(server_addr));
    ERROR_CHECK(ret,-1,"connect");

    int user_select = 0;
    int flag = 1;
    while(flag)
    {
        show_menu1();
        ret = scanf("%d",&user_select);
        rewind(stdin);
        if(ret == -1)
            return 0;
        switch(user_select)
        {
        case 1:
            sign_up(sfd);
            break;
        case 2:
            flag = login(sfd);
            break;
        default:
            puts("Enter error operation number!");
            break;
        }
    }
    int user_id;
    recv(sfd,&user_id,sizeof(int),0);
    int file_id;
    recv(sfd,&file_id,sizeof(int),0);
    flag = 1;
    char buf[4096];
    char path[4096] = {0};
    path[0] = '/';
    while(flag)
    {
        memset(buf,0,sizeof(buf));
        printf("Enter a command: ");
        scanf("%s",buf);
        if(strcmp(buf,"ls") == 0)
        {
            ls(sfd,file_id);
        }
        else if(strcmp(buf,"pwd") == 0)
        {
            puts(path);
        }
        else if(strcmp(buf,"mkdir") == 0)
        {
            memset(buf,0,sizeof(buf));
            scanf("%s",buf);
            rewind(stdin);
            my_mkdir(sfd,file_id,user_id,buf);
        }
        else if(strcmp(buf,"cd") == 0)
        {
            memset(buf,0,sizeof(buf));
            scanf("%s",buf);
            rewind(stdin);
            if(strcmp(buf,"..") == 0 && strlen(path) == 1)
            {
                puts("/");
                continue;

            }
            ret = cd(sfd,buf,path,&file_id);
            if(ret == 0)
            {
                puts(path);
            }
            else
            {
                puts("no such directory");
            }
        }
        else if(strcmp(buf,"puts") == 0)
        {
            memset(buf,0,sizeof(buf));
            scanf("%s",buf);
            rewind(stdin);
            struct stat st_stat;
            ret = stat(buf,&st_stat);
            if(ret == -1)
            {
                perror("");
                continue;
            }
            if((st_stat.st_mode & S_IFMT) == S_IFDIR)
            {
                get_absolute_path(buf,sizeof(buf));
            }
            else
            {
                link_path(buf);
            }
            int newsfd = socket(AF_INET,SOCK_STREAM,0);
            ERROR_CHECK(sfd,-1,"socket");
            int ret = connect(newsfd,(struct sockaddr*)&server_addr,sizeof(server_addr));
            ERROR_CHECK(ret,-1,"connect");
            put(newsfd,buf,user_id,file_id);
        }
        else if(strcmp(buf,"gets") == 0)
        {
            memset(buf,0,sizeof(buf));
            scanf("%s%s",buf + sizeof(buf) / 2,buf);
            rewind(stdin);
            struct stat st_stat;
            ret = stat(buf,&st_stat);
            if(ret == -1)
            {
                perror("");
                continue;
            }
            if((st_stat.st_mode & S_IFMT) != S_IFDIR)
            {
                puts("Not effective directory!"); 
                continue;
            }
            get_absolute_path(buf,sizeof(buf)/ 2);
            int newsfd = socket(AF_INET,SOCK_STREAM,0);
            ERROR_CHECK(sfd,-1,"socket");
            int ret = connect(newsfd,(struct sockaddr*)&server_addr,sizeof(server_addr));
            ERROR_CHECK(ret,-1,"connect");
            gets(newsfd,buf + sizeof(buf)/2,buf,file_id);
        }

    }
    close(sfd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20b8, %rsp           # imm = 0x20B8
cmpl $0x3, %edi
jne 0x2a5b
movq %rsi, %r14
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
cmpl $-0x1, %eax
je 0x2a62
movl %eax, %ebx
movq 0x8(%r14), %rdi
callq 0x2170
leaq -0x48(%rbp), %r15
movl %eax, 0x4(%r15)
movq 0x10(%r14), %rdi
callq 0x2260
rolw $0x8, %ax
movw %ax, 0x2(%r15)
movw $0x2, (%r15)
movl %ebx, -0x2c(%rbp)
movl %ebx, %edi
movq %r15, %rsi
movl $0x10, %edx
callq 0x2120
cmpl $-0x1, %eax
je 0x2a52
leaq -0x38(%rbp), %rbx
movl $0x0, (%rbx)
movl $0x1, %r13d
leaq 0x29d5(%rip), %r15      # 0x5020
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x43b8
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2180
movl %eax, %r14d
movq 0x496c(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
cmpl $-0x1, %r14d
je 0x2a74
movl -0x38(%rbp), %eax
cmpl $0x2, %eax
je 0x2695
cmpl $0x1, %eax
jne 0x26a2
movl -0x2c(%rbp), %edi
callq 0x43d8
jmp 0x26ae
movl -0x2c(%rbp), %edi
callq 0x2ec0
movl %eax, %r13d
jmp 0x26ae
leaq 0x297a(%rip), %rdi      # 0x5023
callq 0x2250
testl %r13d, %r13d
jne 0x264e
leaq -0x34(%rbp), %rsi
movl $0x4, %edx
movl -0x2c(%rbp), %r15d
movl %r15d, %edi
xorl %ecx, %ecx
callq 0x2070
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
movl %r15d, %edi
xorl %ecx, %ecx
callq 0x2070
leaq -0x20e0(%rbp), %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movb $0x2f, (%rbx)
leaq -0x10e0(%rbp), %r13
leaq 0x293d(%rip), %r12      # 0x5041
leaq 0x29a5(%rip), %r14      # 0x50b0
movl $0x736c, %ebx           # imm = 0x736C
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2180
movl -0x10e0(%rbp), %eax
xorl %ebx, %eax
movzbl -0x10de(%rbp), %ecx
orw %ax, %cx
je 0x2764
cmpl $0x647770, -0x10e0(%rbp) # imm = 0x647770
jne 0x2771
leaq -0x20e0(%rbp), %rdi
callq 0x2250
jmp 0x2710
movl -0x30(%rbp), %esi
movl %r15d, %edi
callq 0x3040
jmp 0x2710
movl -0x10e0(%rbp), %eax
movl $0x69646b6d, %ecx       # imm = 0x69646B6D
xorl %ecx, %eax
movzwl -0x10dc(%rbp), %ecx
xorl $0x72, %ecx
orl %eax, %ecx
je 0x28a3
movl -0x10e0(%rbp), %eax
movl $0x6463, %ecx           # imm = 0x6463
xorl %ecx, %eax
movzbl -0x10de(%rbp), %ecx
orw %ax, %cx
je 0x28e4
movl -0x10e0(%rbp), %eax
movl $0x73747570, %ecx       # imm = 0x73747570
xorl %ecx, %eax
movzbl -0x10dc(%rbp), %ecx
orl %eax, %ecx
je 0x2953
movl -0x10e0(%rbp), %eax
movl $0x73746567, %ecx       # imm = 0x73746567
xorl %ecx, %eax
movzbl -0x10dc(%rbp), %ecx
orl %eax, %ecx
jne 0x2710
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
leaq 0x2885(%rip), %rdi      # 0x5080
leaq -0x8e0(%rbp), %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2180
movq 0x47c5(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2150
cmpl $-0x1, %eax
je 0x2a0e
movl -0xc0(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x29fd
movq %r13, %rdi
movl $0x800, %esi            # imm = 0x800
callq 0x2ba4
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
movl %eax, %r15d
movl %eax, %edi
leaq -0x48(%rbp), %rsi
movl $0x10, %edx
callq 0x2120
cmpl $-0x1, %eax
je 0x2a52
movl -0x30(%rbp), %ecx
movl %r15d, %edi
leaq -0x8e0(%rbp), %rsi
movq %r13, %rdx
callq 0x2d7a
movl -0x2c(%rbp), %r15d
jmp 0x2710
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2180
movq 0x4712(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movl %r15d, %edi
movq %r13, %rcx
callq 0x3b9c
jmp 0x2710
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2180
movq 0x46d1(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movl -0x10e0(%rbp), %eax
movl $0x2e2e, %ecx           # imm = 0x2E2E
xorl %ecx, %eax
movzbl -0x10de(%rbp), %ecx
orw %ax, %cx
jne 0x2a1f
leaq -0x20e0(%rbp), %rdi
callq 0x2080
cmpq $0x1, %rax
jne 0x2a1f
leaq 0x2719(%rip), %rdi      # 0x5062
callq 0x2250
jmp 0x2710
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2180
movq 0x4662(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2150
cmpl $-0x1, %eax
je 0x2a0e
movl -0xc0(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
movq %r13, %rdi
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x29b5
movl $0x1000, %esi           # imm = 0x1000
callq 0x2ba4
jmp 0x29ba
callq 0x2e50
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
movl %eax, %r15d
movl %eax, %edi
leaq -0x48(%rbp), %rsi
movl $0x10, %edx
callq 0x2120
cmpl $-0x1, %eax
je 0x2a52
movl -0x34(%rbp), %edx
movl -0x30(%rbp), %ecx
movl %r15d, %edi
movq %r13, %rsi
callq 0x3cb4
movl -0x2c(%rbp), %r15d
jmp 0x2710
leaq 0x2681(%rip), %rdi      # 0x5085
callq 0x2250
jmp 0x2710
leaq 0x25fb(%rip), %rdi      # 0x5010
callq 0x2130
jmp 0x2710
movl %r15d, %edi
movq %r13, %rsi
leaq -0x20e0(%rbp), %rbx
movq %rbx, %rdx
leaq -0x30(%rbp), %rcx
callq 0x240c
testl %eax, %eax
je 0x2a45
leaq 0x2621(%rip), %rdi      # 0x5064
jmp 0x2a48
movq %rbx, %rdi
callq 0x2250
jmp 0x270b
leaq 0x25bf(%rip), %rdi      # 0x5018
jmp 0x2a69
callq 0x22f0
jmp 0x2a6e
leaq 0x25a8(%rip), %rdi      # 0x5011
callq 0x2130
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x20b8, %rsp           # imm = 0x20B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)