// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0xa8(%rbp)
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movq %rsi, -0x8(%rbp)
xorl %esi, %esi
movl $0x410, %edx            # imm = 0x410
callq 0xd290
movq -0xa8(%rbp), %rdi
movq $-0x1, -0x18(%rbp)
movq $-0x1, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq %rax, (%rdi)
movq -0x10(%rbp), %rax
movq %rax, 0x8(%rdi)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x15274
movq -0x8(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3d, %eax
jne 0x15274
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0xd220
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x29, %esi
callq 0xd220
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x15272
cmpq $0x0, -0x28(%rbp)
je 0x15272
movq -0x20(%rbp), %rdi
movl $0x3a, %esi
callq 0xd220
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x15270
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0xd3e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x1526e
movq -0xa8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jle 0x1520d
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0xa8(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpq $0x400, -0x48(%rbp)     # imm = 0x400
jl 0x1523d
jmp 0x15534
movq -0xa8(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
movq -0x48(%rbp), %rdx
callq 0xd0b0
movq -0xa8(%rbp), %rax
movq -0x48(%rbp), %rcx
movb $0x0, 0x10(%rax,%rcx)
jmp 0x15534
jmp 0x15270
jmp 0x15272
jmp 0x15274
movq -0x8(%rbp), %rdi
movl $0x3a, %esi
callq 0xd220
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x15411
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
movl $0x3a, %esi
callq 0xd220
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x152cc
movq -0x58(%rbp), %rdi
addq $0x1, %rdi
movl $0x3a, %esi
callq 0xd220
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpq $0x400, -0x68(%rbp)     # imm = 0x400
jl 0x152ea
jmp 0x15534
movq -0xa8(%rbp), %rdi
addq $0x10, %rdi
movq -0x8(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0xd0b0
movq -0xa8(%rbp), %rax
movq -0x68(%rbp), %rcx
movb $0x0, 0x10(%rax,%rcx)
movq $0x0, -0x70(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x1540f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0xa, %edx
callq 0xd3e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jne 0x1536f
movq -0xa8(%rbp), %rax
movq $-0x1, 0x8(%rax)
jmp 0x1540d
movq -0xa8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jle 0x15390
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x60(%rbp)
je 0x153fa
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0xa, %edx
callq 0xd3e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rax
cmpq -0x80(%rbp), %rax
jne 0x153da
movq -0xa8(%rbp), %rax
movq $0x0, (%rax)
movq -0xa8(%rbp), %rax
cmpq $0x0, (%rax)
jle 0x153f8
movq -0xa8(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
jmp 0x15408
movq -0xa8(%rbp), %rax
movq $0x0, (%rax)
jmp 0x15534
jmp 0x1540f
jmp 0x15411
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0xd220
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x15532
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movl $0x29, %esi
callq 0xd220
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x98(%rbp)
cmpq $0x400, -0x98(%rbp) # imm = 0x400
jl 0x15479
jmp 0x15534
movq -0xa8(%rbp), %rdi
addq $0x10, %rdi
movq -0x8(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0xd0b0
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
movb $0x0, 0x10(%rax,%rcx)
movq $0x0, -0xa0(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x15530
movq -0x88(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0xa, %edx
callq 0xd3e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, -0xa0(%rbp)
jne 0x154fd
movq -0xa8(%rbp), %rax
movq $-0x1, 0x8(%rax)
jmp 0x15520
movq -0xa8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jle 0x1551e
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x15520
movq -0xa8(%rbp), %rax
movq $0x0, (%rax)
jmp 0x15534
jmp 0x15532
jmp 0x15534
movq -0xb0(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)