// File: /workspace/github_c_makefile_star2_O3/VeeeectorPan[P]MyNetdisk/SourceFile/client_ls.c
// Function: client_ls
int client_ls(int client_fd)
{
    int file_id;
    MYSQL* connect;
    connect_mysql(&connect);
    int ret = recv(client_fd,&file_id,sizeof(int),0);
    DISCON_CHECK(ret,0,client_fd);
    char mysql_oper[256];
    sprintf(mysql_oper,"select file_type,file_size,file_name from File where parent_id=%d;",file_id);
    int queryResult = mysql_query(connect,mysql_oper);
    if(queryResult)
    {
        printf("%s\n",mysql_error(connect));
        return -1;
    }
    MYSQL_ROW row;
    MYSQL_RES* res;
    res = mysql_use_result(connect);
    row = mysql_fetch_row(res);
    char buf[256];
    while(row != NULL)
    {
        memset(buf,0,sizeof(buf));
        buf[0] = *row[0];
        int file_size;
        if(row[1] != NULL)
            file_size = atoi(row[1]);
        else
            file_size = 0;
        memcpy(buf + 1,(const char*)&file_size,sizeof(int));
        sprintf(buf + 5,"%s",row[2]);
        int len = 5 + strlen(buf + 5);
        ret = send(client_fd,&len,sizeof(int),MSG_NOSIGNAL);
        DISCON_CHECK(ret,-1,client_fd);
        ret = send(client_fd,buf,len,MSG_NOSIGNAL);
        DISCON_CHECK(ret,-1,client_fd);
        row = mysql_fetch_row(res);
    }
    mysql_free_result(res);
    mysql_close(connect);

    int ctl_num = LS_FIN;
    ret = send(client_fd,&ctl_num,sizeof(int),MSG_NOSIGNAL);
    DISCON_CHECK(ret,-1,client_fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movl %edi, %ebx
leaq -0x38(%rbp), %rdi
callq 0x34e8
leaq -0x3c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x2b1d
movl -0x3c(%rbp), %edx
leaq 0x269b(%rip), %rsi      # 0x508a
leaq -0x240(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x2140
movq -0x38(%rbp), %rdi
testl %eax, %eax
je 0x2a26
callq 0x20b0
movq %rax, %rdi
callq 0x22f0
jmp 0x2b24
callq 0x2340
movq %rax, %r14
movq %rax, %rdi
callq 0x2200
testq %rax, %rax
je 0x2ae7
movq %rax, %r13
leaq -0x13b(%rbp), %r15
xorl %r12d, %r12d
movl $0x100, %edx            # imm = 0x100
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
callq 0x2130
movq (%r13), %rax
movb (%rax), %al
movb %al, -0x140(%rbp)
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x2a7c
callq 0x2300
movl %eax, %r12d
movl %r12d, -0x13f(%rbp)
movq 0x10(%r13), %rsi
movq %r15, %rdi
callq 0x21c0
movq %r15, %rdi
callq 0x20c0
addl $0x5, %eax
movl %eax, -0x2c(%rbp)
movl $0x4, %edx
movl %ebx, %edi
leaq -0x2c(%rbp), %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x2b1d
movslq -0x2c(%rbp), %rdx
movl %ebx, %edi
leaq -0x140(%rbp), %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
je 0x2b1d
movq %r14, %rdi
callq 0x2200
movq %rax, %r13
testq %rax, %rax
jne 0x2a49
movq %r14, %rdi
callq 0x21f0
movq -0x38(%rbp), %rdi
callq 0x2260
leaq -0x2c(%rbp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movl %ebx, %edi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
movq %rax, %rcx
xorl %eax, %eax
cmpl $-0x1, %ecx
jne 0x2b29
movl %ebx, %edi
callq 0x2380
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop