// File: /workspace/github_c_makefile_star2_O2/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
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0x445a(%rip), %rsi      # 0x9084
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x43f9
cmpb $0x0, 0x8(%rbx)
je 0x4cda
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x54dc
testl %eax, %eax
jne 0x4f1b
movq 0x60(%rbx), %rdx
leaq 0x44cb(%rip), %rsi      # 0x9128
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x43f9
movq 0x60(%rbx), %rdx
testb $0x3, %dl
je 0x4c90
leaq 0x3(%rdx), %r14
andq $-0x4, %r14
leaq 0x44bb(%rip), %rsi      # 0x913a
pushq $0x2
popq %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x43f9
movq %r14, 0x60(%rbx)
cmpl $0x4, 0x94b9(%rip)      # 0xe150
jl 0x4cda
leaq 0x44e3(%rip), %rsi      # 0x9183
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x43f9
leaq 0x44e7(%rip), %rdi      # 0x9198
movl $0x242, %esi            # imm = 0x242
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x4200
movl %eax, %ebp
movq 0x58(%rbx), %rsi
movq 0x60(%rbx), %rdx
movl %eax, %edi
callq 0x4090
movl %ebp, %edi
callq 0x4100
movq 0x28(%rbx), %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x4200
movl %eax, 0x80(%rbx)
testl %eax, %eax
js 0x4ee3
movq 0x28(%rbx), %rdx
leaq 0x4738(%rip), %rsi      # 0x943b
pushq $0x3
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0x43f9
movl 0x80(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x40b0
movl 0x80(%rbx), %edi
xorl %esi, %esi
callq 0x40b0
movl 0x80(%rbx), %r14d
movl %r14d, %edi
movl %ebp, %esi
xorl %eax, %eax
callq 0x4080
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
pushq $0x4
popq %rsi
movl %r14d, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x4080
movl 0x80(%rbx), %edi
leaq 0x84(%rbx), %rsi
callq 0x41d0
xorps %xmm0, %xmm0
movups %xmm0, 0xc0(%rbx)
movups %xmm0, 0xd0(%rbx)
movups %xmm0, 0xe0(%rbx)
movups %xmm0, 0xec(%rbx)
movl $0x8b0, 0xc8(%rbx)      # imm = 0x8B0
movq 0x40(%rbx), %r14
movq %r14, %rdi
callq 0x41f0
cmpq $0x2580, %rax           # imm = 0x2580
je 0x4dfd
cmpq $0x4b00, %rax           # imm = 0x4B00
je 0x4e0b
cmpq $0x9600, %rax           # imm = 0x9600
je 0x4e04
cmpq $0xe100, %rax           # imm = 0xE100
je 0x4de8
cmpq $0x1c200, %rax          # imm = 0x1C200
je 0x4def
cmpq $0x38400, %rax          # imm = 0x38400
je 0x4df6
movl $0x18b9, %ecx           # imm = 0x18B9
cmpq $0x119400, %rax         # imm = 0x119400
je 0x4e10
cmpq $0x8ca00, %rax          # imm = 0x8CA00
jne 0x4f35
movl $0x18b6, %ecx           # imm = 0x18B6
jmp 0x4e10
movl $0x18b1, %ecx           # imm = 0x18B1
jmp 0x4e10
movl $0x18b2, %ecx           # imm = 0x18B2
jmp 0x4e10
movl $0x18b3, %ecx           # imm = 0x18B3
jmp 0x4e10
movl $0x8bd, %ecx            # imm = 0x8BD
jmp 0x4e10
movl $0x8bf, %ecx            # imm = 0x8BF
jmp 0x4e10
movl $0x8be, %ecx            # imm = 0x8BE
leaq 0xc0(%rbx), %r14
movl %ecx, 0xc8(%rbx)
movq $0x1405, 0xc0(%rbx) # imm = 0x1405
andl $0x0, 0xcc(%rbx)
movq %r14, %rdi
callq 0x41b0
movw $0x1, 0xd6(%rbx)
movl 0x80(%rbx), %edi
xorl %esi, %esi
callq 0x40b0
movl 0x80(%rbx), %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x41e0
testl %eax, %eax
jne 0x4f06
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4a33
movq %rbx, %rdi
callq 0x4691
cmpb $0x0, 0x8(%rbx)
jne 0x4e83
cmpb $0x0, 0x35(%rbx)
je 0x4eaa
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x4e9c
testl %eax, %eax
jne 0x4f23
movq %rbx, %rdi
callq 0x5f48
jmp 0x4ea4
movq %rbx, %rdi
callq 0x5bb0
movl %eax, %ebp
testl %eax, %eax
jne 0x4f26
cmpq $0x0, 0x70(%rbx)
je 0x4eb7
cmpb $0x0, 0x30(%rbx)
je 0x4ec2
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x4a33
movl $0x1, 0x9284(%rip)      # 0xe150
movq %rbx, %rdi
callq 0x7f41
movq %rbx, %rdi
callq 0x4f4b
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x4050
movl (%rax), %ecx
movq 0x28(%rbx), %rdx
leaq 0x4518(%rip), %rsi      # 0x940d
pushq $0x1
popq %rdi
movl %ecx, %r8d
xorl %eax, %eax
callq 0x43f9
pushq $0x2
jmp 0x4f1d
leaq 0x455a(%rip), %rsi      # 0x9467
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x43f9
pushq $0x3
jmp 0x4f1d
pushq $0x1
popq %rdi
callq 0x4240
pushq $-0x1
popq %rbp
movq %rbx, %rdi
callq 0x4f4b
movl %ebp, %edi
callq 0x4240
leaq 0x4516(%rip), %rsi      # 0x9452
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x43f9
jmp 0x4f17