// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movl $0x0, 0x18(%rsi)
movq %rsi, %rdi
callq 0xe396
leaq 0x1ba22(%rip), %rsi     # 0x2ebb9
movq %r15, %rdi
callq 0x1c943
movl %eax, 0x70(%rsp)
movq %rdx, 0x78(%rsp)
cmpl $0x2, %eax
jne 0x13449
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x1c9b1
testq %rax, %rax
je 0x13449
movq %rax, %r15
cmpq $0x0, 0x8(%rax)
jle 0x13442
xorl %ebp, %ebp
xorl %r12d, %r12d
testq %rbp, %rbp
je 0x131e7
movq %rbp, %rdi
callq 0xd090
movq (%r15), %rax
leaq (%r12,%r12,2), %rcx
cmpl $0x1, (%rax,%rcx,8)
jne 0x133c3
leaq (%rax,%rcx,8), %r13
addq $0x8, %r13
movq %r13, %rdi
leaq 0x1b9f9(%rip), %rsi     # 0x2ec03
callq 0x1c943
movl %eax, 0x60(%rsp)
movq %rdx, 0x68(%rsp)
cmpl $0x3, %eax
jne 0x133c3
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
callq 0x1c9cc
testq %rax, %rax
je 0x133c3
movq %rax, %rdi
callq 0xd640
movq %rax, %rbp
movq %rax, %rdi
callq 0x130cb
movq %r13, %rdi
leaq 0x1b998(%rip), %rsi     # 0x2ebec
callq 0x1c943
movl %eax, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
cmpl $0x1, %eax
jne 0x133c5
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
callq 0x1c996
testq %rax, %rax
je 0x133c5
movq %rax, %r13
movq %rax, %rdi
leaq 0x1a43b(%rip), %rsi     # 0x2d6c9
callq 0x1c943
movl %eax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
cmpl $0x1, %eax
jne 0x133c5
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c996
testq %rax, %rax
je 0x133c5
movq %rax, %r13
movq %rax, %rdi
leaq 0x1a9f5(%rip), %rsi     # 0x2dcbd
callq 0x1c943
movl %eax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
cmpl $0x4, %eax
jne 0x133c5
movq %r13, %rdi
leaq 0x1b909(%rip), %rsi     # 0x2ebf2
callq 0x1c943
movl %eax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
cmpl $0x4, %eax
jne 0x133c5
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x1c9e5
cvttsd2si (%rax), %rax
movq %rax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x1c9e5
cvttsd2si (%rax), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x1(%rcx), %r8
movq 0x8(%rsp), %r9
incq %r9
movl $0x400, %esi            # imm = 0x400
leaq 0x80(%rsp), %r13
movq %r13, %rdi
leaq 0x1b8ca(%rip), %rdx     # 0x2ec1b
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd260
movq %rbx, %rdi
callq 0xda40
movq %rdx, %rcx
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xda6e
movq %r14, 0x8(%rsp)
testq %r14, %r14
je 0x1340c
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0xd410
movq %rax, %r13
movq %rbp, %rdi
movq %rax, %rsi
callq 0xd390
movl %eax, %r14d
movq %r13, %rdi
callq 0xd090
testl %r14d, %r14d
je 0x133d4
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x1338c
jmp 0x1340c
xorl %ebp, %ebp
incq %r12
cmpq 0x8(%r15), %r12
jl 0x131da
jmp 0x13435
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x8(%rax)
jle 0x1340c
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %r14
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0xda40
movq %rdx, %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xda6e
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0xda40
movq %rdx, %rcx
movq %rbx, %rdi
leaq 0x1bacb(%rip), %rsi     # 0x2eef1
movq %rax, %rdx
callq 0xda6e
movq 0x8(%rsp), %r14
jmp 0x133c5
testq %rbp, %rbp
je 0x13442
movq %rbp, %rdi
callq 0xd090
movl $0x2, 0x18(%rbx)
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq