// File: 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 namespace std;

    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." << endl;
            return 1;
        }
    }

    if (!wait_for_service) {
        if (verbose) {
            cout << "Issued " << describe_verb(do_stop) << " command successfully for service '"
                    <<  service_name <<  "'." << endl;
        }
        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
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl %r9d, -0x120(%rbp)
movl %r8d, %eax
movl %ecx, %r8d
movl -0x120(%rbp), %ecx
movq %rdx, %r9
movq %rsi, %r10
movl %edi, %r11d
movb %cl, %sil
movb %al, %dil
movb 0x20(%rbp), %al
movb 0x18(%rbp), %cl
movb 0x10(%rbp), %dl
movl %r11d, -0x8(%rbp)
movq %r10, -0x10(%rbp)
movq %r9, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
andb $0x1, %dil
movb %dil, -0x1d(%rbp)
andb $0x1, %sil
movb %sil, -0x1e(%rbp)
andb $0x1, %dl
movb %dl, -0x1f(%rbp)
andb $0x1, %cl
movb %cl, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movb $0x1, %al
cmpl $0x3, -0x1c(%rbp)
movb %al, -0x11a(%rbp)
je 0xbb52
cmpl $0x5, -0x1c(%rbp)
sete %al
movb %al, -0x11a(%rbp)
movb -0x11a(%rbp), %al
andb $0x1, %al
movb %al, -0x22(%rbp)
cmpl $0x4, -0x1c(%rbp)
je 0xbb73
cmpl $0x3, -0x1c(%rbp)
je 0xbb73
cmpl $0x5, -0x1c(%rbp)
je 0xbb73
movb $0x0, -0x20(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movb -0x20(%rbp), %al
xorb $-0x1, %al
movzbl %al, %r9d
andl $0x1, %r9d
leaq -0x28(%rbp), %rcx
leaq -0x23(%rbp), %r8
callq 0xc5e0
testb $0x1, %al
jne 0xbbb4
movb -0x20(%rbp), %dl
movl $0x1, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0xc50e
movb -0x22(%rbp), %al
notb %al
andb $0x1, %al
addb %al, %al
movb %al, -0x29(%rbp)
movl -0x1c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x128(%rbp)
subl $0x4, %eax
ja 0xbc02
movq -0x128(%rbp), %rax
leaq 0x1745f(%rip), %rcx     # 0x23040
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x4, -0x2a(%rbp)
jmp 0xbc06
movb $0x6, -0x2a(%rbp)
jmp 0xbc06
movb $0x3, -0x2a(%rbp)
jmp 0xbc06
movb $0x5, -0x2a(%rbp)
jmp 0xbc06
movb $0x4, -0x2a(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x11b20
movb -0x1d(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x130(%rbp)
xorl %eax, %eax
cmpb $0x4, -0x2a(%rbp)
movb %al, -0x129(%rbp)
jne 0xbc3e
movb -0x1e(%rbp), %al
xorb $-0x1, %al
movb %al, -0x129(%rbp)
movl -0x130(%rbp), %eax
movb -0x129(%rbp), %sil
xorl %ecx, %ecx
movl $0x2, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
cmpl $0x4, -0x1c(%rbp)
jne 0xbc70
movsbl -0x41(%rbp), %eax
orl $0x84, %eax
movb %al, -0x41(%rbp)
movb -0x2a(%rbp), %al
movb %al, -0x4c(%rbp)
leaq -0x4b(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x11b60
movb %al, -0x4a(%rbp)
leaq -0x4a(%rbp), %rdi
leaq -0x41(%rbp), %rsi
callq 0x11b90
movw %ax, -0x49(%rbp)
leaq -0x49(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x11bc0
movl %eax, %ecx
movl %ecx, -0x47(%rbp)
shrq $0x20, %rax
movw %ax, -0x43(%rbp)
movl -0x8(%rbp), %edi
leaq -0x47(%rbp), %rsi
callq 0x11c10
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
movl -0x28(%rbp), %edx
leaq -0x40(%rbp), %rcx
callq 0x11c50
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movb %al, -0x4d(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
cmpb $0x4f, -0x4d(%rbp)
jne 0xbd2d
movb $0x0, -0x40(%rbp)
movb $0x0, -0x3f(%rbp)
movb $0x0, -0x3e(%rbp)
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
movl -0x28(%rbp), %edx
leaq -0x40(%rbp), %rcx
callq 0x11c50
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x113e0
movb %al, -0x4d(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x115f0
cmpb $0x3d, -0x4d(%rbp)
jne 0xbddd
movb -0x23(%rbp), %al
cmpb -0x29(%rbp), %al
sete %al
andb $0x1, %al
movb %al, -0x4e(%rbp)
testb $0x1, -0x21(%rbp)
je 0xbdd1
cmpl $0x4, -0x1c(%rbp)
jne 0xbd6a
movq 0x2623c(%rip), %rdi     # 0x31f98
leaq 0x181ee(%rip), %rsi     # 0x23f51
callq 0x53d0
jmp 0xbdcf
movq 0x26227(%rip), %rdi     # 0x31f98
leaq 0x181ed(%rip), %rsi     # 0x23f65
callq 0x53d0
movq %rax, %rdi
movb -0x4e(%rbp), %cl
leaq 0x18d2c(%rip), %rsi     # 0x24ab6
leaq 0x181dd(%rip), %rax     # 0x23f6e
testb $0x1, %cl
cmovneq %rax, %rsi
callq 0x53d0
movq %rax, -0x138(%rbp)
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0xc660
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x1851a(%rip), %rsi     # 0x242e4
callq 0x53d0
jmp 0xbdd1
movl $0x0, -0x4(%rbp)
jmp 0xc50e
cmpb $0x44, -0x4d(%rbp)
jne 0xbe1d
movq 0x261fe(%rip), %rdi     # 0x31fe8
leaq 0x18188(%rip), %rsi     # 0x23f79
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x1818d(%rip), %rsi     # 0x23f99
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xc50e
cmpb $0x43, -0x4d(%rbp)
jne 0xbe5d
movq 0x261be(%rip), %rdi     # 0x31fe8
leaq 0x18183(%rip), %rsi     # 0x23fb4
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x18189(%rip), %rsi     # 0x23fd5
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xc50e
cmpb $0x41, -0x4d(%rbp)
jne 0xc0d9
cmpb $0x4, -0x2a(%rbp)
jne 0xc0d9
movq 0x26170(%rip), %rdi     # 0x31fe8
leaq 0x180fa(%rip), %rsi     # 0x23f79
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x18156(%rip), %rsi     # 0x23ff0
callq 0x53d0
cmpl $0x4, -0x1c(%rbp)
je 0xbeb8
movq 0x2613c(%rip), %rdi     # 0x31fe8
leaq 0x18161(%rip), %rsi     # 0x24014
callq 0x53d0
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
movl $0x8, %edx
movl %edx, -0x144(%rbp)
callq 0x11710
movl -0x144(%rbp), %ecx
movq -0x10(%rbp), %rdi
leaq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x11540
movl -0x144(%rbp), %esi
movq -0x10(%rbp), %rdi
callq 0x115f0
leaq -0x70(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x11e70
movq -0x140(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x11e90
jmp 0xbf15
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0xbfa8
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %esi
movl $0x4, %edx
movl %edx, -0x154(%rbp)
callq 0x11710
movl -0x154(%rbp), %ecx
movq -0x10(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
movq %rsi, -0x150(%rbp)
xorl %edx, %edx
callq 0x11540
movq -0x150(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x11f90
jmp 0xbf75
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x115f0
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0xbf20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc0cb
movq 0x26039(%rip), %rdi     # 0x31fe8
leaq 0x18705(%rip), %rsi     # 0x246bb
callq 0x53d0
jmp 0xbfbd
leaq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x12000
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x12030
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x12060
testb $0x1, %al
jne 0xc00a
jmp 0xc0a1
leaq -0xa0(%rbp), %rdi
callq 0x120a0
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movq 0x25fc3(%rip), %rdi     # 0x31fe8
leaq 0x1868f(%rip), %rsi     # 0x246bb
callq 0x53d0
movq %rax, -0x160(%rbp)
jmp 0xc03a
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0xac(%rbp), %ecx
leaq -0xd0(%rbp), %rdi
callq 0xc6a0
jmp 0xc055
movq -0x160(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x53a0
jmp 0xc06a
leaq -0xd0(%rbp), %rdi
callq 0x5280
leaq -0xa0(%rbp), %rdi
callq 0x120c0
jmp 0xbfee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5280
jmp 0xc0cb
movq 0x25f40(%rip), %rdi     # 0x31fe8
leaq 0x18a06(%rip), %rsi     # 0x24ab5
callq 0x53d0
jmp 0xc0b6
movl $0x1, -0x4(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x120e0
jmp 0xc50e
leaq -0x70(%rbp), %rdi
callq 0x120e0
jmp 0xc51a
cmpb $0x33, -0x4d(%rbp)
jne 0xc14a
cmpl $0x4, -0x1c(%rbp)
jne 0xc14a
testb $0x1, -0x20(%rbp)
je 0xc12b
testb $0x1, -0x21(%rbp)
je 0xc11f
movq 0x25ea0(%rip), %rdi     # 0x31f98
leaq 0x17f66(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17f55(%rip), %rsi     # 0x2406f
callq 0x53d0
movl $0x0, -0x4(%rbp)
jmp 0xc50e
movq 0x25eb6(%rip), %rdi     # 0x31fe8
leaq 0x17f53(%rip), %rsi     # 0x2408c
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xc50e
cmpb $0x33, -0x4d(%rbp)
jne 0xc175
cmpl $0x2, -0x1c(%rbp)
jne 0xc175
movq 0x25e8b(%rip), %rdi     # 0x31fe8
leaq 0x17f60(%rip), %rsi     # 0x240c4
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xc50e
cmpb $0x45, -0x4d(%rbp)
jne 0xc19a
movq 0x25e66(%rip), %rdi     # 0x31fe8
leaq 0x17f75(%rip), %rsi     # 0x240fe
callq 0x53d0
movl $0x1, -0x4(%rbp)
jmp 0xc50e
cmpb $0x32, -0x4d(%rbp)
je 0xc1ce
movq 0x25e41(%rip), %rdi     # 0x31fe8
leaq 0x17f97(%rip), %rsi     # 0x24145
callq 0x53d0
movq %rax, %rdi
movq 0x25dab(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x1, -0x4(%rbp)
jmp 0xc50e
testb $0x1, -0x1f(%rbp)
jne 0xc259
testb $0x1, -0x21(%rbp)
je 0xc24d
movq 0x25db3(%rip), %rdi     # 0x31f98
leaq 0x17f73(%rip), %rsi     # 0x2415f
callq 0x53d0
movq %rax, -0x168(%rbp)
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
callq 0xc980
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17f49(%rip), %rsi     # 0x24167
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17f52(%rip), %rsi     # 0x2418b
callq 0x53d0
movq %rax, %rdi
movq 0x25d20(%rip), %rsi     # 0x31f68
callq 0x5410
movl $0x0, -0x4(%rbp)
jmp 0xc50e
cmpl $0x4, -0x1c(%rbp)
jne 0xc399
testb $0x1, -0x3f(%rbp)
je 0xc2a2
testb $0x1, -0x21(%rbp)
je 0xc29d
movq 0x25d22(%rip), %rdi     # 0x31f98
leaq 0x17de8(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17ef6(%rip), %rsi     # 0x2418e
callq 0x53d0
jmp 0xc397
movl -0x8(%rbp), %eax
movl %eax, -0x18c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x17c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x5700
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x10f00
jmp 0xc2f9
movl -0x17c(%rbp), %edx
movq -0x188(%rbp), %rsi
movl -0x18c(%rbp), %edi
movzbl -0x21(%rbp), %r9d
andl $0x1, %r9d
leaq -0xf0(%rbp), %rcx
movl $0x1, %r8d
callq 0xc9b0
movl %eax, -0x190(%rbp)
jmp 0xc32f
leaq -0xf0(%rbp), %rdi
callq 0x5280
leaq -0xf1(%rbp), %rdi
callq 0x5440
movl -0x190(%rbp), %eax
cmpl $0x0, %eax
je 0xc395
movl $0x1, -0x4(%rbp)
jmp 0xc50e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc384
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x5280
leaq -0xf1(%rbp), %rdi
callq 0x5440
jmp 0xc51a
jmp 0xc397
jmp 0xc399
testb $0x1, -0x40(%rbp)
je 0xc3d5
testb $0x1, -0x21(%rbp)
je 0xc3d3
movq 0x25bec(%rip), %rdi     # 0x31f98
leaq 0x17cb2(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17dcc(%rip), %rsi     # 0x2419a
callq 0x53d0
jmp 0xc427
testb $0x1, -0x3e(%rbp)
je 0xc425
testb $0x1, -0x21(%rbp)
je 0xc423
movq 0x25bb0(%rip), %rdi     # 0x31f98
leaq 0x17c76(%rip), %rsi     # 0x24065
callq 0x53d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x53d0
movq %rax, %rdi
leaq 0x17d9c(%rip), %rsi     # 0x241a6
callq 0x53d0
movl -0x3c(%rbp), %edi
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0x30(%rbp), %r8d
xorl %esi, %esi
callq 0xcb50
jmp 0xc425
jmp 0xc427
movl -0x8(%rbp), %eax
movl %eax, -0x1b4(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x1a4(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x5700
movq -0x1a0(%rbp), %rsi
movq -0x198(%rbp), %rdx
leaq -0x118(%rbp), %rdi
callq 0x10f00
jmp 0xc47e
movl -0x1a4(%rbp), %edx
movq -0x1b0(%rbp), %rsi
movl -0x1b4(%rbp), %edi
movzbl -0x21(%rbp), %r9d
movzbl -0x22(%rbp), %r8d
andl $0x1, %r8d
andl $0x1, %r9d
leaq -0x118(%rbp), %rcx
callq 0xc9b0
movl %eax, -0x1b8(%rbp)
jmp 0xc4b7
movl -0x1b8(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x5280
leaq -0x119(%rbp), %rdi
callq 0x5440
jmp 0xc50e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0xc500
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x5280
leaq -0x119(%rbp), %rdi
callq 0x5440
jmp 0xc51a
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x56f0
nopw %cs:(%rax,%rax)