// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x2cf8(%rax)
jne 0x173e2
jmp 0x1784d
jmp 0x173e4
movq -0x8(%rbp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
callq 0x1b280
testb $0x1, %al
jne 0x173fd
jmp 0x1784d
movq -0x8(%rbp), %rsi
addq $0x2cd0, %rsi           # imm = 0x2CD0
leaq -0x20(%rbp), %rdi
callq 0x1b2a0
cmpq $0x0, -0x10(%rbp)
je 0x1770f
movq -0x10(%rbp), %rdi
leaq 0x2c7b1(%rip), %rsi     # 0x43bd8
callq 0xd370
cmpl $0x0, %eax
je 0x17474
movq -0x10(%rbp), %rdi
leaq 0x2c7b8(%rip), %rsi     # 0x43bf4
callq 0xd370
cmpl $0x0, %eax
je 0x17474
movq -0x10(%rbp), %rdi
leaq 0x2c7bb(%rip), %rsi     # 0x43c0c
callq 0xd370
cmpl $0x0, %eax
je 0x17474
movq -0x10(%rbp), %rdi
leaq 0x2c7bf(%rip), %rsi     # 0x43c25
callq 0xd370
cmpl $0x0, %eax
jne 0x1750d
movq -0x8(%rbp), %rax
movq 0x2818(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x17860
movq -0x8(%rbp), %rdi
addq $0x2828, %rdi           # imm = 0x2828
movq -0x30(%rbp), %rsi
movq -0x8(%rbp), %rdx
addq $0x1a50, %rdx           # imm = 0x1A50
movq -0x8(%rbp), %rcx
addq $0x20, %rcx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq -0x440(%rbp), %rax
movq %rax, (%rsp)
callq 0x17ab0
cmpq $0x0, %rax
je 0x17508
movq -0x8(%rbp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
movq -0x8(%rbp), %rax
movq 0x2828(%rax), %rax
movq (%rax), %rsi
callq 0x1a760
jmp 0x1770a
movq -0x10(%rbp), %rdi
leaq 0x2c729(%rip), %rsi     # 0x43c41
callq 0xd370
cmpl $0x0, %eax
jne 0x176aa
movq -0x8(%rbp), %rax
cmpq $0x0, 0x2d70(%rax)
je 0x17554
movq -0x8(%rbp), %rax
movq 0x2d70(%rax), %rdi
callq 0x221f0
movq -0x8(%rbp), %rax
movq 0x2d70(%rax), %rdi
callq 0xd090
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x2d50, %rsi           # imm = 0x2D50
callq 0x161f0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x2d70(%rax)
movq -0x8(%rbp), %rax
movq 0x2818(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x448(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x2d70(%rax)
je 0x176a8
movq -0x448(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax)
jne 0x176a8
movq -0x448(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x8, %rax
movq %rax, -0x450(%rbp)
movq -0x450(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0x2d50(%rcx), %rax
movq %rax, -0x458(%rbp)
cmpq $0x0, -0x458(%rbp)
jle 0x17642
movq -0x450(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x8(%rbp), %rax
movq -0x458(%rbp), %rcx
movq 0x2d50(%rax), %rsi
movq 0x2d58(%rax), %rdx
callq 0x10900
movq %rax, -0x460(%rbp)
movq -0x8(%rbp), %rax
movq 0x2d70(%rax), %rdi
movq -0x460(%rbp), %rsi
callq 0x222f0
movq -0x460(%rbp), %rdi
callq 0xd090
movq -0x8(%rbp), %rax
movq 0x2d78(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x2d70(%rax), %rsi
callq 0x14d80
movq -0x8(%rbp), %rdi
addq $0x2d50, %rdi           # imm = 0x2D50
addq $0x30, %rdi
movq -0x8(%rbp), %rdx
movq -0x450(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x2d78(%rax), %r8
movq -0x8(%rbp), %r9
addq $0x1a50, %r9            # imm = 0x1A50
movq -0x8(%rbp), %rax
movq 0x2d50(%rdx), %rsi
movq 0x2d58(%rdx), %rdx
movq %rax, (%rsp)
callq 0x167b0
jmp 0x17708
movq -0x10(%rbp), %rdi
leaq 0x2c5a4(%rip), %rsi     # 0x43c59
callq 0xd370
cmpl $0x0, %eax
jne 0x17706
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x2898(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x2828(%rax), %rdx
callq 0x16f60
movq -0x8(%rbp), %rax
movq 0x2898(%rax), %rax
cmpq $0x0, 0x8(%rax)
jle 0x17704
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x2898(%rax), %rsi
callq 0x17c50
jmp 0x17706
jmp 0x17708
jmp 0x1770a
jmp 0x1783f
movq -0x18(%rbp), %rdi
leaq 0x2c557(%rip), %rsi     # 0x43c71
callq 0x25e70
movl %eax, -0x470(%rbp)
movq %rdx, -0x468(%rbp)
cmpl $0x3, -0x470(%rbp)
jne 0x1783d
movq -0x18(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x25fb0
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
je 0x1783b
movq -0x478(%rbp), %rdi
leaq 0x2c50c(%rip), %rsi     # 0x43c78
callq 0xd370
cmpl $0x0, %eax
jne 0x17839
movq -0x18(%rbp), %rsi
leaq -0x490(%rbp), %rdi
callq 0x16a40
cmpq $0x0, -0x480(%rbp)
je 0x17837
movq -0x8(%rbp), %rax
movq 0x2828(%rax), %rdi
movq -0x480(%rbp), %rsi
callq 0x14350
movq %rax, -0x498(%rbp)
cmpq $0x0, -0x498(%rbp)
je 0x17829
movq -0x498(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x4a0(%rbp)
movq -0x4a0(%rbp), %rax
cmpq $0x0, 0x618(%rax)
jle 0x177f6
movq -0x4a0(%rbp), %rdi
addq $0x610, %rdi            # imm = 0x610
callq 0x1b6c0
movq -0x4a0(%rbp), %rax
movq -0x490(%rbp), %rcx
movq %rcx, 0x610(%rax)
movq -0x488(%rbp), %rcx
movq %rcx, 0x618(%rax)
movq -0x480(%rbp), %rcx
movq %rcx, 0x620(%rax)
jmp 0x17835
leaq -0x490(%rbp), %rdi
callq 0x1b6c0
jmp 0x17837
jmp 0x17839
jmp 0x1783b
jmp 0x1783d
jmp 0x1783f
leaq -0x20(%rbp), %rdi
callq 0x1b5d0
jmp 0x173e4
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopw %cs:(%rax,%rax)