// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_clangd.c
// Function: ce_clangd_init
bool ce_clangd_init(const char* executable_path,
                    CeClangD_t* clangd){
     char command[MAX_COMMAND_SIZE];
     // DEBUG
     // snprintf(command, MAX_COMMAND_SIZE, "%s --log=verbose", executable_path);
     snprintf(command, MAX_COMMAND_SIZE, "%s", executable_path);
     bool use_shell = false;
     if(!ce_subprocess_open(&clangd->proc, command, CE_PROC_COMM_STDIN | CE_PROC_COMM_STDOUT, use_shell)){
          return false;
     }

     HandleOutputData_t* thread_data = malloc(sizeof(*thread_data));
     thread_data->buffer = clangd->buffer;
     thread_data->proc = &clangd->proc;
     thread_data->response_queue = &clangd->response_queue;

#if defined(PLATFORM_WINDOWS)
     clangd->response_queue.mutex = CreateMutex(NULL, false, NULL);
     if(clangd->response_queue.mutex == NULL){
          ce_log("Failed to create clangd mutex\n");
          return false;
     }

     clangd->thread_handle = CreateThread(NULL,
                                          0,
                                          handle_output_fn,
                                          thread_data,
                                          0,
                                          &clangd->thread_id);
     if(clangd->thread_handle == INVALID_HANDLE_VALUE){
          ce_log("failed to create thread to run command\n");
          return false;
     }
#else
     int rc = pthread_create(&clangd->thread, NULL, handle_output_fn, thread_data);
     if(rc != 0){
          ce_log("pthread_create() failed: '%s'\n", strerror(errno));
          return false;
     }

     rc = pthread_mutex_init(&clangd->response_queue.mutex, NULL);
     if(rc != 0){
          ce_log("pthread_mutex_init() failed: %s\n", strerror(rc));
          return false;
     }
#endif

     // Build our initialization structure.
     CeJsonObj_t initialize_obj = {};
     ce_json_obj_set_string(&initialize_obj, "jsonrpc", "2.0");
     ce_json_obj_set_number(&initialize_obj, "id", 0);
     ce_json_obj_set_string(&initialize_obj, "method", "initialize");

     char cwd[MAX_PATH_LEN + 1];
     char cwd_uri[MAX_PATH_LEN + 16];

     CeJsonObj_t params_obj = {};

#if defined(PLATFORM_WINDOWS)
     DWORD pid = GetCurrentProcessId();
     _getcwd(cwd, MAX_PATH_LEN);
#else
     pid_t pid = getpid();
     getcwd(cwd, MAX_PATH_LEN);
#endif
     ce_json_obj_set_number(&params_obj, "processId", (double)(pid));

#if defined(PLATFORM_WINDOWS)
     strncpy(cwd_uri, cwd, MAX_PATH_LEN);
     _convert_windows_path_to_uri(cwd_uri, MAX_PATH_LEN);
     char* json_cwd = _convert_string_to_json_string(cwd);
#else
     snprintf(cwd_uri, MAX_PATH_LEN + 15, "file://%s", cwd);
     char* json_cwd = _convert_string_to_json_string(cwd);
#endif

     ce_json_obj_set_string(&params_obj, "rootPath", json_cwd);
     ce_json_obj_set_string(&params_obj, "rootUri", cwd_uri);
     ce_json_obj_set_obj(&initialize_obj, "params", &params_obj);

     CeJsonObj_t client_info_obj = {};
     ce_json_obj_set_string(&client_info_obj, "name", "ce");
     ce_json_obj_set_string(&client_info_obj, "version", "9.8.7");
     ce_json_obj_set_obj(&initialize_obj, "ClientInfo", &client_info_obj);

     bool result = _send_json_obj(&initialize_obj, &clangd->proc);
     ce_json_obj_free(&initialize_obj);
     ce_json_obj_free(&params_obj);
     ce_json_obj_free(&client_info_obj);

     free(json_cwd);
     return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xca0, %rsp            # imm = 0xCA0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x400, %esi            # imm = 0x400
leaq 0x2bf80(%rip), %rdx     # 0x45bda
movb $0x0, %al
callq 0xd250
movb $0x0, -0x421(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
leaq -0x420(%rbp), %rsi
movb -0x421(%rbp), %al
movl $0x3, %edx
andb $0x1, %al
movzbl %al, %ecx
callq 0x2abf0
testb $0x1, %al
jne 0x19c99
movb $0x0, -0x1(%rbp)
jmp 0x19f5c
movl $0x18, %edi
callq 0xd4a0
movq %rax, -0x430(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x430(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movq -0x430(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
addq $0x38, %rcx
movq -0x430(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdi
movq -0x430(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0x278(%rip), %rdx       # 0x19f70
callq 0xd550
movl %eax, -0x434(%rbp)
cmpl $0x0, -0x434(%rbp)
je 0x19d32
callq 0xd0a0
movl (%rax), %edi
callq 0xd630
movq %rax, %rsi
leaq 0x29fed(%rip), %rdi     # 0x43d0f
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0x19f5c
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd6a0
movl %eax, -0x434(%rbp)
cmpl $0x0, -0x434(%rbp)
je 0x19d7b
movl -0x434(%rbp), %edi
callq 0xd630
movq %rax, %rsi
leaq 0x2a23f(%rip), %rdi     # 0x43faa
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0x19f5c
leaq -0x448(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd290
leaq -0x448(%rbp), %rdi
leaq 0x2a22f(%rip), %rsi     # 0x43fcb
leaq 0x2a230(%rip), %rdx     # 0x43fd3
callq 0x25860
leaq -0x448(%rbp), %rdi
leaq 0x2b260(%rip), %rsi     # 0x45016
xorps %xmm0, %xmm0
callq 0x25920
leaq -0x448(%rbp), %rdi
leaq 0x29ea5(%rip), %rsi     # 0x43c71
leaq 0x2a204(%rip), %rdx     # 0x43fd7
callq 0x25860
leaq -0xc70(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd290
callq 0xd1d0
movl %eax, -0xc74(%rbp)
leaq -0x850(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0xd2c0
cvtsi2sdl -0xc74(%rbp), %xmm0
leaq -0xc70(%rbp), %rdi
leaq 0x2a1c5(%rip), %rsi     # 0x43fe2
callq 0x25920
leaq -0xc60(%rbp), %rdi
leaq -0x850(%rbp), %rcx
movl $0x40f, %esi            # imm = 0x40F
leaq 0x2a1b0(%rip), %rdx     # 0x43fec
movb $0x0, %al
callq 0xd250
leaq -0x850(%rbp), %rdi
callq 0x1a350
movq %rax, -0xc80(%rbp)
movq -0xc80(%rbp), %rdx
leaq -0xc70(%rbp), %rdi
leaq 0x2a18b(%rip), %rsi     # 0x43ff6
callq 0x25860
leaq -0xc60(%rbp), %rdx
leaq -0xc70(%rbp), %rdi
leaq 0x2a17a(%rip), %rsi     # 0x43fff
callq 0x25860
leaq -0x448(%rbp), %rdi
leaq 0x29d15(%rip), %rsi     # 0x43bad
leaq -0xc70(%rbp), %rdx
callq 0x25560
leaq -0xc90(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd290
leaq -0xc90(%rbp), %rdi
leaq 0x29773(%rip), %rsi     # 0x43638
leaq 0x2822c(%rip), %rdx     # 0x420f8
callq 0x25860
leaq -0xc90(%rbp), %rdi
leaq 0x2a128(%rip), %rsi     # 0x44007
leaq 0x2a129(%rip), %rdx     # 0x4400f
callq 0x25860
leaq -0x448(%rbp), %rdi
leaq 0x2a11c(%rip), %rsi     # 0x44015
leaq -0xc90(%rbp), %rdx
callq 0x25560
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
leaq -0x448(%rbp), %rdi
callq 0x1a680
andb $0x1, %al
movb %al, -0xc91(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x25b50
leaq -0xc70(%rbp), %rdi
callq 0x25b50
leaq -0xc90(%rbp), %rdi
callq 0x25b50
movq -0xc80(%rbp), %rdi
callq 0xd090
movb -0xc91(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xca0, %rsp            # imm = 0xCA0
popq %rbp
retq
nopw (%rax,%rax)