// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_app.c
// Function: extract_reference_locations_to_buffer
void _extract_reference_locations_to_buffer(CeJsonObj_t* obj, CeBuffer_t* buffer,
                                            CeBufferNode_t* buffer_node_head){
     buffer->status = CE_BUFFER_STATUS_NONE;
     ce_buffer_empty(buffer);

     CeJsonFindResult_t result_find = ce_json_obj_find(obj, "result");
     if(result_find.type != CE_JSON_TYPE_ARRAY){
         return;
     }
     CeJsonArray_t* result_array = ce_json_obj_get_array(obj, &result_find);
     if(result_array == NULL){
         return;
     }

     char* filepath = NULL;
     for(int64_t i = 0; i < result_array->count; i++){
          if(filepath){
               free(filepath);
               filepath = NULL;
          }

          CeJsonValue_t* value = result_array->values + i;
          if(value->type != CE_JSON_TYPE_OBJECT){
                continue;
          }

          CeJsonFindResult_t uri_find = ce_json_obj_find(&value->obj, "uri");
          if(uri_find.type != CE_JSON_TYPE_STRING){
               continue;
          }

          const char* file_uri = ce_json_obj_get_string(&value->obj, &uri_find);
          if(file_uri == NULL){
               continue;
          }

          filepath = strdup(file_uri);
#if defined(PLATFORM_WINDOWS)
          _convert_uri_to_windows_path(filepath);
#else
          _convert_uri_to_linux_path(filepath);
#endif

          CeJsonFindResult_t range_find = ce_json_obj_find(&value->obj, "range");
          if(range_find.type != CE_JSON_TYPE_OBJECT){
              continue;
          }

          CeJsonObj_t* range_obj = ce_json_obj_get_obj(&value->obj, &range_find);
          if(range_obj == NULL){
              continue;
          }

          // This logic can be compressed.
          CeJsonFindResult_t start_find = ce_json_obj_find(range_obj, "start");
          if(start_find.type != CE_JSON_TYPE_OBJECT){
               continue;
          }
          CeJsonObj_t* start_obj = ce_json_obj_get_obj(range_obj, &start_find);
          if(start_obj == NULL){
               continue;
          }
          CeJsonFindResult_t line_find = ce_json_obj_find(start_obj, "line");
          if(line_find.type != CE_JSON_TYPE_NUMBER){
               continue;
          }
          CeJsonFindResult_t character_find = ce_json_obj_find(start_obj, "character");
          if(character_find.type != CE_JSON_TYPE_NUMBER){
               continue;
          }
          int64_t start_x = (int64_t)(*ce_json_obj_get_number(start_obj, &character_find));
          int64_t start_y = (int64_t)(*ce_json_obj_get_number(start_obj, &line_find));

          char line[MAX_PATH_LEN];
          snprintf(line, MAX_PATH_LEN, "%s:%" PRId64 ":%" PRId64 " ", filepath, start_y + 1, start_x + 1);
          CePoint_t end = ce_buffer_end_point(buffer);
          ce_buffer_insert_string(buffer, line, end);

          // Find the line to insert text from that buffer.
          CeBufferNode_t* buffer_itr = buffer_node_head;
          while(buffer_itr){
#if defined(PLATFORM_WINDOWS)
              char* buffer_full_path = _fullpath(NULL, buffer_itr->buffer->name, MAX_PATH_LEN);
#else
              char* buffer_full_path = realpath(buffer_itr->buffer->name, NULL);
#endif
              bool matches = (strcmp(filepath, buffer_full_path) == 0);
              free(buffer_full_path);
              if(matches){
                  if(start_y < buffer_itr->buffer->line_count){
                      char* buffer_line = buffer_itr->buffer->lines[start_y];
                      end = ce_buffer_end_point(buffer);
                      ce_buffer_insert_string(buffer, buffer_line, end);
                  }
                  break;
              }
              buffer_itr = buffer_itr->next;
          }

          end = ce_buffer_end_point(buffer);
          ce_buffer_insert_string(buffer, "\n", end);
     }
     if(filepath){
          free(filepath);
          filepath = NULL;
     }
     buffer->status = CE_BUFFER_STATUS_READONLY;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rdi
callq 0xe920
movq -0x8(%rbp), %rdi
leaq 0x2cbd4(%rip), %rsi     # 0x43b6a
callq 0x25e70
movl %eax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x2, -0x28(%rbp)
je 0x16fad
jmp 0x173ad
movq -0x8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x25f60
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x16fca
jmp 0x173ad
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x1738a
cmpq $0x0, -0x38(%rbp)
je 0x17004
movq -0x38(%rbp), %rdi
callq 0xd090
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x1, (%rax)
je 0x17025
jmp 0x17379
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
leaq 0x2cb80(%rip), %rsi     # 0x43bb4
callq 0x25e70
movl %eax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
cmpl $0x3, -0x58(%rbp)
je 0x1704b
jmp 0x17379
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
leaq -0x58(%rbp), %rsi
callq 0x25fb0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x1706c
jmp 0x17379
movq -0x60(%rbp), %rdi
callq 0xd620
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x16e50
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
leaq 0x2cb0c(%rip), %rsi     # 0x43b9d
callq 0x25e70
movl %eax, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
cmpl $0x1, -0x70(%rbp)
je 0x170a8
jmp 0x17379
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
leaq -0x70(%rbp), %rsi
callq 0x25f10
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x170c9
jmp 0x17379
movq -0x78(%rbp), %rdi
leaq 0x2b591(%rip), %rsi     # 0x42665
callq 0x25e70
movl %eax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
cmpl $0x1, -0x88(%rbp)
je 0x170f1
jmp 0x17379
movq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x25f10
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x17117
jmp 0x17379
movq -0x90(%rbp), %rdi
leaq 0x2bb49(%rip), %rsi     # 0x42c6e
callq 0x25e70
movl %eax, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
cmpl $0x4, -0xa0(%rbp)
je 0x17145
jmp 0x17379
movq -0x90(%rbp), %rdi
leaq 0x2ca50(%rip), %rsi     # 0x43ba3
callq 0x25e70
movl %eax, -0xb0(%rbp)
movq %rdx, -0xa8(%rbp)
cmpl $0x4, -0xb0(%rbp)
je 0x17173
jmp 0x17379
movq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x26000
cvttsd2si (%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x90(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x26000
cvttsd2si (%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x4c0(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0xc0(%rbp), %r8
addq $0x1, %r8
movq -0xb8(%rbp), %r9
addq $0x1, %r9
movl $0x400, %esi            # imm = 0x400
leaq 0x2c9ee(%rip), %rdx     # 0x43bcc
movb $0x0, %al
callq 0xd250
movq -0x10(%rbp), %rdi
callq 0xda10
movq %rax, -0x4d0(%rbp)
movq %rdx, -0x4c8(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x4c0(%rbp), %rsi
movq -0x4d0(%rbp), %rdx
movq -0x4c8(%rbp), %rcx
callq 0xda70
movq -0x18(%rbp), %rax
movq %rax, -0x4d8(%rbp)
cmpq $0x0, -0x4d8(%rbp)
je 0x17328
movq -0x4d8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd3f0
movq %rax, -0x4e0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x4e0(%rbp), %rsi
callq 0xd370
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x4e1(%rbp)
movq -0x4e0(%rbp), %rdi
callq 0xd090
testb $0x1, -0x4e1(%rbp)
je 0x17311
movq -0xc0(%rbp), %rax
movq -0x4d8(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jge 0x1730f
movq -0x4d8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0xc0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4f0(%rbp)
movq -0x10(%rbp), %rdi
callq 0xda10
movq %rax, -0x500(%rbp)
movq %rdx, -0x4f8(%rbp)
movq -0x500(%rbp), %rax
movq %rax, -0x4d0(%rbp)
movq -0x4f8(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x4f0(%rbp), %rsi
movq -0x4d0(%rbp), %rdx
movq -0x4c8(%rbp), %rcx
callq 0xda70
jmp 0x17328
movq -0x4d8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x4d8(%rbp)
jmp 0x17225
movq -0x10(%rbp), %rdi
callq 0xda10
movq %rax, -0x510(%rbp)
movq %rdx, -0x508(%rbp)
movq -0x510(%rbp), %rax
movq %rax, -0x4d0(%rbp)
movq -0x508(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x4d0(%rbp), %rdx
movq -0x4c8(%rbp), %rcx
leaq 0x2cb34(%rip), %rsi     # 0x43ea8
callq 0xda70
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x16fda
cmpq $0x0, -0x38(%rbp)
je 0x173a2
movq -0x38(%rbp), %rdi
callq 0xd090
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x2, 0x18(%rax)
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
nopw %cs:(%rax,%rax)