// File: /workspace/github_c_makefile_star2_O3/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 0x4432(%rip), %rsi      # 0x9084
movl $0x2, %edi
xorl %eax, %eax
callq 0x43fd
cmpb $0x0, 0x8(%rbx)
je 0x4d0a
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x557f
testl %eax, %eax
jne 0x4f8c
movq 0x60(%rbx), %rdx
leaq 0x44a1(%rip), %rsi      # 0x9128
movl $0x2, %edi
xorl %eax, %eax
callq 0x43fd
movq 0x60(%rbx), %rdx
testb $0x3, %dl
je 0x4cbe
leaq 0x3(%rdx), %r14
andq $-0x4, %r14
leaq 0x448f(%rip), %rsi      # 0x913a
movl $0x2, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x43fd
movq %r14, 0x60(%rbx)
cmpl $0x4, 0x948b(%rip)      # 0xe150
jl 0x4d0a
leaq 0x44b5(%rip), %rsi      # 0x9183
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
leaq 0x44b7(%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 0x4f44
movq 0x28(%rbx), %rdx
leaq 0x4708(%rip), %rsi      # 0x943b
movl $0x3, %edi
xorl %eax, %eax
callq 0x43fd
movl 0x80(%rbx), %edi
movl $0x1, %esi
callq 0x40b0
movl 0x80(%rbx), %edi
xorl %esi, %esi
callq 0x40b0
movl 0x80(%rbx), %ebp
movl %ebp, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x4080
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %ebp, %edi
movl $0x4, %esi
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 $0x1c1ff, %rax          # imm = 0x1C1FF
jg 0x4df7
cmpq $0x95ff, %rax           # imm = 0x95FF
jg 0x4e1a
cmpq $0x2580, %rax           # imm = 0x2580
je 0x4e55
cmpq $0x4b00, %rax           # imm = 0x4B00
jne 0x4faa
movl $0x8be, %ecx            # imm = 0x8BE
jmp 0x4e68
cmpq $0x8c9ff, %rax          # imm = 0x8C9FF
jg 0x4e35
cmpq $0x1c200, %rax          # imm = 0x1C200
je 0x4e5c
cmpq $0x38400, %rax          # imm = 0x38400
jne 0x4faa
movl $0x18b3, %ecx           # imm = 0x18B3
jmp 0x4e68
cmpq $0x9600, %rax           # imm = 0x9600
je 0x4e63
cmpq $0xe100, %rax           # imm = 0xE100
jne 0x4faa
movl $0x18b1, %ecx           # imm = 0x18B1
jmp 0x4e68
movl $0x18b9, %ecx           # imm = 0x18B9
cmpq $0x119400, %rax         # imm = 0x119400
je 0x4e68
cmpq $0x8ca00, %rax          # imm = 0x8CA00
jne 0x4faa
movl $0x18b6, %ecx           # imm = 0x18B6
jmp 0x4e68
movl $0x8bd, %ecx            # imm = 0x8BD
jmp 0x4e68
movl $0x18b2, %ecx           # imm = 0x18B2
jmp 0x4e68
movl $0x8bf, %ecx            # imm = 0x8BF
leaq 0xc0(%rbx), %r14
movl %ecx, 0xc8(%rbx)
movq $0x1405, 0xc0(%rbx) # imm = 0x1405
movl $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 0x4f6f
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4a56
movq %rbx, %rdi
callq 0x46b7
cmpb $0x0, 0x8(%rbx)
jne 0x4ede
cmpb $0x0, 0x35(%rbx)
je 0x4f09
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x4ef7
testl %eax, %eax
jne 0x4f96
movq %rbx, %rdi
callq 0x60ac
jmp 0x4eff
movq %rbx, %rdi
callq 0x5cf8
movl %eax, %ebp
testl %eax, %eax
jne 0x4f9b
cmpq $0x0, 0x70(%rbx)
je 0x4f16
cmpb $0x0, 0x30(%rbx)
je 0x4f23
movq %rbx, %rdi
movl $0x1, %esi
callq 0x4a56
movl $0x1, 0x9223(%rip)      # 0xe150
movq %rbx, %rdi
callq 0x8691
movq %rbx, %rdi
callq 0x4fc2
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x4050
movl (%rax), %ecx
movq 0x28(%rbx), %rdx
leaq 0x44b7(%rip), %rsi      # 0x940d
movl $0x1, %edi
movl %ecx, %r8d
xorl %eax, %eax
callq 0x43fd
movl $0x2, %edi
callq 0x4240
leaq 0x44f1(%rip), %rsi      # 0x9467
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
movl $0x3, %edi
callq 0x4240
movl $0x1, %edi
callq 0x4240
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4fc2
movl %ebp, %edi
callq 0x4240
leaq 0x44a1(%rip), %rsi      # 0x9452
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x43fd
jmp 0x4f82