// File: /workspace/github_c_makefile_star2_O2/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 0x267e
movq %rsi, %r14
pushq $0x2
popq %rdi
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %edx, %edx
callq 0x2060
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x269f
movq 0x8(%r14), %rdi
callq 0x2170
leaq -0x48(%rbp), %r15
movl %eax, 0x4(%r15)
movq 0x10(%r14), %rdi
callq 0x2270
rolw $0x8, %ax
movw %ax, 0x2(%r15)
movw $0x2, (%r15)
pushq $0x10
popq %rdx
movl -0x2c(%rbp), %edi
movq %r15, %rsi
callq 0x2120
cmpl $-0x1, %eax
je 0x2a3a
leaq -0x38(%rbp), %r14
andl $0x0, (%r14)
leaq 0x2a0e(%rip), %r15      # 0x5020
xorl %r13d, %r13d
testl %ebx, %ebx
je 0x26ab
xorl %eax, %eax
callq 0x4198
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2190
movl %eax, %r12d
movq 0x499d(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
cmpl $-0x1, %r12d
je 0x2a4a
movl -0x38(%rbp), %eax
cmpl $0x1, %eax
je 0x2668
cmpl $0x2, %eax
je 0x2672
leaq 0x29c2(%rip), %rdi      # 0x5023
callq 0x2260
jmp 0x2615
movl -0x2c(%rbp), %edi
callq 0x41b8
jmp 0x2615
movl -0x2c(%rbp), %edi
callq 0x2e64
movl %eax, %ebx
jmp 0x2615
movq 0x495b(%rip), %rax      # 0x6fe0
movq (%rax), %rcx
leaq 0x2975(%rip), %rdi      # 0x5004
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
callq 0x22d0
jmp 0x2a46
leaq 0x296b(%rip), %rdi      # 0x5011
jmp 0x2a41
leaq -0x34(%rbp), %rsi
pushq $0x4
popq %rbx
movl -0x2c(%rbp), %r14d
movl %r14d, %edi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2070
leaq -0x30(%rbp), %rsi
movl %r14d, %edi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2070
leaq -0x10e0(%rbp), %rbx
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movb $0x2f, (%rbx)
leaq -0x20e0(%rbp), %r13
leaq 0x2946(%rip), %r15      # 0x5041
leaq 0x29ae(%rip), %r14      # 0x50b0
leaq 0x294a(%rip), %rbx      # 0x5053
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r15, %rdi
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2190
movq %r13, %rdi
movq %rbx, %rsi
pushq $0x3
popq %rdx
callq 0x2180
testl %eax, %eax
je 0x275b
cmpl $0x647770, -0x20e0(%rbp) # imm = 0x647770
jne 0x2768
leaq -0x10e0(%rbp), %rdi
callq 0x2260
jmp 0x2709
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edi
callq 0x2fe0
jmp 0x2709
movq %r13, %rdi
leaq 0x28e4(%rip), %rsi      # 0x5056
pushq $0x6
popq %rdx
callq 0x2180
testl %eax, %eax
je 0x288c
movq %r13, %rdi
leaq 0x28d0(%rip), %rsi      # 0x505c
pushq $0x3
popq %r12
movq %r12, %rdx
callq 0x2180
testl %eax, %eax
je 0x28cd
movq %r13, %rdi
leaq 0x28cc(%rip), %rsi      # 0x5076
pushq $0x5
popq %r12
movq %r12, %rdx
callq 0x2180
testl %eax, %eax
je 0x2939
movq %r13, %rdi
leaq 0x28b3(%rip), %rsi      # 0x507b
movq %r12, %rdx
callq 0x2180
testl %eax, %eax
jne 0x2709
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
leaq 0x2892(%rip), %rdi      # 0x5080
leaq -0x18e0(%rbp), %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2190
movq 0x47d2(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2150
cmpl $-0x1, %eax
je 0x29ea
movl -0xc0(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x29d9
movq %r13, %rdi
movl $0x800, %esi            # imm = 0x800
callq 0x2b74
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x2060
movl %eax, %r12d
movl %eax, %edi
leaq -0x48(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x2120
cmpl $-0x1, %eax
je 0x2a3a
movl -0x30(%rbp), %ecx
movl %r12d, %edi
leaq -0x18e0(%rbp), %rsi
movq %r13, %rdx
callq 0x2d21
jmp 0x2709
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2190
movq 0x4729(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x2c(%rbp), %edi
movq %r13, %rcx
callq 0x3a04
jmp 0x2709
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2190
movq 0x46e8(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq 0x275d(%rip), %rsi      # 0x505f
movq %r12, %rdx
callq 0x2180
testl %eax, %eax
jne 0x29fb
leaq -0x10e0(%rbp), %rdi
callq 0x2080
cmpq $0x1, %rax
jne 0x29fb
leaq 0x2733(%rip), %rdi      # 0x5062
callq 0x2260
jmp 0x2709
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2190
movq 0x467c(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2150
cmpl $-0x1, %eax
je 0x29ea
movl -0xc0(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
movq %r13, %rdi
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x299b
movl $0x1000, %esi           # imm = 0x1000
callq 0x2b74
jmp 0x29a0
callq 0x2df4
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x2060
movl %eax, %r12d
movl %eax, %edi
leaq -0x48(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x2120
cmpl $-0x1, %eax
je 0x2a3a
movl -0x34(%rbp), %edx
movl -0x30(%rbp), %ecx
movl %r12d, %edi
movq %r13, %rsi
callq 0x3b16
jmp 0x2709
leaq 0x26a5(%rip), %rdi      # 0x5085
callq 0x2260
jmp 0x2709
leaq 0x261f(%rip), %rdi      # 0x5010
callq 0x2130
jmp 0x2709
movl -0x2c(%rbp), %edi
movq %r14, %rbx
movq %r15, %r14
movq %r13, %rsi
leaq -0x10e0(%rbp), %r15
movq %r15, %rdx
leaq -0x30(%rbp), %rcx
callq 0x23ec
testl %eax, %eax
je 0x2a27
leaq 0x263f(%rip), %rdi      # 0x5064
jmp 0x2a2a
movq %r15, %rdi
callq 0x2260
movq %r14, %r15
movq %rbx, %r14
jmp 0x2702
leaq 0x25d7(%rip), %rdi      # 0x5018
callq 0x2130
pushq $-0x1
popq %r13
movl %r13d, %eax
addq $0x20b8, %rsp           # imm = 0x20B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop