// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_clangd.c
// Function: handle_output_fn
static void* handle_output_fn(void* user_data)
#endif
{
     HandleOutputData_t* data = (HandleOutputData_t*)(user_data);
     // bool sent_definition_request = false;
     ParseResponse_t parse = {};
     strcpy(parse.expected_header_prefix, "Content-Length: ");

     char block[READ_BLOCK_SIZE];
     while(true){
          int64_t bytes_read = ce_subprocess_read_stdout(data->proc, block, (READ_BLOCK_SIZE - 1));
          if(bytes_read <= 0){
#if !defined(PLATFORM_WINDOWS)
               if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR){
                    usleep(1000);
                    continue;
               }
#endif
               break;
          }

          block[bytes_read] = 0;

          // Attempt to parse the messages before we sanitize and print them.
          _parse_response_block(&parse, block, bytes_read);
          if(_parse_response_complete(&parse)){
               CeJsonObj_t* obj = malloc(sizeof(*obj));
               memset(obj, 0, sizeof(*obj));
               if(ce_json_parse(parse.message_body, obj, false)){
                    // DEBUG
                    // char* buffer = malloc(MAX_PRINT_SIZE + 1);
                    // ce_json_obj_to_string(obj, buffer, MAX_PRINT_SIZE, 1);
                    // printf("%s\n", buffer);
                    // free(buffer);
                    if(!_push_response(data->response_queue, obj)){
                         ce_json_obj_free(obj);
                         free(obj);
                    }
               }else{
                    printf("Failed to parse json obj\n");
               }
               _parse_response_free(&parse);
          }

          // sanitize block for non-printable characters
          for(int i = 0; i < bytes_read; i++){
              if(block[i] < 32 && block[i] != '\n') block[i] = '?';
          }
          // Insert into the clangd buffer.
          CePoint_t end = ce_buffer_advance_point(data->buffer,
                                                  ce_buffer_end_point(data->buffer), 1);
          data->buffer->status = CE_BUFFER_STATUS_NONE;
          ce_buffer_insert_string(data->buffer, block, end);
          data->buffer->status = CE_BUFFER_STATUS_READONLY;

#if defined(DISPLAY_TERMINAL)
          int64_t bell_bytes_read = 0;
          do{
               bell_bytes_read = write(g_shell_command_ready_fds[1], "1", 2);
          }while(bell_bytes_read == -1 && errno == EINTR);
#endif
     }

     int status = ce_subprocess_close(data->proc);

#if defined(PLATFORM_WINDOWS)
    (void)(status);
#else
     // TODO: Could compress this with ce_app.c's version.
     if(WIFEXITED(status)){
          snprintf(block, READ_BLOCK_SIZE, "\npid %d exited with code %d", data->proc->pid, WEXITSTATUS(status));
     }else if(WIFSIGNALED(status)){
          snprintf(block, READ_BLOCK_SIZE, "\npid %d killed by signal %d", data->proc->pid, WTERMSIG(status));
     }else if(WIFSTOPPED(status)){
          snprintf(block, READ_BLOCK_SIZE, "\npid %d stopped by signal %d", data->proc->pid, WSTOPSIG(status));
     }else{
          snprintf(block, READ_BLOCK_SIZE, "\npid %d stopped with unexpected status %d", data->proc->pid, status);
     }
#endif

     free(data);
     return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1148, %rsp           # imm = 0x1148
