// File: /workspace/github_c_makefile_star2_O0/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
subq $0x2190, %rsp           # imm = 0x2190
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x2613
movq 0x59ea(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
leaq 0x3a07(%rip), %rsi      # 0x6007
movb $0x0, %al
callq 0x21f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x2645
leaq 0x39e0(%rip), %rdi      # 0x6014
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2170
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2260
movzwl %ax, %edi
callq 0x2040
movw %ax, -0x22(%rbp)
movw $0x2, -0x24(%rbp)
movl -0x14(%rbp), %edi
leaq -0x24(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x2120
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
jne 0x26ae
leaq 0x397e(%rip), %rdi      # 0x601b
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl $0x0, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x2748
movb $0x0, %al
callq 0x5110
leaq 0x394f(%rip), %rdi      # 0x6023
leaq -0x34(%rbp), %rsi
movb $0x0, %al
callq 0x2180
movl %eax, -0x28(%rbp)
movq 0x58ef(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2050
cmpl $-0x1, -0x28(%rbp)
jne 0x2703
movl $0x0, -0x4(%rbp)
jmp 0x2c1c
movl -0x34(%rbp), %eax
movl %eax, -0x2184(%rbp)
subl $0x1, %eax
je 0x2720
jmp 0x2713
movl -0x2184(%rbp), %eax
subl $0x2, %eax
je 0x272a
jmp 0x2737
movl -0x14(%rbp), %edi
callq 0x5130
jmp 0x2743
movl -0x14(%rbp), %edi
callq 0x31a0
movl %eax, -0x38(%rbp)
jmp 0x2743
leaq 0x38e8(%rip), %rdi      # 0x6026
callq 0x2250
jmp 0x26bc
movl -0x14(%rbp), %edi
leaq -0x3c(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movl -0x14(%rbp), %edi
leaq -0x40(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2080
movl $0x1, -0x38(%rbp)
leaq -0x2040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
movb $0x2f, -0x2040(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x2c14
leaq -0x1040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq 0x3891(%rip), %rdi      # 0x6044
movb $0x0, %al
callq 0x2030
leaq -0x1040(%rbp), %rsi
leaq 0x38ec(%rip), %rdi      # 0x60b4
movb $0x0, %al
callq 0x2180
leaq -0x1040(%rbp), %rdi
leaq 0x3879(%rip), %rsi      # 0x6056
callq 0x21e0
cmpl $0x0, %eax
jne 0x27f7
movl -0x14(%rbp), %edi
movl -0x40(%rbp), %esi
callq 0x3390
jmp 0x2c0f
leaq -0x1040(%rbp), %rdi
leaq 0x3854(%rip), %rsi      # 0x6059
callq 0x21e0
cmpl $0x0, %eax
jne 0x2820
leaq -0x2040(%rbp), %rdi
callq 0x2250
jmp 0x2c0d
leaq -0x1040(%rbp), %rdi
leaq 0x382f(%rip), %rsi      # 0x605d
callq 0x21e0
cmpl $0x0, %eax
jne 0x2889
leaq -0x1040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq -0x1040(%rbp), %rsi
leaq 0x385b(%rip), %rdi      # 0x60b4
movb $0x0, %al
callq 0x2180
movq 0x5771(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2050
movl -0x14(%rbp), %edi
movl -0x40(%rbp), %esi
movl -0x3c(%rbp), %edx
leaq -0x1040(%rbp), %rcx
callq 0x4770
jmp 0x2c0b
leaq -0x1040(%rbp), %rdi
leaq 0x37cc(%rip), %rsi      # 0x6063
callq 0x21e0
cmpl $0x0, %eax
jne 0x2959
leaq -0x1040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq -0x1040(%rbp), %rsi
leaq 0x37ee(%rip), %rdi      # 0x60b4
movb $0x0, %al
callq 0x2180
movq 0x5704(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2050
leaq -0x1040(%rbp), %rdi
leaq 0x371a(%rip), %rsi      # 0x6004
callq 0x21e0
cmpl $0x0, %eax
jne 0x2917
leaq -0x2040(%rbp), %rdi
callq 0x2090
cmpq $0x1, %rax
jne 0x2917
leaq 0x3759(%rip), %rdi      # 0x6066
callq 0x2250
jmp 0x278f
movl -0x14(%rbp), %edi
leaq -0x1040(%rbp), %rsi
leaq -0x2040(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x23d0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x2948
leaq -0x2040(%rbp), %rdi
callq 0x2250
jmp 0x2954
leaq 0x3719(%rip), %rdi      # 0x6068
callq 0x2250
jmp 0x2c09
leaq -0x1040(%rbp), %rdi
leaq 0x3713(%rip), %rsi      # 0x607a
callq 0x21e0
cmpl $0x0, %eax
jne 0x2aa5
leaq -0x1040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq -0x1040(%rbp), %rsi
leaq 0x371e(%rip), %rdi      # 0x60b4
movb $0x0, %al
callq 0x2180
movq 0x5634(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2050
leaq -0x1040(%rbp), %rdi
leaq -0x20d0(%rbp), %rsi
callq 0x2150
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
jne 0x29d9
leaq 0x3644(%rip), %rdi      # 0x6013
callq 0x2130
jmp 0x278f
movl -0x20b8(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x29fe
leaq -0x1040(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x2db0
jmp 0x2a0a
leaq -0x1040(%rbp), %rdi
callq 0x3120
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, -0x20d4(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x2a3f
leaq 0x35e6(%rip), %rdi      # 0x6014
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl -0x20d4(%rbp), %edi
leaq -0x24(%rbp), %rax
movq %rax, -0x20e0(%rbp)
movq -0x20e0(%rbp), %rsi
movl $0x10, %edx
callq 0x2120
movl %eax, -0x20d8(%rbp)
cmpl $-0x1, -0x20d8(%rbp)
jne 0x2a88
leaq 0x35a4(%rip), %rdi      # 0x601b
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl -0x20d4(%rbp), %edi
leaq -0x1040(%rbp), %rsi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0x48b0
jmp 0x2c07
leaq -0x1040(%rbp), %rdi
leaq 0x35cc(%rip), %rsi      # 0x607f
callq 0x21e0
cmpl $0x0, %eax
jne 0x2c05
leaq -0x1040(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20f0
leaq -0x1040(%rbp), %rsi
addq $0x800, %rsi            # imm = 0x800
leaq -0x1040(%rbp), %rdx
leaq 0x3594(%rip), %rdi      # 0x6084
movb $0x0, %al
callq 0x2180
movq 0x54da(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2050
leaq -0x1040(%rbp), %rdi
leaq -0x2170(%rbp), %rsi
callq 0x2150
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
jne 0x2b33
leaq 0x34ea(%rip), %rdi      # 0x6013
callq 0x2130
jmp 0x278f
movl -0x2158(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x2b56
leaq 0x353d(%rip), %rdi      # 0x6089
callq 0x2250
jmp 0x278f
leaq -0x1040(%rbp), %rdi
movl $0x800, %esi            # imm = 0x800
callq 0x2db0
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2070
movl %eax, -0x2174(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x2b9c
leaq 0x3489(%rip), %rdi      # 0x6014
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl -0x2174(%rbp), %edi
leaq -0x24(%rbp), %rax
movq %rax, -0x2180(%rbp)
movq -0x2180(%rbp), %rsi
movl $0x10, %edx
callq 0x2120
movl %eax, -0x2178(%rbp)
cmpl $-0x1, -0x2178(%rbp)
jne 0x2be2
leaq 0x3447(%rip), %rdi      # 0x601b
callq 0x2130
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c1c
movl -0x2174(%rbp), %edi
leaq -0x1040(%rbp), %rsi
addq $0x800, %rsi            # imm = 0x800
leaq -0x1040(%rbp), %rdx
movl -0x40(%rbp), %ecx
callq 0x3000
jmp 0x2c07
jmp 0x2c09
jmp 0x2c0b
jmp 0x2c0d
jmp 0x2c0f
jmp 0x278f
movl -0x14(%rbp), %edi
callq 0x22c0
movl -0x4(%rbp), %eax
addq $0x2190, %rsp           # imm = 0x2190
popq %rbp
retq
nopl (%rax,%rax)