// File: /workspace/github_c_makefile_star2_O0/bokunimowakaru[P]petit15term/lpc21isp/lpc21isp.c
// Function: PerformActions
int PerformActions(ISP_ENVIRONMENT *IspEnvironment)
{
    int downloadResult = -1;

    DebugPrintf(2, "lpc21isp version " VERSION_STR "\n");

    /* Download requested, read in the input file.                  */
    if (IspEnvironment->ProgramChip)
    {
        LoadFiles(IspEnvironment);
    }

    OpenSerialPort(IspEnvironment);   /* Open the serial port to the microcontroller. */

    ResetTarget(IspEnvironment, PROGRAM_MODE);

    ClearSerialPortBuffers(IspEnvironment);

    /* Perform the requested download.                              */
    if (IspEnvironment->ProgramChip || IspEnvironment->DetectOnly)
    {
        switch (IspEnvironment->micro)
        {
#ifdef LPC_SUPPORT
        case NXP_ARM:
            downloadResult = NxpDownload(IspEnvironment);
            break;
#endif

#ifdef AD_SUPPORT
        case ANALOG_DEVICES_ARM:
            downloadResult = AnalogDevicesDownload(IspEnvironment);
            break;
#endif
        }

        if (downloadResult != 0)
        {
            CloseSerialPort(IspEnvironment);
            exit(downloadResult);
        }
    }

    if (IspEnvironment->StartAddress == 0 || IspEnvironment->TerminalOnly)
    {
        /* Only reset target if startaddress = 0
        * Otherwise stay with the running program as started in Download()
        */
        ResetTarget(IspEnvironment, RUN_MODE);
    }

    debug_level = 1;    /* From now on there is no more debug output !! */
                                        /* Therefore switch it off...                   */

#ifdef TERMINAL_SUPPORT
    // Pass control to Terminal which will provide a terminal if one was asked for
    // User asked for terminal emulation, provide a really dumb terminal.
    Terminal(IspEnvironment);
#endif

    CloseSerialPort(IspEnvironment);  /*  All done, close the serial port to the      */

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl $0x2, %edi
leaq 0x5edd(%rip), %rsi      # 0xb06c
movb $0x0, %al
callq 0x44e0
movq -0x8(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x51a9
movq -0x8(%rbp), %rdi
callq 0x5280
movq -0x8(%rbp), %rdi
callq 0x5380
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x4ef0
movq -0x8(%rbp), %rdi
callq 0x48f0
movq -0x8(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0x51e0
movq -0x8(%rbp), %rax
movzbl 0x35(%rax), %eax
cmpl $0x0, %eax
je 0x522c
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
testl %eax, %eax
je 0x51f9
jmp 0x51ef
movl -0x10(%rbp), %eax
subl $0x1, %eax
je 0x5207
jmp 0x5213
movq -0x8(%rbp), %rdi
callq 0x7210
movl %eax, -0xc(%rbp)
jmp 0x5213
movq -0x8(%rbp), %rdi
callq 0x6c00
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x522a
movq -0x8(%rbp), %rdi
callq 0x56e0
movl -0xc(%rbp), %edi
callq 0x4250
jmp 0x522c
movq -0x8(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x5244
movq -0x8(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x0, %eax
je 0x5252
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4ef0
movl $0x1, 0xaef4(%rip)      # 0x10150
movq -0x8(%rbp), %rdi
callq 0xac30
movq -0x8(%rbp), %rdi
callq 0x56e0
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)