// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce_app.c
// Function: ce_app_handle_clangd_response
void ce_app_handle_clangd_response(CeApp_t* app){
     if(app->clangd.buffer == NULL){
          return;
     }
     while(ce_clangd_outstanding_responses(&app->clangd)){
          CeClangDResponse_t response = ce_clangd_pop_response(&app->clangd);
          if(response.method != NULL){
               if(strcmp(response.method, "textDocument/typeDefinition") == 0 ||
                  strcmp(response.method, "textDocument/definition") == 0 ||
                  strcmp(response.method, "textDocument/declaration") == 0 ||
                  strcmp(response.method, "textDocument/implementation") == 0){
                    CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;
                    CeView_t* view = &tab_layout->tab.current->view;
                    CeDestination_t dest = _extract_destination_from_range_response(response.obj);
                    if(load_destination_into_view(&app->buffer_node_head,
                                                  view,
                                                  &app->config_options,
                                                  &app->vim,
                                                  true,
                                                  NULL,
                                                  &dest)){
                         ce_clangd_file_open(&app->clangd, app->buffer_node_head->buffer);
                    }
               }else if(strcmp(response.method, "textDocument/completion") == 0){
                    if(app->clangd_completion.complete){
                         ce_complete_free(app->clangd_completion.complete);
                         free(app->clangd_completion.complete);
                    }
                    app->clangd_completion.complete = _extract_completion_from_response(response.obj,
                                                                                        &app->clangd_completion.start);
                    CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;
                    if(app->clangd_completion.complete &&
                       tab_layout->tab.current->type == CE_LAYOUT_TYPE_VIEW){
                         CeView_t* completed_view = &tab_layout->tab.current->view;
                         int64_t match_len = completed_view->cursor.x - app->clangd_completion.start.x;
                         if(match_len > 0){
                              char* match = ce_buffer_dupe_string(completed_view->buffer, app->clangd_completion.start, match_len);
                              ce_complete_match(app->clangd_completion.complete, match);
                              free(match);
                         }
                         build_complete_list(app->clangd_completion.buffer,
                                             app->clangd_completion.complete);
                         build_clangd_completion_view(&app->clangd_completion.view,
                                                      app->clangd_completion.start,
                                                      completed_view,
                                                      app->clangd_completion.buffer,
                                                      &app->config_options,
                                                      &app->terminal_rect);
                    }
               }else if(strcmp(response.method, "textDocument/references") == 0){
                   _extract_reference_locations_to_buffer(response.obj, app->clangd_references_buffer,
                                                          app->buffer_node_head);
                   if(app->clangd_references_buffer->line_count > 0){
                       ce_app_open_popup_view(app, app->clangd_references_buffer);
                   }
               }
          }else{
               CeJsonFindResult_t method_find = ce_json_obj_find(response.obj, "method");
               if(method_find.type == CE_JSON_TYPE_STRING){
                    const char* method = ce_json_obj_get_string(response.obj, &method_find);
                    if(method != NULL){
                        if(strcmp(method, "textDocument/publishDiagnostics") == 0){
                            CeClangDDiagnostics_t diagnostics = _extract_diagnostics_from_response(response.obj);
                            if(diagnostics.filepath != NULL){
                                // DEBUG
                                // printf("diags: %s %lld\n", diagnostics.filepath, diagnostics.count);
                                // for(int64_t i = 0; i < diagnostics.count; i++){
                                //     CeClangDDiagnostic_t* diag = diagnostics.elements + i;
                                //     printf("  %lld, %lld -> %lld, %lld %s\n",
                                //            diag->start.x, diag->start.y, diag->end.x, diag->end.y,
                                //            diag->message);
                                // }
                                CeBuffer_t* buffer = find_already_loaded_file(app->buffer_node_head, diagnostics.filepath);
                                if(buffer){
                                    CeAppBufferData_t* app_data = (CeAppBufferData_t*)(buffer->app_data);
                                    if(app_data->clangd_diagnostics.count > 0){
                                        ce_clangd_diag_free(&app_data->clangd_diagnostics);
                                    }
                                    memcpy(&app_data->clangd_diagnostics, &diagnostics, sizeof(diagnostics));
                                }else{
                                    ce_clangd_diag_free(&diagnostics);
                                }
                            }
                        }
                    }
               }
          }
          ce_clangd_response_free(&response);
     }
}

