// File: /workspace/github_c_makefile_star2_O1/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 0xe3d9
leaq 0x1c80f(%rip), %rsi     # 0x2fbb7
movq %r15, %rdi
callq 0x1c543
movl %eax, 0x70(%rsp)
movq %rdx, 0x78(%rsp)
cmpl $0x2, %eax
jne 0x1365b
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x1c5b1
testq %rax, %rax
je 0x1365b
movq %rax, %r15
cmpq $0x0, 0x8(%rax)
jle 0x13645
movq %r14, 0x18(%rsp)
leaq 0x1c80f(%rip), %r14     # 0x2fc01
xorl %ebp, %ebp
xorl %r12d, %r12d
testq %rbp, %rbp
je 0x13404
movq %rbp, %rdi
callq 0xd090
movq (%r15), %rax
leaq (%r12,%r12,2), %rcx
cmpl $0x1, (%rax,%rcx,8)
jne 0x13634
leaq (%rax,%rcx,8), %r13
addq $0x8, %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x1c543
movl %eax, 0x60(%rsp)
movq %rdx, 0x68(%rsp)
cmpl $0x3, %eax
jne 0x13634
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
callq 0x1c5cc
testq %rax, %rax
je 0x13634
movq %rax, %rdi
callq 0xd640
movq %rax, %rbp
movq %rax, %rdi
callq 0x132c6
movq %r13, %rdi
leaq 0x1c77d(%rip), %rsi     # 0x2fbea
callq 0x1c543
movl %eax, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
cmpl $0x1, %eax
jne 0x13636
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
callq 0x1c596
testq %rax, %rax
je 0x13636
movq %rax, %r13
movq %rax, %rdi
leaq 0x1b222(%rip), %rsi     # 0x2e6c9
callq 0x1c543
movl %eax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
cmpl $0x1, %eax
jne 0x13636
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x1c596
testq %rax, %rax
je 0x13636
movq %rax, %r13
movq %rax, %rdi
leaq 0x1b7da(%rip), %rsi     # 0x2ecbb
callq 0x1c543
movl %eax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
cmpl $0x4, %eax
jne 0x13636
movq %r13, %rdi
leaq 0x1c6ee(%rip), %rsi     # 0x2fbf0
callq 0x1c543
movl %eax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
cmpl $0x4, %eax
jne 0x13636
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x1c5e5
cvttsd2si (%rax), %rax
movq %rax, (%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x1c5e5
cvttsd2si (%rax), %rax
movq %rax, 0x10(%rsp)
leaq 0x1(%rax), %r8
movq (%rsp), %r9
incq %r9
movl $0x400, %esi            # imm = 0x400
leaq 0x80(%rsp), %r13
movq %r13, %rdi
leaq 0x1c6b1(%rip), %rdx     # 0x2fc19
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd260
movq %rbx, %rdi
callq 0xda40
movq %rdx, %rcx
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xda6e
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x13610
movq (%rbx), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0xd410
movq %rax, %r14
movq %rbp, %rdi
movq %rax, %rsi
callq 0xd390
movl %eax, %r13d
movq %r14, %rdi
callq 0xd090
testl %r13d, %r13d
je 0x135cc
movq 0x8(%rbx), %rbx
jmp 0x13604
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x8(%rax)
jle 0x13604
movq (%rax), %rax
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xda40
movq %rdx, %rcx
movq %r14, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
callq 0xda6e
leaq 0x1c5f6(%rip), %r14     # 0x2fc01
testl %r13d, %r13d
jne 0x13595
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xda40
movq %rdx, %rcx
movq %rbx, %rdi
leaq 0x1c8cb(%rip), %rsi     # 0x2fef5
movq %rax, %rdx
callq 0xda6e
jmp 0x13636
xorl %ebp, %ebp
incq %r12
cmpq 0x8(%r15), %r12
jl 0x133f7
jmp 0x13647
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x13654
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