// File: /workspace/github_c_makefile_star2_O2/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 0x13c2b
movb $0x1, 0x27ee3(%rip)     # 0x3bb00
xorl %esi, %esi
callq 0xd630
movb $0x0, 0x27ed5(%rip)     # 0x3bb00
leaq 0x2ca8(%rbx), %r14
movq 0x2880(%rbx), %rdi
callq 0xe2e2
movq 0x2880(%rbx), %rax
movq 0x58(%rax), %rcx
andq $0x0, 0x5f8(%rcx)
movq %rax, 0x2888(%rbx)
testb %bpl, %bpl
je 0x13c8a
movq 0x40(%r12), %rdi
callq 0x1132c
testq %rax, %rax
je 0x13c8a
leaq 0x180dd(%rip), %rdx     # 0x2bd50
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %rax, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0xd260
jmp 0x13c9a
movq %rsp, %rdi
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rsi
callq 0xd0b0
pushq $0x18
popq %rdi
callq 0xd4c0
movq %rax, %r15
movq 0x2880(%rbx), %rax
movq %rax, (%r15)
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xf56b
movq %rax, 0x8(%r15)
leaq 0x2cc0(%rbx), %rax
movq %rax, 0x10(%r15)
leaq 0x56(%rip), %rdx        # 0x13d28
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rcx
callq 0xd570
movl %eax, %ebp
testl %eax, %eax
je 0x13d04
callq 0xd0a0
movl (%rax), %edi
callq 0xd650
leaq 0x18064(%rip), %rdi     # 0x2bd5c
movq %rax, %rsi
xorl %eax, %eax
callq 0xd8e5
jmp 0x13d13
movq 0x2880(%rbx), %rsi
movq %rbx, %rdi
callq 0x13236
testl %ebp, %ebp
sete %al
addq $0x2000, %rsp           # imm = 0x2000
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq