// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/dinitctl.cc
// Function: start_stop_service(int, cpbuffer<1024u>&, char const*, ctl_cmd, bool, bool, bool, bool, bool)
static int start_stop_service(int socknum, cpbuffer_t &rbuffer, const char *service_name,
        ctl_cmd command, bool do_pin, bool do_force, bool wait_for_service, bool ignore_unstarted,
        bool verbose)
{
    using std::cout;
    using std::cerr;

    bool do_stop = (command == ctl_cmd::STOP_SERVICE || command == ctl_cmd::RELEASE_SERVICE);

    service_state_t state;
    handle_t handle;
    
    if (command != ctl_cmd::RESTART_SERVICE && command != ctl_cmd::STOP_SERVICE
            && command != ctl_cmd::RELEASE_SERVICE) {
        ignore_unstarted = false;
    }

    if (!load_service(socknum, rbuffer, service_name, &handle, &state, !ignore_unstarted)) {
        return ignore_unstarted ? 0 : 1;
    }

    service_state_t wanted_state = do_stop ? service_state_t::STOPPED : service_state_t::STARTED;
    cp_cmd pcommand;
    switch (command) {
        case ctl_cmd::STOP_SERVICE:
        case ctl_cmd::RESTART_SERVICE:  // stop, and then start
            pcommand = cp_cmd::STOPSERVICE;
            break;
        case ctl_cmd::RELEASE_SERVICE:
            pcommand = cp_cmd::RELEASESERVICE;
            break;
        case ctl_cmd::START_SERVICE:
            pcommand = cp_cmd::STARTSERVICE;
            break;
        case ctl_cmd::WAKE_SERVICE:
            pcommand = cp_cmd::WAKESERVICE;
            break;
        default:
            // can't get here (hopefully)
            pcommand = cp_cmd::STOPSERVICE;
    }

    observed_states_t seen_states;

    // Need to issue command (eg STOPSERVICE/STARTSERVICE)
    // We'll do this regardless of the current service state / target state, since issuing
    // start/stop also sets or clears the "explicitly started" flag on the service.
    // (For other commands we could potentially avoid sending the command if we had more
    // information about the service state, but it doesn't seem worth the effort to implement
    // that optimisation).
    {
        char flags = (do_pin ? 1 : 0) | ((pcommand == cp_cmd::STOPSERVICE && !do_force) ? 2 : 0);
        if (command == ctl_cmd::RESTART_SERVICE) {
            flags |= (4 | 128); // restart, pre-ack
        }

        auto m = membuf()
                .append((char) pcommand)
                .append(flags)
                .append(handle);
        write_all_x(socknum, m);

        wait_for_reply(rbuffer, socknum, handle, &seen_states);
        cp_rply reply_pkt_h = (cp_rply)rbuffer[0];
        rbuffer.consume(1); // consume header

        if (reply_pkt_h == cp_rply::PREACK) {
            // We should consider state changes seen only after the PREACK (i.e. between the
            // PREACK and the main reply):
            seen_states.started = false;
            seen_states.stopped = false;
            seen_states.failed_start = false;

            // PREACK will be followed by a 2nd reply, get that now:
            wait_for_reply(rbuffer, socknum, handle, &seen_states);
            reply_pkt_h = (cp_rply)rbuffer[0];
            rbuffer.consume(1);
        }

        if (reply_pkt_h == cp_rply::ALREADYSS) {
            bool already = (state == wanted_state);
            if (verbose) {
                if (command == ctl_cmd::RESTART_SERVICE) {
                    cout << "Service restarted.\n";
                }
                else {
                    cout << "Service " << (already ? "(already) " : "")
                            << describe_state(do_stop) << ".\n";
                }
            }
            return 0; // success!
        }
        if (reply_pkt_h == cp_rply::PINNEDSTARTED) {
            cerr << "dinitctl: cannot stop service '" << service_name << "' as it is pinned started\n";
            return 1;
        }
        if (reply_pkt_h == cp_rply::PINNEDSTOPPED) {
            cerr << "dinitctl: cannot start service '" << service_name << "' as it is pinned stopped\n";
            return 1;
        }
        if (reply_pkt_h == cp_rply::DEPENDENTS && pcommand == cp_cmd::STOPSERVICE) {
            cerr << "dinitctl: cannot stop service '" << service_name << "' due to the following dependents:\n";
            if (command != ctl_cmd::RESTART_SERVICE) {
                cerr << "(only direct dependents are listed. Exercise caution before using '--force' !!)\n";
            }
            // size_t number, N * handle_t handles
            size_t number;
            rbuffer.fill_to(socknum, sizeof(number));
            rbuffer.extract(&number, 0, sizeof(number));
            rbuffer.consume(sizeof(number));
            std::vector<handle_t> handles;
            handles.reserve(number);
            for (size_t i = 0; i < number; i++) {
                handle_t handle;
                rbuffer.fill_to(socknum, sizeof(handle_t));
                rbuffer.extract(&handle, 0, sizeof(handle));
                handles.push_back(handle);
                rbuffer.consume(sizeof(handle));
            }
            // Print the directly affected dependents:
            cerr << " ";
            for (handle_t handle : handles) {
                cerr << " " << get_service_name(socknum, rbuffer, handle);
            }
            cerr << "\n";
            return 1;
        }
        if (reply_pkt_h == cp_rply::NAK && command == ctl_cmd::RESTART_SERVICE) {
            if (ignore_unstarted) {
                if (verbose) {
                    cout << "Service '" << service_name << "' is not currently started.\n";
                }
                return 0;
            }
            cerr << "dinitctl: cannot restart service; service not started.\n";
            return 1;
        }
        if (reply_pkt_h == cp_rply::NAK && command == ctl_cmd::WAKE_SERVICE) {
            cerr << "dinitctl: service has no active dependents, cannot wake.\n";
            return 1;
        }
        if (reply_pkt_h == cp_rply::SHUTTINGDOWN) {
            cerr << "dinitctl: cannot start/restart/wake service, shutdown is in progress.\n";
            return 1;
        }
        if (reply_pkt_h != cp_rply::ACK) {
            cerr << "dinitctl: protocol error.\n";
            return 1;
        }
    }

    if (!wait_for_service) {
        if (verbose) {
            cout << "Issued " << describe_verb(do_stop) << " command successfully for service '"
                    <<  service_name <<  "'.\n";
        }
        return 0;
    }

    if (command == ctl_cmd::RESTART_SERVICE) {
        // for restart we want to display both "stopped" and "started" statuses
        if (seen_states.stopped) {
            if (verbose) {
                cout << "Service '" << service_name << "' stopped.\n";
            }
        }
        else if (wait_service_state(socknum, rbuffer, handle, service_name, true, verbose) != 0) {
            return EXIT_FAILURE;
        }
    }

    if (seen_states.started) {
        if (verbose) {
            cout << "Service '" << service_name << "' started.\n";
        }
    }
    else if (seen_states.failed_start) {
        if (verbose) {
            cout << "Service '" << service_name << "' failed to start.\n";
            print_failure_details(seen_states.stop_reason, 0 /* not applicable */,
                    seen_states.exit_status, seen_states.exit_si_code, seen_states.exit_si_status);
        }
    }
    return wait_service_state(socknum, rbuffer, handle, service_name, do_stop, verbose);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, %ebx
movl %r8d, 0x90(%rsp)
movl %ecx, %r13d
movq %rdx, %r12
movq %rsi, %r14
leal -0x3(%r13), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
sete 0xf(%rsp)
cmpl $0x3, %eax
setb %al
andb 0xe8(%rsp), %al
movl %edi, %r15d
movb %al, 0x38(%rsp)
xorb $0x1, %al
movzbl %al, %r9d
leaq 0x14(%rsp), %rcx
leaq 0x13(%rsp), %r8
movl %r9d, %ebp
callq 0xd198
testb %al, %al
je 0xc272
movb 0xf(%rsp), %cl
xorb $0x1, %cl
cmpl $0x1, %r13d
movq %r12, 0x88(%rsp)
je 0xc280
cmpl $0x2, %r13d
je 0xc27a
cmpl $0x5, %r13d
jne 0xc288
movw $0x6, %ax
jmp 0xc284
movl %ebp, %r13d
jmp 0xcff0
movw $0x5, %ax
jmp 0xc284
movw $0x3, %ax
xorl %edx, %edx
jmp 0xc28e
movw $0x4, %ax
movb $0x1, %dl
addb %cl, %cl
movb %cl, 0x12(%rsp)
xorb $0x1, %bl
movl %edx, 0x80(%rsp)
andb %dl, %bl
addb %bl, %bl
addb 0x90(%rsp), %bl
leal -0x7c(%rbx), %ecx
movq %r13, 0x78(%rsp)
cmpl $0x4, %r13d
movw $0x0, 0x4c(%rsp)
movb $0x0, 0x4e(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rsp)
movzbl %bl, %edx
movzbl %cl, %ecx
cmovnel %edx, %ecx
shll $0x8, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movl 0x14(%rsp), %ecx
movq %rcx, %rdx
shlq $0x10, %rdx
movzwl %ax, %eax
orq %rdx, %rax
shrl $0x10, %ecx
leaq 0xa0(%rsp), %rbx
movw %cx, 0x4(%rbx)
movl %eax, (%rbx)
movl $0x6, %r13d
xorl %ebp, %ebp
movl %r13d, %edx
movl %r15d, %edi
movq %rbx, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0xc326
addl %eax, %ebp
movslq %eax, %rcx
addq %rcx, %rbx
subl %eax, %r13d
xorl %ecx, %ecx
jmp 0xc346
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0xc346
testl %ebp, %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmovgl %ebp, %r12d
movl $0x1, %ecx
testb $0x1, %cl
jne 0xc352
testl %r13d, %r13d
jg 0xc304
jmp 0xc355
movl %r12d, %ebp
cmpl $-0x1, %ebp
movq 0x88(%rsp), %r12
je 0xd0a8
movl 0x14(%rsp), %edx
leaq 0x4c(%rsp), %rcx
movq %r14, %rdi
movl %r15d, %esi
callq 0xf09d
movl 0x400(%r14), %ecx
leal -0x400(%rcx), %eax
movl $0x400, %ebx            # imm = 0x400
cmpl %ebx, %ecx
cmovbl %ecx, %eax
movb (%r14,%rax), %al
leal 0x1(%rcx), %edx
addl $0xfffffc01, %ecx       # imm = 0xFFFFFC01
cmpl %ebx, %edx
cmovbl %edx, %ecx
movl %ecx, 0x400(%r14)
decl 0x404(%r14)
cmpb $0x4f, %al
jne 0xc404
leaq 0x4c(%rsp), %rcx
movw $0x0, (%rcx)
movb $0x0, 0x2(%rcx)
movl 0x14(%rsp), %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0xf09d
movl 0x400(%r14), %ecx
leal -0x400(%rcx), %eax
cmpl %ebx, %ecx
cmovbl %ecx, %eax
movb (%r14,%rax), %al
leal 0x1(%rcx), %edx
addl $0xfffffc01, %ecx       # imm = 0xFFFFFC01
cmpl %ebx, %edx
cmovbl %edx, %ecx
movl %ecx, 0x400(%r14)
decl 0x404(%r14)
cmpb $0x44, %al
je 0xc4a2
movzbl %al, %ecx
cmpl $0x43, %ecx
je 0xc45f
cmpl $0x3d, %ecx
jne 0xc4e5
xorl %r12d, %r12d
movl $0x0, %r13d
cmpb $0x0, 0xf0(%rsp)
je 0xc614
cmpl $0x4, 0x78(%rsp)
jne 0xc753
movq 0x10b62(%rip), %rdi     # 0x1cfa8
leaq 0x9b31(%rip), %rsi      # 0x15f7e
movl $0x13, %edx
callq 0x4330
xorl %r12d, %r12d
jmp 0xc7d6
movq 0x10b82(%rip), %rbx     # 0x1cfe8
leaq 0x9b74(%rip), %rsi      # 0x15fe1
movl $0x20, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xc5b5
movq %r12, %rdi
callq 0x4150
movq 0x10b56(%rip), %rdi     # 0x1cfe8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xc5cc
movq 0x10b3f(%rip), %rbx     # 0x1cfe8
leaq 0x9af6(%rip), %rsi      # 0x15fa6
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xc5dc
movq %r12, %rdi
callq 0x4150
movq 0x10b13(%rip), %rdi     # 0x1cfe8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xc5f3
cmpb $0x41, %al
setne %dl
movl 0x80(%rsp), %esi
xorb $0x1, %sil
orb %dl, %sil
movq 0x78(%rsp), %r13
jne 0xc542
movq 0x10ae2(%rip), %rbx     # 0x1cfe8
leaq 0x9a99(%rip), %rsi      # 0x15fa6
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xc8e8
movq %r12, %rdi
callq 0x4150
movq 0x10ab6(%rip), %rdi     # 0x1cfe8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xc8ff
cmpl $0x4, %r13d
jne 0xc729
cmpb $0x33, %al
jne 0xc729
cmpb $0x0, 0x38(%rsp)
je 0xcf0d
xorl %r12d, %r12d
movl $0x0, %r13d
cmpb $0x0, 0xf0(%rsp)
je 0xc614
movq 0x10a2b(%rip), %rbx     # 0x1cfa8
leaq 0x9b0e(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
movq %rbx, %rdi
movq 0x88(%rsp), %rsi
callq 0x42d0
leaq 0x9af4(%rip), %rsi      # 0x1609c
movl $0x1c, %edx
movq %rax, %rdi
jmp 0xc452
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x10a15(%rip), %rdi     # 0x1cfe8
leaq 0x9a28(%rip), %rsi      # 0x16002
jmp 0xc601
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x109ee(%rip), %rdi     # 0x1cfe8
leaq 0x99c5(%rip), %rsi      # 0x15fc6
movl $0x1a, %edx
callq 0x4330
movl $0x1, %r13d
xorl %r12d, %r12d
testb %r12b, %r12b
movq 0x88(%rsp), %r12
je 0xcff0
cmpb $0x0, 0xe0(%rsp)
je 0xc69a
movzbl 0xf0(%rsp), %ebp
cmpl $0x4, 0x78(%rsp)
jne 0xc83a
cmpb $0x1, 0x4d(%rsp)
jne 0xc7de
cmpb $0x0, 0xf0(%rsp)
je 0xc83a
movq 0x10946(%rip), %rbx     # 0x1cfa8
leaq 0x9a29(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
movq %rbx, %rdi
movq %r12, %rsi
callq 0x42d0
leaq 0x9b35(%rip), %rsi      # 0x161bd
movl $0xb, %edx
movq %rax, %rdi
callq 0x4330
jmp 0xc83a
xorl %r13d, %r13d
cmpb $0x0, 0xf0(%rsp)
je 0xcff0
movq 0x108f6(%rip), %rbx     # 0x1cfa8
leaq 0x9ad4(%rip), %rsi      # 0x1618d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x4330
leaq 0x8ba9(%rip), %rax      # 0x15276
leaq 0xa11c(%rip), %rsi      # 0x167f0
movb 0xf(%rsp), %cl
testb %cl, %cl
cmovneq %rax, %rsi
movzbl %cl, %edx
xorq $0x5, %rdx
movq %rbx, %rdi
callq 0x4330
leaq 0x9aa1(%rip), %rsi      # 0x16195
movl $0x23, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xceb0
movq %r12, %rdi
callq 0x4150
movq 0x1088f(%rip), %rdi     # 0x1cfa8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xcec7
cmpl $0x2, %r13d
jne 0xcee4
cmpb $0x33, %al
jne 0xcee4
movq 0x108a6(%rip), %rdi     # 0x1cfe8
leaq 0x99a8(%rip), %rsi      # 0x160f1
movl $0x39, %edx
jmp 0xc606
movb 0x13(%rsp), %bpl
movq 0x10849(%rip), %rbx     # 0x1cfa8
leaq 0x982c(%rip), %rsi      # 0x15f92
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
xorl %r12d, %r12d
cmpb 0x12(%rsp), %bpl
leaq 0x9819(%rip), %rax      # 0x15f9b
leaq 0xa38d(%rip), %rsi      # 0x16b16
cmoveq %rax, %rsi
movl $0xa, %edx
cmovneq %r12, %rdx
movq %rbx, %rdi
callq 0x4330
leaq 0x9b71(%rip), %rax      # 0x16316
leaq 0x8afd(%rip), %rsi      # 0x152a9
cmpb $0x0, 0xf(%rsp)
cmovneq %rax, %rsi
movl $0x7, %edx
movq %rbx, %rdi
callq 0x4330
leaq 0x99f1(%rip), %rsi      # 0x161ba
movl $0x2, %edx
movq %rbx, %rdi
callq 0x4330
xorl %r13d, %r13d
jmp 0xc614
movl 0x14(%rsp), %ebx
leaq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r12, %rsi
callq 0xeba8
leaq 0x18(%rsp), %rcx
movl %r15d, %edi
movq %r14, %rsi
movl %ebx, %edx
movl $0x1, %r8d
movl %ebp, %r9d
callq 0xd1e3
movl %eax, %ebx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xc82c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42f0
movl $0x1, %r13d
testl %ebx, %ebx
jne 0xcff0
cmpb $0x1, 0x4c(%rsp)
jne 0xc892
cmpb $0x0, 0xf0(%rsp)
je 0xcf9d
movq 0x10752(%rip), %rbx     # 0x1cfa8
leaq 0x9835(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xcf25
movq %r12, %rdi
callq 0x4150
movq 0x10726(%rip), %rdi     # 0x1cfa8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xcf3c
movb 0xf0(%rsp), %al
andb 0x4e(%rsp), %al
cmpb $0x1, %al
jne 0xcf9d
movq 0x106fc(%rip), %rbx     # 0x1cfa8
leaq 0x97df(%rip), %rsi      # 0x16092
movl $0x9, %edx
movq %rbx, %rdi
callq 0x4330
testq %r12, %r12
je 0xcf56
movq %r12, %rdi
callq 0x4150
movq 0x106d0(%rip), %rdi     # 0x1cfa8
movq %r12, %rsi
movq %rax, %rdx
callq 0x4330
jmp 0xcf6d
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x106e2(%rip), %rdi     # 0x1cfe8
leaq 0x9710(%rip), %rsi      # 0x1601d
movl $0x23, %edx
callq 0x4330
cmpl $0x4, %r13d
je 0xc935
movq 0x106c4(%rip), %rdi     # 0x1cfe8
leaq 0x9716(%rip), %rsi      # 0x16041
movl $0x50, %edx
callq 0x4330
leaq 0x400(%r14), %rbp
cmpl $0x7, 0x404(%r14)
ja 0xc95f
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
jle 0xc95f
cmpl $0x8, 0x404(%r14)
jb 0xc946
movl (%rbp), %eax
leal -0x400(%rax), %ebx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ebx
leal -0x3f9(%rbx), %eax
movl %ebx, %esi
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xc9b4
movl $0x400, %r12d           # imm = 0x400
subl %ebx, %r12d
addq %r14, %rsi
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x4270
addq %r13, %r12
addl $0xfffffc08, %ebx       # imm = 0xFFFFFC08
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4270
jmp 0xc9bd
movq (%r14,%rsi), %rax
movq %rax, 0x40(%rsp)
movl 0x400(%r14), %eax
leal 0x8(%rax), %ecx
addl $0xfffffc08, %eax       # imm = 0xFFFFFC08
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
addl $-0x8, 0x404(%r14)
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x40(%rsp), %rsi
callq 0xf49a
cmpq $0x0, 0x40(%rsp)
movq %rbp, 0x38(%rsp)
je 0xcb01
xorl %r13d, %r13d
leaq 0x18(%rsp), %rbx
cmpl $0x3, 0x404(%r14)
ja 0xca3d
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
jle 0xca3d
cmpl $0x4, 0x404(%r14)
jb 0xca24
movl (%rbp), %eax
leal -0x400(%rax), %r12d
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %r12d
leal -0x3fd(%r12), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xca97
movl $0x400, %ebp            # imm = 0x400
subl %r12d, %ebp
movl %r12d, %esi
addq %r14, %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x4270
addq %rbx, %rbp
addl $0xfffffc04, %r12d      # imm = 0xFFFFFC04
movq %rbp, %rdi
movq 0x38(%rsp), %rbp
movq %r14, %rsi
movq %r12, %rdx
callq 0x4270
jmp 0xcaa2
movl %r12d, %eax
movl (%r14,%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0xcabf
movl 0x18(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x68(%rsp)
jmp 0xcacc
leaq 0x60(%rsp), %rdi
movq %rbx, %rdx
callq 0xf54c
movl 0x400(%r14), %eax
leal 0x4(%rax), %ecx
addl $0xfffffc04, %eax       # imm = 0xFFFFFC04
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
addl $-0x4, 0x404(%r14)
incq %r13
cmpq 0x40(%rsp), %r13
jb 0xca1a
movq 0x104e0(%rip), %rdi     # 0x1cfe8
leaq 0x9be1(%rip), %rsi      # 0x166f0
movl $0x1, %edx
callq 0x4330
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rcx, 0x80(%rsp)
cmpq %rcx, %rax
je 0xce78
movq 0x104ad(%rip), %r12     # 0x1cfe8
movq %rax, 0x90(%rsp)
movl (%rax), %ebx
movl $0x1, %edx
movq %r12, %rdi
leaq 0x9b9c(%rip), %rsi      # 0x166f0
callq 0x4330
movl %ebx, %eax
shrl $0x10, %eax
shlq $0x10, %rbx
orq $0xf, %rbx
movw %ax, 0x9c(%rsp)
movl %ebx, 0x98(%rsp)
movl $0x6, %r13d
xorl %r12d, %r12d
leaq 0x98(%rsp), %rbx
movl %r13d, %edx
movl %r15d, %edi
movq %rbx, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0xcba9
addl %eax, %r12d
movslq %eax, %rcx
addq %rcx, %rbx
subl %eax, %r13d
xorl %ecx, %ecx
jmp 0xcbc9
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0xcbc9
testl %r12d, %r12d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmovgl %r12d, %ebp
movl $0x1, %ecx
testb $0x1, %cl
jne 0xcbd5
testl %r13d, %r13d
jg 0xcb86
jmp 0xcbd8
movl %ebp, %r12d
cmpl $-0x1, %r12d
je 0xd089
movq %r14, %rdi
movl %r15d, %esi
callq 0xedbd
movl 0x400(%r14), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
cmpb $0x42, (%r14,%rcx)
jne 0xd04d
movl $0x1, %ebx
cmpl $0x3, 0x404(%r14)
ja 0xcc30
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
cmovlel %eax, %ebp
movl %ebp, %ebx
jg 0xcc0d
cmpl $-0x1, %ebx
je 0xcc3e
testl %ebx, %ebx
jne 0xcc4c
jmp 0xd04d
callq 0x4040
cmpl $0x4, (%rax)
jne 0xd062
cmpl $-0x1, %ebx
je 0xcc0d
movq 0x38(%rsp), %rbp
movl (%rbp), %ebx
leal 0x2(%rbx), %eax
addl $0xfffffc02, %ebx       # imm = 0xFFFFFC02
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ebx
leal -0x3ff(%rbx), %eax
cmpl $0xfffffbfe, %eax       # imm = 0xFFFFFBFE
ja 0xccae
movl $0x400, %r12d           # imm = 0x400
subl %ebx, %r12d
movl %ebx, %esi
addq %r14, %rsi
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x4270
addq %r13, %r12
addl $0xfffffc02, %ebx       # imm = 0xFFFFFC02
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4270
jmp 0xccba
movl %ebx, %eax
movzwl (%r14,%rax), %eax
movw %ax, 0x10(%rsp)
movl 0x400(%r14), %eax
leal 0x4(%rax), %ecx
addl $0xfffffc04, %eax       # imm = 0xFFFFFC04
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%r14)
addl $-0x4, 0x404(%r14)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
cmpl $0x0, 0x404(%r14)
jne 0xcd28
jmp 0xcd13
callq 0x4040
cmpl $0x4, (%rax)
jne 0xd02b
movq %r14, %rdi
movl %r15d, %esi
callq 0xeffc
testl %eax, %eax
je 0xd019
jle 0xcd05
movl 0x400(%r14), %eax
movl 0x404(%r14), %ecx
movzwl 0x10(%rsp), %r12d
subq 0x20(%rsp), %r12
cmpq %rcx, %r12
cmovaeq %rcx, %r12
leal -0x400(%rax), %edx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %edx
leaq (%rdx,%r14), %rsi
testq %rcx, %rcx
je 0xcd7f
leal (%rax,%rcx), %edi
cmpl $0x400, %edi            # imm = 0x400
leal -0x400(%rax,%rcx), %ecx
cmovbl %edi, %ecx
leal (%r14,%rcx), %eax
cmpl %edx, %ecx
cmovbel %ebp, %eax
subl %esi, %eax
jmp 0xcd81
xorl %eax, %eax
movl %eax, %r13d
movq %r12, %rbx
subq %r13, %rbx
jae 0xcd9e
leaq 0x18(%rsp), %rdi
movq %r12, %rdx
callq 0x4070
movq %r12, %rbx
jmp 0xcdec
leaq 0x18(%rsp), %rdi
movq %r13, %rdx
callq 0x4070
movl 0x400(%r14), %eax
addl %r13d, %eax
movl $0xfffffc00, %esi       # imm = 0xFFFFFC00
leal (%rax,%rsi), %ecx
movl $0x400, %edx            # imm = 0x400
cmpl %edx, %eax
cmovbl %eax, %ecx
movl %ecx, 0x400(%r14)
subl %r13d, 0x404(%r14)
addl %ecx, %esi
cmpl %edx, %ecx
cmovbl %ecx, %esi
addq %r14, %rsi
leaq 0x18(%rsp), %rdi
movq %rbx, %rdx
callq 0x4070
movl 0x400(%r14), %eax
leal (%rax,%rbx), %ecx
cmpl $0x400, %ecx            # imm = 0x400
leal -0x400(%rax,%rbx), %eax
cmovbl %ecx, %eax
subl %ebx, 0x404(%r14)
movl %eax, 0x400(%r14)
cmpq %r13, %r12
jb 0xce29
movzwl 0x10(%rsp), %eax
cmpq %rax, 0x20(%rsp)
jb 0xccf9
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x101ae(%rip), %r12     # 0x1cfe8
movq %r12, %rdi
callq 0x4330
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xce5e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42f0
movq 0x90(%rsp), %rax
addq $0x4, %rax
cmpq 0x80(%rsp), %rax
jne 0xcb3b
movq 0x10169(%rip), %rdi     # 0x1cfe8
leaq 0x9c8f(%rip), %rsi      # 0x16b15
movl $0x1, %edx
callq 0x4330
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xc60b
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
jmp 0xc60b
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x100da(%rip), %rdi     # 0x1cfa8
leaq 0x92e4(%rip), %rsi      # 0x161b9
movl $0x3, %edx
callq 0x4330
jmp 0xcff0
cmpb $0x32, %al
je 0xd005
movq 0x100f5(%rip), %rdi     # 0x1cfe8
cmpl $0x45, %ecx
jne 0xd00d
leaq 0x9228(%rip), %rsi      # 0x1612b
movl $0x46, %edx
jmp 0xc606
movq 0x100d4(%rip), %rdi     # 0x1cfe8
leaq 0x919e(%rip), %rsi      # 0x160b9
movl $0x37, %edx
jmp 0xc606
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x10065(%rip), %rdi     # 0x1cfa8
leaq 0x927f(%rip), %rsi      # 0x161c9
movl $0xb, %edx
callq 0x4330
jmp 0xcf9d
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x44c0
movq 0x10034(%rip), %rdi     # 0x1cfa8
leaq 0x925a(%rip), %rsi      # 0x161d5
movl $0x13, %edx
callq 0x4330
movl 0x50(%rsp), %edi
movl 0x54(%rsp), %edx
movl 0x58(%rsp), %ecx
movl 0x5c(%rsp), %r8d
xorl %esi, %esi
callq 0xd3d4
movl 0x14(%rsp), %ebx
leaq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r12, %rsi
callq 0xeba8
movb 0xf(%rsp), %al
xorl %r8d, %r8d
movb %al, %r8b
leaq 0x18(%rsp), %rcx
movl %r15d, %edi
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %r9d
callq 0xd1e3
movl %eax, %r13d
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xcff0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42f0
movl %r13d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r12b
jmp 0xc614
leaq 0x915e(%rip), %rsi      # 0x16172
jmp 0xc601
movl $0x4, %edi
callq 0x4190
movl $0x0, (%rax)
jmp 0xd03c
movq %rax, %rbx
movl $0x4, %edi
callq 0x4190
movl (%rbx), %ecx
movl %ecx, (%rax)
leaq 0xfafd(%rip), %rsi      # 0x1cb40
movq %rax, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
movl $0x0, (%rax)
jmp 0xd078
movq %rax, %r12
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
movl (%r12), %eax
movl %eax, (%rbx)
leaq 0xfac1(%rip), %rsi      # 0x1cb40
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0xfaaa(%rip), %rsi      # 0x1cb50
jmp 0xd07f
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0xfa8b(%rip), %rsi      # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0
jmp 0xd0d3
jmp 0xd0ee
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xd13c
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0xd137
movq %rax, %rbx
jmp 0xd13c
jmp 0xd0ff
jmp 0xd0ff
jmp 0xd106
jmp 0xd0ff
jmp 0xd0ff
jmp 0xd0ff
movq %rax, %rbx
jmp 0xd125
jmp 0xd106
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xd125
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42f0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xd13c
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
movq %rbx, %rdi
callq 0x44f0