// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x2008, %rsp           # imm = 0x2008
movl %r8d, %ebp
movq %rcx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq 0x2ca8(%rdi), %rdi
testq %rdi, %rdi
je 0x14829
movb $0x1, 0x292e5(%rip)     # 0x3db00
xorl %esi, %esi
callq 0xd630
movb $0x0, 0x292d7(%rip)     # 0x3db00
movq 0x2880(%rbx), %rdi
callq 0xe3d9
movq 0x2880(%rbx), %rax
movq 0x58(%rax), %rcx
movq $0x0, 0x5f8(%rcx)
movq %rax, 0x2888(%rbx)
testb %bpl, %bpl
je 0x14865
movq 0x40(%r15), %rdi
callq 0x11c40
movq %rax, %rcx
jmp 0x14867
xorl %ecx, %ecx
leaq 0x2ca8(%rbx), %r15
testq %rcx, %rcx
je 0x1488e
leaq 0x1b4d6(%rip), %rdx     # 0x2fd50
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %r14, %r8
xorl %eax, %eax
callq 0xd260
jmp 0x1489e
movq %rsp, %rdi
movl $0x2000, %edx           # imm = 0x2000
movq %r14, %rsi
callq 0xd0b0
movl $0x18, %edi
callq 0xd4c0
movq %rax, %r14
movq 0x2880(%rbx), %rax
movq %rax, (%r14)
movq %rsp, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xf9db
movq %rax, 0x8(%r14)
leaq 0x2cc0(%rbx), %rax
movq %rax, 0x10(%r14)
leaq 0x54(%rip), %rdx        # 0x1492c
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0xd570
movl %eax, %ebp
testl %eax, %eax
je 0x1490a
callq 0xd0a0
movl (%rax), %edi
callq 0xd650
leaq 0x1b45e(%rip), %rdi     # 0x2fd5c
movq %rax, %rsi
xorl %eax, %eax
callq 0xd954
jmp 0x14919
movq 0x2880(%rbx), %rsi
movq %rbx, %rdi
callq 0x13c89
testl %ebp, %ebp
sete %al
addq $0x2008, %rsp           # imm = 0x2008
popq %rbx
popq %r14
popq %r15
popq %rbp
retq