// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_command.c
// Function: ce_command_parse
bool ce_command_parse(CeCommand_t* command, const char* string){
     if(*string == 0) return false;

     const char* start = NULL;
     const char* end = NULL;

     int64_t arg_count = 0;
     start = eat_blanks(string);

     // count the args
     while(*start){
          end = find_end_of_arg(start);
          arg_count++;
          if(!end) break;
          start = eat_blanks(end + 1);
     }

     // account for command at the beginning
     arg_count--;

     start = eat_blanks(string);
     end = find_end_of_arg(start);

     if(!end){
          command->args = NULL;
          command->arg_count = 0;

          int64_t len = strlen(start);
          if(len >= CE_COMMAND_NAME_MAX_LEN){
               ce_log("error: in command '%s' command name is greater than max %d characters\n", string, CE_COMMAND_NAME_MAX_LEN);
               return false;
          }

          strcpy(command->name, start);
          return true;
     }

     // copy the command name
     int64_t len = end - start;
     if(len >= CE_COMMAND_NAME_MAX_LEN){
          ce_log("error: in command '%s' command name is greater than max %d characters\n", string, CE_COMMAND_NAME_MAX_LEN);
          return false;
     }

     strncpy(command->name, start, len);
     command->name[len] = 0;

     // exit early if there are no arguments
     if(arg_count == 0){
          command->args = NULL;
          command->arg_count = 0;
          return true;
     }

     start = eat_blanks(end + 1);

     // allocate the arguments
     command->args = malloc(arg_count * sizeof(*command->args));
     if(!command->args) return false;
     command->arg_count = arg_count;

     CeCommandArg_t* arg = command->args;

     // parse the individual args
     char buffer[CE_COMMAND_ARG_MAX_LEN];
     while(*start){
          end = find_end_of_arg(start);
          if(end){
               int64_t arg_len = end - start;
               if (arg_len >= CE_COMMAND_ARG_MAX_LEN) {
                   return false;
               }
               memset(buffer, 0, arg_len + 1);
               buffer[arg_len] = 0;

               strncpy(buffer, start, arg_len);
               if(!parse_arg(arg, buffer)){
                    ce_command_free(command);
                    return false;
               }
          }else{
               int64_t arg_len = strlen(start);
               if (arg_len >= CE_COMMAND_ARG_MAX_LEN) {
                   return false;
               }
               memset(buffer, 0, arg_len + 1);
               strcpy(buffer, start);
               buffer[arg_len] = 0;
               if(!parse_arg(arg, buffer)){
                    ce_command_free(command);
                    return false;
               }
               break;
          }

          start = eat_blanks(end + 1);
          arg++;
     }

     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
cmpb $0x0, (%rsi)
je 0x158d5
movq %rsi, %r14
movq %rdi, %rbp
movq %rsi, %rdi
callq 0x158eb
movq %rax, %r15
xorl %r13d, %r13d
movq %rax, %rdi
cmpb $0x0, (%rdi)
je 0x1572e
callq 0x1591a
testq %rax, %rax
je 0x1572b
incq %rax
movq %rax, %rdi
callq 0x158eb
movq %rax, %rdi
incq %r13
jmp 0x15709
incq %r13
movq %r15, %rdi
callq 0x1591a
testq %rax, %rax
je 0x15830
movq %rax, %r12
movq %rax, %rbx
subq %r15, %rbx
cmpq $0x200, %rbx            # imm = 0x200
jge 0x15857
decq %r13
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd0b0
movb $0x0, (%rbp,%rbx)
testq %r13, %r13
je 0x15871
incq %r12
movq %r12, %rdi
callq 0x158eb
movq %rax, %r15
movq %r13, %rdi
shlq $0x4, %rdi
callq 0xd4c0
movq %rax, 0x200(%rbp)
testq %rax, %rax
je 0x158d5
movq %rax, %r14
movq %rbp, 0x8(%rsp)
movq %r13, 0x208(%rbp)
leaq 0x10(%rsp), %r12
cmpb $0x0, (%r15)
sete %bpl
je 0x158d7
movq %r15, %rdi
callq 0x1591a
testq %rax, %rax
je 0x15880
movq %rax, %rbx
movq %rax, %r13
subq %r15, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x158d7
leaq 0x1(%r13), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0xd2a0
movb $0x0, 0x10(%rsp,%r13)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd0b0
movq %r14, %rdi
movq %r12, %rsi
callq 0x15955
testb %al, %al
je 0x158cb
incq %rbx
movq %rbx, %rdi
callq 0x158eb
movq %rax, %r15
addq $0x10, %r14
jmp 0x157b2
xorps %xmm0, %xmm0
movups %xmm0, 0x200(%rbp)
movq %r15, %rdi
callq 0xd210
cmpq $0x200, %rax            # imm = 0x200
jge 0x15857
movq %rbp, %rdi
movq %r15, %rsi
callq 0xd0e0
jmp 0x1587b
leaq 0x16974(%rip), %rdi     # 0x2c1d2
xorl %ebp, %ebp
movq %r14, %rsi
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0xd8e5
jmp 0x158d7
xorps %xmm0, %xmm0
movups %xmm0, 0x200(%rbp)
movb $0x1, %bpl
jmp 0x158d7
movq %r15, %rdi
callq 0xd210
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x158d5
movq %rax, %r12
movq %rax, %rdx
incq %rdx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd2a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd0e0
movb $0x0, 0x10(%rsp,%r12)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x15955
movb $0x1, %bpl
testb %al, %al
jne 0x158d7
movq 0x8(%rsp), %rdi
callq 0x15a3b
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq