// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rdi), %r14
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0xd2a0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rbx)
cmpb $0x3d, (%r15)
jne 0x11ecc
cmpb $0x3d, 0x1(%r15)
jne 0x11ecc
movq %r15, %rdi
movl $0x28, %esi
callq 0xd230
movq %rax, %r12
movq %r15, %rdi
movl $0x29, %esi
callq 0xd230
testq %r12, %r12
je 0x11ecc
testq %rax, %rax
je 0x11ecc
movq %r12, %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
je 0x11ecc
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq $0x0, (%rsi)
leaq 0x1(%rax), %rbp
movq %rbp, %rdi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
leaq 0x10(%rsp), %rcx
cmpq %rbp, (%rcx)
je 0x11ecc
testq %rax, %rax
jle 0x11e99
decq %rax
movq %rax, 0x8(%rbx)
movq $0x0, (%rbx)
incq %r12
subq %r12, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x1205e
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r13)
jmp 0x1205e
movq %r15, %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
je 0x11f91
movq %rax, %rbp
leaq 0x1(%rax), %r13
movq %r13, %rdi
movl $0x3a, %esi
callq 0xd230
movq %rax, %r12
testq %rax, %rax
je 0x11f15
leaq 0x1(%r12), %rdi
movl $0x3a, %esi
callq 0xd230
testq %rax, %rax
sete %al
jmp 0x11f17
movb $0x1, %al
subq %r15, %rbp
cmpq $0x3ff, %rbp            # imm = 0x3FF
jg 0x1205e
movb %al, 0xf(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%rbp)
movq $0x0, 0x10(%rsp)
testq %r12, %r12
je 0x11f91
leaq 0x10(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq %r13, (%rbp)
je 0x11f89
testq %rax, %rax
jle 0x11f77
decq %rax
movq %rax, 0x8(%rbx)
cmpb $0x0, 0xf(%rsp)
je 0x1201b
xorl %ecx, %ecx
jmp 0x12047
movq $-0x1, 0x8(%rbx)
movq %r15, %rdi
movl $0x28, %esi
callq 0xd230
testq %rax, %rax
je 0x1205e
movq %rax, %r12
movq %rax, %r13
subq %r15, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x1205e
incq %r12
movq %r12, %rdi
movl $0x29, %esi
callq 0xd230
movq %rax, %rbp
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r13)
movq $0x0, 0x10(%rsp)
testq %rbp, %rbp
je 0x1205e
leaq 0x10(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq $0x0, (%r14)
je 0x1204c
testq %rax, %rax
jle 0x12057
decq %rax
jmp 0x12053
incq %r12
leaq 0x10(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0xd400
xorl %ecx, %ecx
cmpq %r12, (%r14)
cmovneq %rax, %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
jle 0x1205e
decq %rcx
movq %rcx, (%rbx)
jmp 0x1205e
movq $-0x1, %rax
movq %rax, 0x8(%rbx)
movq $0x0, (%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq