// File: /workspace/github_c_makefile_star2_O1/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 0x2a9c
movq %rsi, %rbx
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
cmpl $-0x1, %eax
je 0x2aa3
movl %eax, %r15d
movq 0x8(%rbx), %rdi
callq 0x2160
leaq -0x50(%rbp), %r14
movl %eax, 0x4(%r14)
movq 0x10(%rbx), %rdi
callq 0x2250
rolw $0x8, %ax
movw %ax, 0x2(%r14)
movw $0x2, (%r14)
movl %r15d, %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2110
cmpl $-0x1, %eax
je 0x2aac
movl %r15d, -0x2c(%rbp)
leaq -0x40(%rbp), %rbx
movl $0x0, (%rbx)
movl $0x1, %r12d
leaq 0x29e1(%rip), %r14      # 0x5023
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x43ec
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2170
movl %eax, %r13d
movq 0x4975(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
cmpl $-0x1, %r13d
je 0x2a87
movl -0x40(%rbp), %eax
cmpl $0x2, %eax
je 0x268c
cmpl $0x1, %eax
jne 0x2699
movl -0x2c(%rbp), %edi
callq 0x440c
jmp 0x26a5
movl -0x2c(%rbp), %edi
callq 0x2ef4
movl %eax, %r12d
jmp 0x26a5
leaq 0x2986(%rip), %rdi      # 0x5026
callq 0x2240
testl %r12d, %r12d
jne 0x2645
leaq -0x3c(%rbp), %rsi
movl $0x4, %edx
movl -0x2c(%rbp), %ebx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x2070
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %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 0x294c(%rip), %r14      # 0x5044
leaq 0x29b1(%rip), %r12      # 0x50b0
movl $0x736c, %ebx           # imm = 0x736C
movl $0x69646b6d, %r15d      # imm = 0x69646B6D
movl $0x0, -0x34(%rbp)
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
xorl %eax, %eax
callq 0x2030
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2170
movl -0x10e0(%rbp), %eax
xorl %ebx, %eax
movzbl -0x10de(%rbp), %ecx
orw %ax, %cx
je 0x27fe
cmpl $0x647770, -0x10e0(%rbp) # imm = 0x647770
je 0x283b
movl -0x10e0(%rbp), %eax
xorl %r15d, %eax
movzwl -0x10dc(%rbp), %ecx
xorl $0x72, %ecx
orl %eax, %ecx
je 0x284c
movl -0x10e0(%rbp), %eax
movl $0x6463, %ecx           # imm = 0x6463
xorl %ecx, %eax
movzbl -0x10de(%rbp), %ecx
orw %ax, %cx
jne 0x288d
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2170
movq 0x481e(%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 0x280e
leaq -0x20e0(%rbp), %rdi
callq 0x2080
cmpq $0x1, %rax
jne 0x280e
leaq 0x286e(%rip), %rdi      # 0x5062
callq 0x2240
jmp 0x2711
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edi
callq 0x3074
jmp 0x2711
movl -0x2c(%rbp), %edi
movq %r13, %rsi
leaq -0x20e0(%rbp), %r15
movq %r15, %rdx
leaq -0x30(%rbp), %rcx
callq 0x23fc
testl %eax, %eax
je 0x297f
leaq 0x282e(%rip), %rdi      # 0x5064
jmp 0x2982
leaq -0x20e0(%rbp), %rdi
callq 0x2240
jmp 0x2711
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2170
movq 0x4769(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movl -0x30(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x2c(%rbp), %edi
movq %r13, %rcx
callq 0x3bd8
jmp 0x2711
movl -0x10e0(%rbp), %eax
movl $0x73747570, %ecx       # imm = 0x73747570
xorl %ecx, %eax
movzbl -0x10dc(%rbp), %ecx
orl %eax, %ecx
je 0x2992
movl -0x10e0(%rbp), %eax
movl $0x73746567, %ecx       # imm = 0x73746567
xorl %ecx, %eax
movzbl -0x10dc(%rbp), %ecx
orl %eax, %ecx
jne 0x2711
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
leaq 0x27a5(%rip), %rdi      # 0x5080
leaq -0x8e0(%rbp), %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2170
movq 0x46e5(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2140
cmpl $-0x1, %eax
je 0x2a45
movl -0xc8(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x2a37
movq %r13, %rdi
movl $0x800, %esi            # imm = 0x800
callq 0x2bd8
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
movl %eax, -0x38(%rbp)
movl %eax, %edi
leaq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x2110
cmpl $-0x1, %eax
je 0x2a69
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %edi
leaq -0x8e0(%rbp), %rsi
movq %r13, %rdx
callq 0x2dae
jmp 0x2a33
movq %r15, %rdi
callq 0x2240
movl $0x69646b6d, %r15d      # imm = 0x69646B6D
jmp 0x2711
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2170
movq 0x4623(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x2040
movq %r13, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2140
cmpl $-0x1, %eax
je 0x2a45
movl -0xc8(%rbp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
movq %r13, %rdi
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x29f4
movl $0x1000, %esi           # imm = 0x1000
callq 0x2bd8
jmp 0x29f9
callq 0x2e84
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
movl %eax, -0x38(%rbp)
movl %eax, %edi
leaq -0x50(%rbp), %rsi
movl $0x10, %edx
callq 0x2110
cmpl $-0x1, %eax
je 0x2a69
movl -0x3c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %edi
movq %r13, %rsi
callq 0x3cf0
xorl %eax, %eax
jmp 0x2a56
leaq 0x2647(%rip), %rdi      # 0x5085
callq 0x2240
jmp 0x2a51
leaq 0x25c7(%rip), %rdi      # 0x5013
callq 0x2120
movl $0x5, %eax
testl %eax, %eax
je 0x2711
cmpl $0x5, %eax
je 0x2711
jmp 0x2a83
leaq 0x25ab(%rip), %rdi      # 0x501b
callq 0x2120
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movl $0x1, %eax
jmp 0x2a56
movl -0x34(%rbp), %r15d
movl %r15d, %eax
addq $0x20b8, %rsp           # imm = 0x20B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x22e0
jmp 0x2ab8
leaq 0x256a(%rip), %rdi      # 0x5014
jmp 0x2ab3
leaq 0x2568(%rip), %rdi      # 0x501b
callq 0x2120
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2a8a
nop