// Assembly:
cmpq $0x0, 0x2cf8(%rdi)
je 0x139a7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rdi, %rbx
leaq 0x2cd0(%rdi), %r14
movq %r14, %rdi
callq 0x15e0d
testb %al, %al
je 0x13996
leaq 0x2828(%rbx), %r15
leaq 0x2d50(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x2d80(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x1a50(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x28(%rsp), %r12
movq %r15, 0x48(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x15e16
movq 0x38(%rsp), %r13
testq %r13, %r13
je 0x137d0
movq %r13, %rdi
leaq 0x1b732(%rip), %rsi     # 0x2ec27
callq 0xd390
testl %eax, %eax
je 0x135a4
movq %r13, %rdi
leaq 0x1b737(%rip), %rsi     # 0x2ec43
callq 0xd390
testl %eax, %eax
je 0x135a4
movq %r13, %rdi
leaq 0x1b738(%rip), %rsi     # 0x2ec5b
callq 0xd390
testl %eax, %eax
je 0x135a4
movq %r13, %rdi
leaq 0x1b73e(%rip), %rsi     # 0x2ec74
callq 0xd390
testl %eax, %eax
je 0x135a4
movq %r13, %rdi
leaq 0x1b747(%rip), %rsi     # 0x2ec90
callq 0xd390
testl %eax, %eax
je 0x138a3
movq %r13, %rdi
leaq 0x1b748(%rip), %rsi     # 0x2eca8
callq 0xd390
testl %eax, %eax
jne 0x13816
movq 0x30(%rsp), %rdi
movq 0x2828(%rbx), %rdx
movq 0x2898(%rbx), %rsi
callq 0x13167
movq 0x2898(%rbx), %rsi
cmpq $0x0, 0x8(%rsi)
jle 0x13816
movq %rbx, %rdi
callq 0x13a6f
jmp 0x13816
movq 0x2818(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rbp
movq 0x30(%rsp), %r13
movl $0x410, %edx            # imm = 0x410
leaq 0xa8(%rsp), %rdi
xorl %esi, %esi
callq 0xd2a0
movq %r13, %rdi
leaq 0x1b5e3(%rip), %rsi     # 0x2ebb9
callq 0x1c943
movl %eax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x2, %eax
jne 0x1378d
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1c9b1
testq %rax, %rax
je 0x1378d
movq %rax, %r13
cmpq $0x0, 0x8(%rax)
je 0x1378d
movq (%r13), %rdi
cmpl $0x1, (%rdi)
jne 0x1378d
addq $0x8, %rdi
leaq 0x1b5c3(%rip), %rsi     # 0x2ebec
callq 0x1c943
movl %eax, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
cmpl $0x1, %eax
jne 0x13788
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x58(%rsp), %rsi
callq 0x1c996
testq %rax, %rax
je 0x13788
movq %rax, %r15
movq %rax, %rdi
leaq 0x1a061(%rip), %rsi     # 0x2d6c9
callq 0x1c943
movl %eax, 0x98(%rsp)
movq %rdx, 0xa0(%rsp)
cmpl $0x1, 0x58(%rsp)
jne 0x13788
movq %r15, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1c996
testq %rax, %rax
je 0x13788
movq %rax, %r15
movq %rax, %rdi
leaq 0x1b545(%rip), %rsi     # 0x2ebf2
callq 0x1c943
movl %eax, 0x88(%rsp)
movq %rdx, 0x90(%rsp)
cmpl $0x4, %eax
jne 0x13788
movq %r15, %rdi
leaq 0x88(%rsp), %rsi
callq 0x1c9e5
testq %rax, %rax
je 0x13788
cvttsd2si (%rax), %rax
movq %rax, 0xa8(%rsp)
movq %r15, %rdi
leaq 0x1a5c3(%rip), %rsi     # 0x2dcbd
callq 0x1c943
movl %eax, 0x78(%rsp)
movq %rdx, 0x80(%rsp)
cmpl $0x4, %eax
jne 0x13788
movq %r15, %rdi
leaq 0x78(%rsp), %rsi
callq 0x1c9e5
testq %rax, %rax
je 0x13788
cvttsd2si (%rax), %rax
movq %rax, 0xb0(%rsp)
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x1b4c5(%rip), %rsi     # 0x2ec03
callq 0x1c943
movl %eax, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
cmpl $0x3, %eax
jne 0x13788
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x68(%rsp), %rsi
callq 0x1c9cc
testq %rax, %rax
je 0x13788
movl $0x3ff, %edx            # imm = 0x3FF
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0xd0b0
movq %r15, %rdi
callq 0x130cb
movq 0x48(%rsp), %r15
addq $0x8, %rbp
leaq 0xa8(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
movq 0x50(%rsp), %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x139a8
testq %rax, %rax
je 0x13816
movq (%r15), %rax
movq (%rax), %rsi
movq %r14, %rdi
callq 0x15667
jmp 0x13816
movq 0x30(%rsp), %rdi
leaq 0x1b4e4(%rip), %rsi     # 0x2ecc0
callq 0x1c943
movl %eax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x3, %eax
jne 0x13816
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1c9cc
testq %rax, %rax
je 0x13816
movq %rax, %rdi
leaq 0x1b4ba(%rip), %rsi     # 0x2ecc7
callq 0xd390
testl %eax, %eax
je 0x13833
movq %r12, %rdi
callq 0x15fcc
movq %r14, %rdi
callq 0x15e0d
testb %al, %al
jne 0x134d2
jmp 0x13996
movq 0x30(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x12d9c
movq 0xb8(%rsp), %rsi
testq %rsi, %rsi
je 0x13816
movq (%r15), %rdi
callq 0x11620
testq %rax, %rax
je 0x13984
movq %r15, %r13
movq 0x58(%rax), %rax
leaq 0x610(%rax), %r15
cmpq $0x0, 0x618(%rax)
jle 0x13883
movq %r15, %rdi
callq 0x16062
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%r15)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%r15)
movq %r13, %r15
jmp 0x13816
movq 0x2d70(%rbx), %rdi
testq %rdi, %rdi
je 0x138c0
callq 0x199ea
movq 0x2d70(%rbx), %rdi
callq 0xd090
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x12805
movq %rax, 0x2d70(%rbx)
testq %rax, %rax
je 0x13816
movq 0x2818(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x10(%rcx), %r13
cmpl $0x0, (%r13)
jne 0x13816
movq 0x38(%r13), %rcx
movq 0x8(%rsp), %rdx
movq (%rdx), %rsi
subq %rsi, %rcx
jle 0x13941
movq 0x48(%r13), %rdi
movq 0x2d58(%rbx), %rdx
callq 0xf60a
movq %r15, %rbp
movq %rax, %r15
movq 0x2d70(%rbx), %rdi
movq %rax, %rsi
callq 0x19fcd
movq %r15, %rdi
movq %rbp, %r15
callq 0xd090
movq 0x2d70(%rbx), %rax
addq $0x8, %r13
movq 0x2d78(%rbx), %rdi
movq %rax, %rsi
callq 0x11c24
movq 0x2d78(%rbx), %r8
movq 0x2d50(%rbx), %rsi
movq 0x2d58(%rbx), %rdx
movq %rbx, (%rsp)
movq 0x40(%rsp), %rdi
movq %r13, %rcx
movq 0x10(%rsp), %r9
callq 0x12c53
jmp 0x13816
leaq 0xa8(%rsp), %rdi
callq 0x16062
jmp 0x13816
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq