// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce_app.c
// Function: ce_app_run_shell_command
bool ce_app_run_shell_command(CeApp_t* app, const char* command, CeLayout_t* tab_layout, CeView_t* view, bool relative){
#if defined(PLATFORM_WINDOWS)
     if(app->shell_command_thread != INVALID_HANDLE_VALUE){
          g_shell_command_should_die = true;
          WaitForSingleObject(app->shell_command_thread,
                              INFINITE);
          CloseHandle(app->shell_command_thread);
          app->shell_command_thread = INVALID_HANDLE_VALUE;
          g_shell_command_should_die = false;
     }
#else
     if(app->shell_command_thread){
          g_shell_command_should_die = true;
          pthread_join(app->shell_command_thread, NULL);
          g_shell_command_should_die = false;
     }
#endif

     ce_buffer_empty(app->shell_command_buffer);

     CeAppBufferData_t* buffer_data = app->shell_command_buffer->app_data;
     buffer_data->last_goto_destination = 0;
     app->last_goto_buffer = app->shell_command_buffer;

     char* base_directory = relative ? buffer_base_directory(view->buffer) : NULL;

     char updated_command[BUFSIZ];
     if(base_directory){
          snprintf(updated_command, BUFSIZ, "cd %s && %s", base_directory, command);
     }else{
          strncpy(updated_command, command, BUFSIZ);
     }

     ShellCommandData_t* shell_command_data = malloc(sizeof(*shell_command_data));
     shell_command_data->buffer = app->shell_command_buffer;
     shell_command_data->command = ce_strndup(updated_command, BUFSIZ);
     shell_command_data->should_scroll = &app->shell_command_buffer_should_scroll;

#if defined(PLATFORM_WINDOWS)
     app->shell_command_thread = CreateThread(NULL,
                                              0,
                                              run_shell_command_output_to_buffer,
                                              shell_command_data,
                                              0,
                                              &app->shell_command_thread_id);
     if(app->shell_command_thread == NULL){
          ce_log("failed to create thread to run command\n");
          return false;
     }
#else
     int rc = pthread_create(&app->shell_command_thread, NULL, run_shell_command_and_output_to_buffer, shell_command_data);
     if(rc != 0){
          ce_log("pthread_create() failed: '%s'\n", strerror(errno));
          return false;
     }
#endif
     ce_app_open_popup_view(app, app->shell_command_buffer);
     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2000, %rsp           # imm = 0x2000
movl %r8d, %ebp
movq %rcx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq 0x2ca8(%rdi), %rdi
testq %rdi, %rdi
je 0x14568
movb $0x1, 0x285a6(%rip)     # 0x3cb00
xorl %esi, %esi
callq 0xd630
movb $0x0, 0x28598(%rip)     # 0x3cb00
leaq 0x2ca8(%rbx), %r14
movq 0x2880(%rbx), %rdi
callq 0xe396
movq 0x2880(%rbx), %rax
movq 0x58(%rax), %rcx
movq $0x0, 0x5f8(%rcx)
movq %rax, 0x2888(%rbx)
testb %bpl, %bpl
je 0x145ca
movq 0x40(%r12), %rdi
callq 0x11a2b
testq %rax, %rax
je 0x145ca
leaq 0x1a79d(%rip), %rdx     # 0x2ed50
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rax, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xd260
jmp 0x145da
movq %rsp, %rdi
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rsi
callq 0xd0b0
movl $0x18, %edi
callq 0xd4c0
movq %rax, %r15
movq 0x2880(%rbx), %rax
movq %rax, (%r15)
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xf886
movq %rax, 0x8(%r15)
leaq 0x2cc0(%rbx), %rax
movq %rax, 0x10(%r15)
leaq 0x56(%rip), %rdx        # 0x1466a
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rcx
callq 0xd570
movl %eax, %ebp
testl %eax, %eax
je 0x14646
callq 0xd0a0
movl (%rax), %edi
callq 0xd650
leaq 0x1a722(%rip), %rdi     # 0x2ed5c
movq %rax, %rsi
xorl %eax, %eax
callq 0xd954
jmp 0x14655
movq 0x2880(%rbx), %rsi
movq %rbx, %rdi
callq 0x13a6f
testl %ebp, %ebp
sete %al
addq $0x2000, %rsp           # imm = 0x2000
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq