// File: /workspace/github_c_makefile_star2_O1/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 0x43fb(%rip), %rsi      # 0x9084
movl $0x2, %edi
xorl %eax, %eax
callq 0x43fd
cmpb $0x0, 0x8(%rbx)
je 0x4d41
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x55e3
testl %eax, %eax
jne 0x4fd3
movq 0x60(%rbx), %rdx
leaq 0x446a(%rip), %rsi      # 0x9128
movl $0x2, %edi
xorl %eax, %eax
callq 0x43fd
movq 0x60(%rbx), %rdx
testb $0x3, %dl
je 0x4cf5
leaq 0x3(%rdx), %r14
andq $-0x4, %r14
leaq 0x4458(%rip), %rsi      # 0x913a
movl $0x2, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x43fd
movq %r14, 0x60(%rbx)
cmpl $0x4, 0x9454(%rip)      # 0xe150
jl 0x4d41
leaq 0x447e(%rip), %rsi      # 0x9183
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
leaq 0x4480(%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 0x4f7c
movq 0x28(%rbx), %rdx
leaq 0x46d1(%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 0x4e2e
cmpq $0x95ff, %rax           # imm = 0x95FF
jg 0x4e51
cmpq $0x2580, %rax           # imm = 0x2580
je 0x4e8c
cmpq $0x4b00, %rax           # imm = 0x4B00
jne 0x4fdd
movl $0x8be, %ecx            # imm = 0x8BE
jmp 0x4e9f
cmpq $0x8c9ff, %rax          # imm = 0x8C9FF
jg 0x4e6c
cmpq $0x1c200, %rax          # imm = 0x1C200
je 0x4e93
cmpq $0x38400, %rax          # imm = 0x38400
jne 0x4fdd
movl $0x18b3, %ecx           # imm = 0x18B3
jmp 0x4e9f
cmpq $0x9600, %rax           # imm = 0x9600
je 0x4e9a
cmpq $0xe100, %rax           # imm = 0xE100
jne 0x4fdd
movl $0x18b1, %ecx           # imm = 0x18B1
jmp 0x4e9f
movl $0x18b9, %ecx           # imm = 0x18B9
cmpq $0x119400, %rax         # imm = 0x119400
je 0x4e9f
cmpq $0x8ca00, %rax          # imm = 0x8CA00
jne 0x4fdd
movl $0x18b6, %ecx           # imm = 0x18B6
jmp 0x4e9f
movl $0x8bd, %ecx            # imm = 0x8BD
jmp 0x4e9f
movl $0x18b2, %ecx           # imm = 0x18B2
jmp 0x4e9f
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 0x4fa7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4a8d
movq %rbx, %rdi
callq 0x46b6
cmpb $0x0, 0x8(%rbx)
jne 0x4f15
cmpb $0x0, 0x35(%rbx)
je 0x4f41
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x4f2f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x4f39
movq %rbx, %rdi
callq 0x6110
jmp 0x4f37
movq %rbx, %rdi
callq 0x5d60
movl %eax, %ebp
testl %ebp, %ebp
jne 0x4fc4
cmpq $0x0, 0x70(%rbx)
je 0x4f4e
cmpb $0x0, 0x30(%rbx)
je 0x4f5b
movq %rbx, %rdi
movl $0x1, %esi
callq 0x4a8d
movl $0x1, 0x91eb(%rip)      # 0xe150
movq %rbx, %rdi
callq 0x81a9
movq %rbx, %rdi
callq 0x4ff5
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x4050
movl (%rax), %ecx
movq 0x28(%rbx), %rdx
leaq 0x447f(%rip), %rsi      # 0x940d
movl $0x1, %edi
movl %ecx, %r8d
xorl %eax, %eax
callq 0x43fd
movl $0x2, %edi
callq 0x4240
leaq 0x44b9(%rip), %rsi      # 0x9467
movl $0x1, %edi
xorl %eax, %eax
callq 0x43fd
movl $0x3, %edi
callq 0x4240
movq %rbx, %rdi
callq 0x4ff5
movl %ebp, %edi
callq 0x4240
movl $0x1, %edi
callq 0x4240
leaq 0x446e(%rip), %rsi      # 0x9452
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x43fd
jmp 0x4fba