// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2ca8(%rax)
je 0x18dd3
movb $0x1, 0x37df8(%rip)     # 0x50bb0
movq -0x10(%rbp), %rax
movq 0x2ca8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd610
movb $0x0, 0x37ddd(%rip)     # 0x50bb0
movq -0x10(%rbp), %rax
movq 0x2880(%rax), %rdi
callq 0xe920
movq -0x10(%rbp), %rax
movq 0x2880(%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, 0x5f8(%rax)
movq -0x10(%rbp), %rax
movq 0x2880(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x2888(%rax)
testb $0x1, -0x29(%rbp)
je 0x18e37
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x149f0
movq %rax, -0x2058(%rbp)
jmp 0x18e42
xorl %eax, %eax
movq %rax, -0x2058(%rbp)
jmp 0x18e42
movq -0x2058(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x18e78
leaq -0x2040(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %r8
movl $0x2000, %esi           # imm = 0x2000
leaq 0x2ae94(%rip), %rdx     # 0x43d03
movb $0x0, %al
callq 0xd250
jmp 0x18e8d
leaq -0x2040(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0xd0b0
movl $0x18, %edi
callq 0xd4a0
movq %rax, -0x2048(%rbp)
movq -0x10(%rbp), %rax
movq 0x2880(%rax), %rcx
movq -0x2048(%rbp), %rax
movq %rcx, (%rax)
leaq -0x2040(%rbp), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x10cc0
movq %rax, %rcx
movq -0x2048(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rcx
addq $0x2cc0, %rcx           # imm = 0x2CC0
movq -0x2048(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0x2ca8, %rdi           # imm = 0x2CA8
movq -0x2048(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0x6b(%rip), %rdx        # 0x18f70
callq 0xd550
movl %eax, -0x204c(%rbp)
cmpl $0x0, -0x204c(%rbp)
je 0x18f3c
callq 0xd0a0
movl (%rax), %edi
callq 0xd630
movq %rax, %rsi
leaq 0x2ade0(%rip), %rdi     # 0x43d0f
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0x18f54
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x2880(%rax), %rsi
callq 0x17c50
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopw %cs:(%rax,%rax)