// File: /workspace/github_c_makefile_star2_O1/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 $0x228, %rsp            # imm = 0x228
movl %edi, %ebx
leaq -0x38(%rbp), %rdi
callq 0x3530
leaq -0x3c(%rbp), %rsi
movl $0x4, %edx
movl %ebx, %edi
xorl %ecx, %ecx
callq 0x20a0
testl %eax, %eax
je 0x2b28
movl -0x3c(%rbp), %edx
leaq 0x269f(%rip), %rsi      # 0x508a
leaq -0x250(%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 0x2a22
callq 0x20b0
movq %rax, %rdi
callq 0x22e0
jmp 0x2b2f
callq 0x2330
movq %rax, -0x48(%rbp)
movq %rax, %rdi
callq 0x21f0
movq %rax, %r14
leaq -0x14b(%rbp), %r15
leaq -0x150(%rbp), %r12
testq %r14, %r14
je 0x2af1
xorl %r13d, %r13d
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
xorl %esi, %esi
callq 0x2130
movq (%r14), %rax
movb (%rax), %al
movb %al, -0x150(%rbp)
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x2a7b
callq 0x22f0
movl %eax, %r13d
movl %r13d, -0x14f(%rbp)
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x21b0
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 0x2ace
movslq -0x2c(%rbp), %rdx
movl %ebx, %edi
movq %r12, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2100
cmpl $-0x1, %eax
jne 0x2ad9
movl %ebx, %edi
callq 0x2370
xorl %eax, %eax
jmp 0x2ae7
movq -0x48(%rbp), %rdi
callq 0x21f0
movq %rax, %r14
movb $0x1, %al
testb %al, %al
jne 0x2a44
jmp 0x2b2f
movq -0x48(%rbp), %rdi
callq 0x21e0
movq -0x38(%rbp), %rdi
callq 0x2250
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 0x2b34
movl %ebx, %edi
callq 0x2370
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop