// File: davmac314[P]dinit/src/dinit.cc
// Function: confirm_restart_boot()
static void confirm_restart_boot() noexcept
{
    // Bypass log; we want to make certain the message is seen:
    std::cout << "All services have stopped with no shutdown issued; boot failure?\n";

    // Drain input, set non-canonical input mode (receive characters as they are typed)
    struct termios term_attr;
    if (tcgetattr(STDIN_FILENO, &term_attr) != 0) {
        // Not a terminal?
        std::cout << "Halting." << std::endl;
        services->stop_all_services(shutdown_type_t::HALT);
        return;
    }
    term_attr.c_lflag &= ~ICANON;
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &term_attr);

    // Set non-blocking mode
    int origFlags = fcntl(STDIN_FILENO, F_GETFL);
    fcntl(STDIN_FILENO, F_SETFL, origFlags | O_NONBLOCK);

    do_prompt:
    std::cout << "Choose: (r)eboot, r(e)covery, re(s)tart boot sequence, (p)ower off? " << std::flush;

    console_input_io.set_enabled(event_loop, true);
    do {
        event_loop.run();
    } while (! console_input_ready && services->get_shutdown_type() == shutdown_type_t::NONE);
    console_input_io.set_enabled(event_loop, false);

    // We either have input, or shutdown type has been set, or both.
    if (console_input_ready) {
        console_input_ready = false;
        char buf[1];
        int r = read(STDIN_FILENO, buf, 1);  // read a single character, to make sure we wait for input
        if (r == 1) {
            std::cout << "\n"; // force new line after input
            if (buf[0] == 'r' || buf[0] == 'R') {
                services->stop_all_services(shutdown_type_t::REBOOT);
            }
            else if (buf[0] == 'e' || buf[0] == 'E') {
                try {
                    services->start_service("recovery");
                }
                catch (...) {
                    std::cout << "Unable to start recovery service.\n";
                    goto do_prompt;
                }
            }
            else if (buf[0] == 's' || buf[0] == 'S') {
                // nothing - leave no shutdown type
            }
            else if (buf[0] == 'p' || buf[0] == 'P') {
                services->stop_all_services(shutdown_type_t::POWEROFF);
            }
            else {
                goto do_prompt;
            }
        }
        tcflush(STDIN_FILENO, TCIFLUSH); // discard the rest of input
    }

    term_attr.c_lflag |= ICANON;
    tcsetattr(STDIN_FILENO, TCSANOW, &term_attr);
    fcntl(STDIN_FILENO, F_SETFL, origFlags);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x9a376(%rip), %rdi     # 0xa7f68
leaq 0x69010(%rip), %rsi     # 0x76c09
callq 0xa6e0
jmp 0xdc00
xorl %edi, %edi
leaq -0x3c(%rbp), %rsi
callq 0xa7f0
cmpl $0x0, %eax
je 0xdc51
movq 0x9a351(%rip), %rdi     # 0xa7f68
leaq 0x6902d(%rip), %rsi     # 0x76c4b
callq 0xa6e0
movq %rax, -0x60(%rbp)
jmp 0xdc29
movq -0x60(%rbp), %rdi
movq 0x9a2ec(%rip), %rsi     # 0xa7f20
callq 0xa750
jmp 0xdc3b
movq 0x9b206(%rip), %rdi     # 0xa8e48
movl $0x2, %esi
callq 0x17b60
jmp 0xde90
movb -0x30(%rbp), %al
andb $-0x3, %al
movb %al, -0x30(%rbp)
xorl %edi, %edi
movl %edi, -0x68(%rbp)
movl $0x2, %esi
leaq -0x3c(%rbp), %rdx
callq 0xa940
movl -0x68(%rbp), %edi
movb %dil, %al
movl $0x3, %esi
callq 0xa3f0
movl %eax, -0x64(%rbp)
jmp 0xdc81
movl -0x64(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
orl $0x800, %edx            # imm = 0x800
xorl %edi, %edi
movb %dil, %al
movl $0x4, %esi
callq 0xa3f0
jmp 0xdca1
jmp 0xdca3
movq 0x9a2be(%rip), %rdi     # 0xa7f68
leaq 0x68fa3(%rip), %rsi     # 0x76c54
callq 0xa6e0
movq %rax, -0x70(%rbp)
jmp 0xdcbc
movq -0x70(%rbp), %rdi
movq 0x9a2b1(%rip), %rsi     # 0xa7f78
callq 0xa750
jmp 0xdcce
leaq 0x9b0eb(%rip), %rdi     # 0xa8dc0
leaq 0x9ae84(%rip), %rsi     # 0xa8b60
movl $0x1, %edx
callq 0x17c00
leaq 0x9ae73(%rip), %rdi     # 0xa8b60
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xfa80
xorl %eax, %eax
testb $0x1, 0x9b152(%rip)     # 0xa8e52
movb %al, -0x71(%rbp)
jne 0xdd19
movq 0x9b13c(%rip), %rdi     # 0xa8e48
callq 0xfb10
cmpb $0x0, %al
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0xdce6
leaq 0x9b099(%rip), %rdi     # 0xa8dc0
leaq 0x9ae32(%rip), %rsi     # 0xa8b60
xorl %edx, %edx
callq 0x17c00
testb $0x1, 0x9b116(%rip)     # 0xa8e52
je 0xde5d
movb $0x0, 0x9b109(%rip)     # 0xa8e52
xorl %edi, %edi
leaq -0x41(%rbp), %rsi
movl $0x1, %edx
callq 0xaac0
movq %rax, -0x80(%rbp)
jmp 0xdd5f
movq -0x80(%rbp), %rax
movl %eax, -0x48(%rbp)
cmpl $0x1, -0x48(%rbp)
jne 0xde54
movq 0x9a1f1(%rip), %rdi     # 0xa7f68
leaq 0x68d6a(%rip), %rsi     # 0x76ae8
callq 0xa6e0
jmp 0xdd85
movsbl -0x41(%rbp), %eax
cmpl $0x72, %eax
je 0xdd97
movsbl -0x41(%rbp), %eax
cmpl $0x52, %eax
jne 0xddad
movq 0x9b0aa(%rip), %rdi     # 0xa8e48
movl $0x4, %esi
callq 0x17b60
jmp 0xde52
movsbl -0x41(%rbp), %eax
cmpl $0x65, %eax
je 0xddbf
movsbl -0x41(%rbp), %eax
cmpl $0x45, %eax
jne 0xde0e
movq 0x9b082(%rip), %rdi     # 0xa8e48
leaq 0x6a202(%rip), %rsi     # 0x77fcf
callq 0xf870
jmp 0xddd4
jmp 0xde0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rdi
callq 0xa240
movq 0x9a176(%rip), %rdi     # 0xa7f68
leaq 0x68ea0(%rip), %rsi     # 0x76c99
callq 0xa6e0
jmp 0xde00
callq 0xac30
jmp 0xde07
jmp 0xdca3
jmp 0xde50
movsbl -0x41(%rbp), %eax
cmpl $0x73, %eax
je 0xde20
movsbl -0x41(%rbp), %eax
cmpl $0x53, %eax
jne 0xde22
jmp 0xde4e
movsbl -0x41(%rbp), %eax
cmpl $0x70, %eax
je 0xde34
movsbl -0x41(%rbp), %eax
cmpl $0x50, %eax
jne 0xde47
movq 0x9b00d(%rip), %rdi     # 0xa8e48
movl $0x3, %esi
callq 0x17b60
jmp 0xde4c
jmp 0xdca3
jmp 0xde4e
jmp 0xde50
jmp 0xde52
jmp 0xde54
xorl %esi, %esi
movl %esi, %edi
callq 0xab40
movb -0x30(%rbp), %al
orb $0x2, %al
movb %al, -0x30(%rbp)
xorl %esi, %esi
movl %esi, -0x84(%rbp)
leaq -0x3c(%rbp), %rdx
movl %esi, %edi
callq 0xa940
movl -0x84(%rbp), %edi
movl -0x40(%rbp), %edx
movb %dil, %al
movl $0x4, %esi
callq 0xa3f0
jmp 0xde90
addq $0x90, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopw %cs:(%rax,%rax)