movq %rdi, %rbp
leaq 0x41(%rsp), %rbx
movl $0xff, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd2a0
movups 0x1ae36(%rip), %xmm0    # 0x30124
movaps %xmm0, -0x11(%rbx)
movb $0x0, -0x1(%rbx)
leaq 0x140(%rsp), %rbx
movq %rbp, 0x10(%rsp)
movq 0x8(%rbp), %rdi
movl $0xfff, %edx            # imm = 0xFFF
movq %rbx, %rsi
callq 0x1f844
testq %rax, %rax
jle 0x154ec
movq %rax, %r13
movb $0x0, 0x140(%rsp,%rax)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x130(%rsp), %rbp
testq %rbp, %rbp
jle 0x1538b
testq %r15, %r15
jne 0x15358
movq 0x138(%rsp), %rdi
movq %rbp, %rsi
callq 0xd2c0
movq %rax, %r15
cmpq %rbp, %r15
jge 0x1553a
movb 0x140(%rsp,%r14), %al
movq 0x138(%rsp), %rcx
movb %al, (%rcx,%r15)
incq %r15
movq %rbx, %rbp
incq %r14
movq %rbp, %rbx
cmpq %r14, %r13
jne 0x15333
jmp 0x1553a
testq %r12, %r12
jne 0x1539d
leaq 0x30(%rsp), %rdi
callq 0xd210
movq %rax, %r12
testq %rbx, %rbx
jne 0x153b2
leaq 0xb0(%rsp), %rdi
callq 0xd210
movq %rax, %rbx
cmpq %r12, %rbx
jge 0x153d5
movb 0x140(%rsp,%r14), %al
cmpb 0x30(%rsp,%rbx), %al
jne 0x1548e
movb %al, 0xb0(%rsp,%rbx)
incq %rbx
jmp 0x15378
cmpq $0x80, %rbx
jge 0x15510
movb 0x140(%rsp,%r14), %al
movb %al, 0xb0(%rsp,%rbx)
leaq 0x1(%rbx), %rbp
cmpb $0xd, 0xad(%rsp,%rbx)
jne 0x1537b
cmpb $0xa, 0xae(%rsp,%rbx)
jne 0x1537b
movb 0xaf(%rsp,%rbx), %cl
xorb $0xd, %cl
xorb $0xa, %al
orb %cl, %al
jne 0x1537b
movq $0x0, 0x18(%rsp)
leaq 0xb0(%rsp), %rbx
leaq (%rbx,%r12), %rdi
leaq 0x18(%rsp), %rsi
movl $0xa, %edx
callq 0xd400
movq %rax, 0x130(%rsp)
movq 0x18(%rsp), %rcx
cmpq %rcx, %rbx
je 0x154bf
incq %rax
movq %rax, %rdi
movq %rax, 0x28(%rsp)
movq %rcx, 0x8(%rsp)
callq 0xd4c0
movq %rax, 0x138(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq 0x28(%rsp), %rdx
callq 0xd2a0
movq 0x8(%rsp), %rcx
jmp 0x154e1
leaq 0xb0(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
xorl %ebp, %ebp
jmp 0x1537b
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
cmpq %rcx, %rbx
jne 0x1537b
jmp 0x1553a
callq 0xd0a0
movl (%rax), %eax
cmpl $0xb, %eax
je 0x15501
cmpl $0x4, %eax
jne 0x1579f
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xd740
jmp 0x15303
leaq 0xb0(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x138(%rsp), %rbx
testq %rbx, %rbx
movq 0x10(%rsp), %rbp
leaq 0xb0(%rsp), %r14
je 0x156e9
movq %rbx, %rdi
callq 0xd210
cmpq 0x130(%rsp), %rax
jne 0x156e9
movl $0x10, %edi
callq 0xd4c0
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1c61b
testb %al, %al
je 0x155fb
movq 0x10(%rbp), %r14
movq %r15, %rdi
leaq 0x1ba82(%rip), %rsi     # 0x31022
callq 0x1c543
movl %eax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq $-0x1, %rbx
cmpl $0x4, %eax
jne 0x155d1
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1c5e5
testq %rax, %rax
je 0x155d1
cvttsd2si (%rax), %rbx
movq %rbx, 0x8(%rsp)
leaq 0x10(%r14), %r12
movq %r12, %rdi
callq 0xd700
movl %eax, %ebx
testl %eax, %eax
je 0x1560c
movl %ebx, %edi
leaq 0x1ab44(%rip), %r12     # 0x30135
leaq 0xb0(%rsp), %r14
jmp 0x15675
leaq 0x1abb7(%rip), %rdi     # 0x301b9
callq 0xd120
jmp 0x1569b
movq (%r14), %rbp
movq 0x8(%r14), %rdi
leaq 0x8(,%rbp,8), %rax
incq %rbp
leaq (%rax,%rax,2), %rsi
callq 0xd520
movq %rax, 0x8(%r14)
movq (%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rcx,8)
movq $0x0, 0x10(%rax,%rcx,8)
movq 0x8(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
movq %r15, 0x8(%rax,%rcx,8)
movq %rbp, (%r14)
movq 0x10(%rsp), %rbp
movq %r12, %rdi
callq 0xd490
testl %eax, %eax
leaq 0xb0(%rsp), %r14
je 0x15687
movl %eax, %edi
leaq 0x1aaf1(%rip), %r12     # 0x30166
callq 0xd650
movq %r12, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xd954
testl %ebx, %ebx
je 0x1569b
movq %r15, %rdi
callq 0x1c2e8
movq %r15, %rdi
callq 0xd090
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%r14)
movups %xmm0, 0x60(%r14)
movups %xmm0, 0x50(%r14)
movups %xmm0, 0x40(%r14)
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x20(%r14)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0x156e9
xorl %ebx, %ebx
movq %rbx, 0x130(%rsp)
callq 0xd090
movq %rbx, 0x138(%rsp)
cmpq $0x2, %r13
movl $0x1, %eax
cmovlq %rax, %r13
xorl %eax, %eax
leaq 0x28405(%rip), %r14     # 0x3db04
leaq 0x1a7f1(%rip), %r15     # 0x2fef7
movb 0x140(%rsp,%rax), %cl
cmpb $0x20, %cl
setge %dl
cmpb $0xa, %cl
sete %cl
orb %dl, %cl
jne 0x15725
movb $0x3f, 0x140(%rsp,%rax)
incq %rax
cmpq %rax, %r13
jne 0x15706
movq (%rbp), %rbx
movq %rbx, %rdi
callq 0xda40
movl $0x1, %ecx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xeffa
movq %rdx, %rcx
movq (%rbp), %rdi
movl $0x0, 0x18(%rdi)
leaq 0x140(%rsp), %rbx
movq %rbx, %rsi
movq %rax, %rdx
callq 0xda6e
movq (%rbp), %rax
movl $0x2, 0x18(%rax)
movl 0x4(%r14), %edi
movl $0x2, %edx
movq %r15, %rsi
callq 0xd1d0
cmpq $-0x1, %rax
jne 0x15303
callq 0xd0a0
cmpl $0x4, (%rax)
je 0x15775
jmp 0x15303
movq 0x8(%rbp), %rdi
callq 0x1f783
movl %eax, %r8d
andl $0x7f, %r8d
je 0x157e1
movl %r8d, %ecx
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x157f3
movq 0x8(%rbp), %rax
movl (%rax), %ecx
leaq 0x1a7c2(%rip), %rdx     # 0x2ff94
leaq 0x140(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
jmp 0x15820
movq 0x8(%rbp), %rcx
movl (%rcx), %ecx
movzbl %ah, %eax
leaq 0x1a787(%rip), %rdx     # 0x2ff78
jmp 0x15810
movq 0x8(%rbp), %rcx
movl (%rcx), %ecx
cmpb $0x7f, %al
jne 0x15809
movzbl %ah, %eax
leaq 0x1a7a9(%rip), %rdx     # 0x2ffb0
jmp 0x15810
leaq 0x1a7bd(%rip), %rdx     # 0x2ffcd
leaq 0x140(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movl %eax, %r8d
xorl %eax, %eax
callq 0xd260
movq %rbp, %rdi
callq 0xd090
xorl %eax, %eax
addq $0x1148, %rsp           # imm = 0x1148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq