// File: /workspace/github_c_makefile_star2_O2/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 0x11797
cmpb $0x3d, 0x1(%r15)
jne 0x11797
pushq $0x28
popq %rsi
movq %r15, %rdi
callq 0xd230
movq %rax, %r12
pushq $0x29
popq %rsi
movq %r15, %rdi
callq 0xd230
testq %r12, %r12
je 0x11797
testq %rax, %rax
je 0x11797
pushq $0x3a
popq %rsi
movq %r12, %rdi
callq 0xd230
testq %rax, %rax
je 0x11797
movq %rax, %r13
leaq 0x10(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x1(%rax), %rbp
pushq $0xa
popq %rdx
movq %rbp, %rdi
callq 0xd400
movq %rax, 0x8(%rbx)
leaq 0x10(%rsp), %rcx
cmpq %rbp, (%rcx)
je 0x11797
testq %rax, %rax
jle 0x11767
decq %rax
movq %rax, 0x8(%rbx)
andq $0x0, (%rbx)
incq %r12
subq %r12, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x11909
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r13)
jmp 0x11909
pushq $0x3a
popq %rsi
movq %r15, %rdi
callq 0xd230
testq %rax, %rax
je 0x1184e
movq %rax, %rbp
leaq 0x1(%rax), %r13
pushq $0x3a
popq %rsi
movq %r13, %rdi
callq 0xd230
movq %rax, %r12
testq %rax, %rax
je 0x117da
leaq 0x1(%r12), %rdi
pushq $0x3a
popq %rsi
callq 0xd230
testq %rax, %rax
sete %al
jmp 0x117dc
movb $0x1, %al
subq %r15, %rbp
cmpq $0x3ff, %rbp            # imm = 0x3FF
jg 0x11909
movb %al, 0xf(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%rbp)
andq $0x0, 0x10(%rsp)
testq %r12, %r12
je 0x1184e
leaq 0x10(%rsp), %rbp
pushq $0xa
popq %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq %r13, (%rbp)
je 0x11849
testq %rax, %rax
jle 0x11837
decq %rax
movq %rax, 0x8(%rbx)
cmpb $0x0, 0xf(%rsp)
je 0x118cf
xorl %ecx, %ecx
jmp 0x118f9
orq $-0x1, 0x8(%rbx)
pushq $0x28
popq %rsi
movq %r15, %rdi
callq 0xd230
testq %rax, %rax
je 0x11909
movq %rax, %r12
movq %rax, %r13
subq %r15, %r13
cmpq $0x3ff, %r13            # imm = 0x3FF
jg 0x11909
incq %r12
pushq $0x29
popq %rsi
movq %r12, %rdi
callq 0xd230
movq %rax, %rbp
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd0b0
movb $0x0, 0x10(%rbx,%r13)
andq $0x0, 0x10(%rsp)
testq %rbp, %rbp
je 0x11909
leaq 0x10(%rsp), %r14
pushq $0xa
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0xd400
movq %rax, 0x8(%rbx)
cmpq $0x0, (%r14)
je 0x118fe
testq %rax, %rax
jle 0x11905
decq %rax
jmp 0x11901
incq %r12
leaq 0x10(%rsp), %r14
pushq $0xa
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0xd400
xorl %ecx, %ecx
cmpq %r12, (%r14)
cmovneq %rax, %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
jle 0x11909
decq %rcx
movq %rcx, (%rbx)
jmp 0x11909
pushq $-0x1
popq %rax
movq %rax, 0x8(%rbx)
andq $0x0, (%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq