// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_app.c
// Function: scan_line_for_destination
CeDestination_t scan_line_for_destination(const char* line){
     CeDestination_t destination = {};
     destination.point = (CePoint_t){-1, -1};

     // TODO: more formats, including git grep

     // valgrind format
     // '==7330==    by 0x638B16A: initializer (ce_config.c:1983)'
     if(line[0] == '=' && line[1] == '='){
          char* open_paren = strchr(line, '(');
          char* close_paren = strchr(line, ')');
          if(open_paren && close_paren){
               char* file_end = strchr(open_paren, ':');
               if(file_end){
                    char* end = NULL;
                    char* number_start = file_end + 1;
                    destination.point.y = strtol(number_start, &end, 10);
                    if(end != number_start){
                         if(destination.point.y > 0) destination.point.y--;
                         destination.point.x = 0;

                         int64_t filepath_len = file_end - (open_paren + 1);
                         if(filepath_len >= MAX_PATH_LEN) return destination;
                         strncpy(destination.filepath, (open_paren + 1), filepath_len);
                         destination.filepath[filepath_len] = 0;
                         return destination;
                    }
               }
          }
     }

     // grep/gcc format
     // ce_app.c:1515:23
     char* file_end = strchr(line, ':');
#if defined(PLATFORM_WINDOWS)
     // detect windows path.
     if(file_end && line[1] == ':'){
         file_end = strchr(line + 2, ':');
     }
#endif
     if(file_end){
          char* row_end = strchr(file_end + 1, ':');
          char* col_end = NULL;
          if(row_end) col_end = strchr(row_end + 1, ':');
          // col_end and row_end is not always present

          int64_t filepath_len = file_end - line;
          if(filepath_len >= MAX_PATH_LEN) return destination;
          strncpy(destination.filepath, line, filepath_len);
          destination.filepath[filepath_len] = 0;
          char* end = NULL;

          if(row_end){
               char* row_start = file_end + 1;
               destination.point.y = strtol(row_start, &end, 10);
               if(end == row_start) {
                   destination.point.y = -1;
               }else {
                   if(destination.point.y > 0){
                        destination.point.y--; // account for format which is 1 indexed
                   }

                   if(col_end){
                        char* col_start = row_end + 1;
                        destination.point.x = strtol(col_start, &end, 10);
                        if(end == col_start) destination.point.x = 0;
                        if(destination.point.x > 0) destination.point.x--; // account for format which is 1 indexed
                   }else{
                        destination.point.x = 0;
                   }
                   return destination;
               }
          }
     }

     // Windows cl format.
     // code\main.cpp(31): error C2065: 'renderer': undeclared identifier
     file_end = strchr(line, '(');
     if(file_end){
          char* row_start = file_end + 1;
          char* row_end = strchr(row_start, ')');
          int64_t filepath_len = file_end - line;
          if(filepath_len >= MAX_PATH_LEN){
               return destination;
          }
          strncpy(destination.filepath, line, filepath_len);
          destination.filepath[filepath_len] = 0;

          char* end = NULL;
          if(row_end){
               destination.point.y = strtol(row_start, &end, 10);
               if(end == NULL){
                    destination.point.y = -1;
               }else if(destination.point.y > 0){
                    destination.point.y--; // account for format which is 1 indexed
               }
               destination.point.x = 0;
               return destination;
          }
     }

     return destination;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x410, %edx            # imm = 0x410
xorl %esi, %esi
callq 0xd2a0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rbx)
cmpb $0x3d, (%r14)
jne 0x120d1
cmpb $0x3d, 0x1(%r14)
jne 0x120d1
movq %r14, %rdi
movl $0x28, %esi
callq 0xd230
movq %rax, %r15
movq %r14, %rdi
movl $0x29, %esi
callq 0xd230
testq %r15, %r15
je 0x120d1
testq %rax, %rax
je 0x120d1
movq %r15, %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
je 0x120d1
movq %rax, %r12
movq %rsp, %r13
movq $0x0, (%r13)
leaq 0x1(%rax), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq %rbp, (%r13)
je 0x120d1
testq %rax, %rax
jle 0x1209d
decq %rax
movq %rax, 0x8(%rbx)
movq $0x0, (%rbx)
incq %r15
subq %r15, %r12
cmpq $0x3ff, %r12            # imm = 0x3FF
jg 0x12264
leaq 0x10(%rbx), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r12)
jmp 0x12264
movq %r14, %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
je 0x121ce
movq %rax, %r13
leaq 0x1(%rax), %r15
movq %r15, %rdi
movl $0x3a, %esi
callq 0xd230
movq %rax, %r12
testq %rax, %rax
je 0x1211b
leaq 0x1(%r12), %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
sete %bpl
jmp 0x1211e
movb $0x1, %bpl
subq %r14, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x12264
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r13)
movq $0x0, (%rsp)
testq %r12, %r12
je 0x121ce
movq %rsp, %r13
movq %r15, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
movq (%r13), %r13
cmpq %r15, %r13
je 0x1218a
testq %rax, %rax
jle 0x1217c
decq %rax
movq %rax, 0x8(%rbx)
testb %bpl, %bpl
je 0x12194
movq $0x0, (%rbx)
jmp 0x121c5
movq $-0x1, 0x8(%rbx)
jmp 0x121c5
incq %r12
movq %rsp, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, (%rbx)
xorl %ecx, %ecx
cmpq %r12, (%rbp)
cmovneq %rax, %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
jle 0x121c5
decq %rcx
movq %rcx, (%rbx)
cmpq %r15, %r13
jne 0x12264
movq %r14, %rdi
movl $0x28, %esi
callq 0xd230
testq %rax, %rax
je 0x12264
movq %rax, %r15
movq %rax, %r12
subq %r14, %r12
cmpq $0x3ff, %r12            # imm = 0x3FF
jg 0x12264
incq %r15
movq %r15, %rdi
movl $0x29, %esi
callq 0xd230
movq %rax, %r13
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r12)
movq $0x0, (%rsp)
testq %r13, %r13
je 0x12264
movq %rsp, %r14
movq %r15, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq $0x0, (%r14)
je 0x12252
testq %rax, %rax
jle 0x1225d
decq %rax
jmp 0x12259
movq $-0x1, %rax
movq %rax, 0x8(%rbx)
movq $0x0, (%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq