// File: /workspace/github_c_makefile_star2_O1/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 0x16665
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x1667b
movq %rax, %r15
cmpb $0x0, (%rax)
je 0x164a8
xorl %r12d, %r12d
movq %r15, %rax
movq %r12, %rbp
movq %rax, %rdi
callq 0x166b1
testq %rax, %rax
je 0x164af
leaq 0x1(%rbp), %r12
incq %rax
movq %rax, %rdi
callq 0x1667b
cmpb $0x0, (%rax)
jne 0x16482
jmp 0x164af
movq $-0x1, %rbp
movq %r15, %rdi
callq 0x166b1
testq %rax, %rax
je 0x165c2
movq %rax, %r12
movq %rax, %r13
subq %r15, %r13
cmpq $0x200, %r13            # imm = 0x200
jge 0x165e9
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, (%rbx,%r13)
testq %rbp, %rbp
je 0x16603
incq %r12
movq %r12, %rdi
callq 0x1667b
movq %rax, %r15
movq %rbp, %rdi
shlq $0x4, %rdi
callq 0xd4c0
movq %rax, 0x200(%rbx)
testq %rax, %rax
je 0x16665
movq %rbp, 0x208(%rbx)
movb $0x1, %bpl
cmpb $0x0, (%r15)
je 0x16667
movq %rax, %r14
movq %rbx, 0x8(%rsp)
movq %r15, %rdi
callq 0x166b1
testq %rax, %rax
je 0x16612
movq %rax, %r12
movq %rax, %r13
subq %r15, %r13
cmpq $0x400, %r13            # imm = 0x400
setl %bpl
jge 0x16667
leaq 0x1(%r13), %rdx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd2a0
movb $0x0, 0x10(%rsp,%r13)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd0b0
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rbx
callq 0x166e6
testb %al, %al
je 0x1665d
incq %r12
movq %r12, %rdi
callq 0x1667b
movq %rax, %r15
addq $0x10, %r14
cmpb $0x0, (%rax)
jne 0x16538
jmp 0x16667
xorps %xmm0, %xmm0
movups %xmm0, 0x200(%rbx)
movq %r15, %rdi
callq 0xd210
cmpq $0x200, %rax            # imm = 0x200
jge 0x165e9
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd0e0
jmp 0x1660d
leaq 0x19be2(%rip), %rdi     # 0x301d2
xorl %ebp, %ebp
movq %r14, %rsi
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0xd954
jmp 0x16667
xorps %xmm0, %xmm0
movups %xmm0, 0x200(%rbx)
movb $0x1, %bpl
jmp 0x16667
movq %r15, %rdi
callq 0xd210
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x16665
movq %rax, %r12
movq %rax, %rdx
incq %rdx
leaq 0x10(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0xd2a0
movq %r13, %rdi
movq %r15, %rsi
callq 0xd0e0
movb $0x0, 0x10(%rsp,%r12)
movq %r14, %rdi
movq %r13, %rsi
callq 0x166e6
movb $0x1, %bpl
testb %al, %al
jne 0x16667
movq %rbx, %rdi
callq 0x167e6
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq