// File: /workspace/github_c_makefile_star2_O0/bokunimowakaru[P]petit15term/lpc21isp/lpc21isp.c
// Function: LoadFile
static int LoadFile(ISP_ENVIRONMENT *IspEnvironment, const char *filename, int FileFormat)
{
    int            fd;
    int            i;
    int            BinaryOffsetDefined;
    unsigned long  Pos;
    unsigned long  FileLength;
    BINARY        *FileContent;              /**< Used to store the content of a hex */
                                             /*   file before converting to binary.  */
    unsigned long  BinaryMemSize;

    fd = open(filename, O_RDONLY | O_BINARY);
    if (fd == -1)
    {
        DebugPrintf(1, "Can't open file %s\n", filename);
        return ERR_FILE_OPEN_HEX;
    }

    FileLength = lseek(fd, 0L, 2);      // Get file size

    if (FileLength == (size_t)-1)
    {
        DebugPrintf(1, "\nFileLength = -1 !?!\n");
        return ERR_FILE_SIZE_HEX;
    }

    lseek(fd, 0L, 0);

    // Just read the entire file into memory to parse.
    FileContent = (BINARY*) malloc(FileLength);

    if( FileContent == 0)
    {
        DebugPrintf( 1, "\nCouldn't allocate enough memory for file.\n");
        return ERR_FILE_ALLOC_HEX;
    }

    BinaryOffsetDefined = 0;

    BinaryMemSize = IspEnvironment->BinaryLength;

    read(fd, FileContent, FileLength);

    close(fd);

    DebugPrintf(2, "File %s:\n\tloaded...\n", filename);

    // Intel-Hex -> Binary Conversion

    if (FileFormat == FORMAT_HEX)
    {
        unsigned char  RecordLength;
        unsigned short RecordAddress;
        unsigned long  RealAddress = 0;
        unsigned char  RecordType;
        unsigned char  Hexvalue;
        unsigned long  StartAddress;

        DebugPrintf(3, "Converting file %s to binary format...\n", filename);

        Pos = 0;
        while (Pos < FileLength)
        {
            if (FileContent[Pos] == '\r')
            {
                Pos++;
                continue;
            }

            if (FileContent[Pos] == '\n')
            {
                Pos++;
                continue;
            }

            if (FileContent[Pos] != ':')
            {
                DebugPrintf(1, "Missing start of record (':') wrong byte %c / %02X\n", FileContent[Pos], FileContent[Pos]);
                exit(1);
            }

            Pos++;

            RecordLength   = Ascii2Hex(FileContent[Pos++]);
            RecordLength <<= 4;
            RecordLength  |= Ascii2Hex(FileContent[Pos++]);

            DebugPrintf(4, "RecordLength = %02X\n", RecordLength);

            RecordAddress   = Ascii2Hex(FileContent[Pos++]);
            RecordAddress <<= 4;
            RecordAddress  |= Ascii2Hex(FileContent[Pos++]);
            RecordAddress <<= 4;
            RecordAddress  |= Ascii2Hex(FileContent[Pos++]);
            RecordAddress <<= 4;
            RecordAddress  |= Ascii2Hex(FileContent[Pos++]);

            DebugPrintf(4, "RecordAddress = %04X\n", RecordAddress);

            RealAddress = RealAddress - (RealAddress & 0xffff) + RecordAddress;

            DebugPrintf(4, "RealAddress = %08lX\n", RealAddress);

            RecordType      = Ascii2Hex(FileContent[Pos++]);
            RecordType    <<= 4;
            RecordType     |= Ascii2Hex(FileContent[Pos++]);

            DebugPrintf(4, "RecordType = %02X\n", RecordType);

            if (RecordType == 0x00)          // 00 - Data record
            {
                /*
                * Binary Offset is defined as soon as first data record read
                */
                BinaryOffsetDefined = 1;
                // Memory for binary file big enough ?
                while (RealAddress + RecordLength - IspEnvironment->BinaryOffset > BinaryMemSize)
                {
                    if(!BinaryMemSize) BinaryMemSize = FileLength * 2;
                    else BinaryMemSize <<= 1;
                    IspEnvironment->BinaryContent = realloc(IspEnvironment->BinaryContent, BinaryMemSize);
                }

                // We need to know, what the highest address is,
                // how many bytes / sectors we must flash
                if (RealAddress + RecordLength - IspEnvironment->BinaryOffset > IspEnvironment->BinaryLength)
                {
                    IspEnvironment->BinaryLength = RealAddress + RecordLength - IspEnvironment->BinaryOffset;
                    DebugPrintf(3, "Image size now: %ld\n", IspEnvironment->BinaryLength);
                }

                for (i = 0; i < RecordLength; i++)
                {
                    Hexvalue        = Ascii2Hex(FileContent[Pos++]);
                    Hexvalue      <<= 4;
                    Hexvalue       |= Ascii2Hex(FileContent[Pos++]);
                    IspEnvironment->BinaryContent[RealAddress + i - IspEnvironment->BinaryOffset] = Hexvalue;
                }
            }
            else if (RecordType == 0x01)     // 01 - End of file record
            {
                break;
            }
            else if (RecordType == 0x02)     // 02 - Extended segment address record
            {
                for (i = 0; i < RecordLength * 2; i++)   // double amount of nibbles
                {
                    RealAddress <<= 4;
                    if (i == 0)
                    {
                        RealAddress  = Ascii2Hex(FileContent[Pos++]);
                    }
                    else
                    {
                        RealAddress |= Ascii2Hex(FileContent[Pos++]);
                    }
                }
                RealAddress <<= 4;
            }
            else if (RecordType == 0x03)     // 03 - Start segment address record
            {
                unsigned long cs,ip;
                StartAddress = 0;
                for (i = 0; i < RecordLength * 2; i++)   // double amount of nibbles
                {
                    StartAddress <<= 4;
                    if (i == 0)
                    {
                        StartAddress  = Ascii2Hex(FileContent[Pos++]);
                    }
                    else
                    {
                        StartAddress |= Ascii2Hex(FileContent[Pos++]);
                    }
                }
                cs = StartAddress >> 16; //high part
                ip = StartAddress & 0xffff; //low part
                StartAddress = cs*16+ip; //segmented 20-bit space
                DebugPrintf(1,"Start Address = 0x%08X\n", StartAddress);
                IspEnvironment->StartAddress = StartAddress;
            }
            else if (RecordType == 0x04)     // 04 - Extended linear address record, used by IAR
            {
                for (i = 0; i < RecordLength * 2; i++)   // double amount of nibbles
                {
                    RealAddress <<= 4;
                    if (i == 0)
                    {
                        RealAddress  = Ascii2Hex(FileContent[Pos++]);
                    }
                    else
                    {
                        RealAddress |= Ascii2Hex(FileContent[Pos++]);
                    }
                }
                RealAddress <<= 16;
                if (!BinaryOffsetDefined)
                {
                    // set startaddress of BinaryContent
                    // use of LPC_FLASHMASK to allow a memory range, not taking the first
                    // [04] record as actual start-address.
                    IspEnvironment->BinaryOffset = RealAddress & LPC_FLASHMASK;
                }
                else
                {
                    if ((RealAddress & LPC_FLASHMASK) != IspEnvironment->BinaryOffset)
                    {
                        DebugPrintf(1, "New Extended Linear Address Record [04] out of memory range\n");
                        DebugPrintf(1, "Current Memory starts at: 0x%08X, new Address is: 0x%08X",
                            IspEnvironment->BinaryOffset, RealAddress);
                        return ERR_MEMORY_RANGE;
                    }
                }
            }
            else if (RecordType == 0x05)     // 05 - Start linear address record
            {
                StartAddress = 0;
                for (i = 0; i < RecordLength * 2; i++)   // double amount of nibbles
                {
                    StartAddress <<= 4;
                    if (i == 0)
                    {
                        StartAddress  = Ascii2Hex(FileContent[Pos++]);
                    }
                    else
                    {
                        StartAddress |= Ascii2Hex(FileContent[Pos++]);
                    }
                }
                DebugPrintf(1,"Start Address = 0x%08X\n", StartAddress);
                IspEnvironment->StartAddress = StartAddress;
            }
            else
            {
                free( FileContent);
                DebugPrintf( 1, "Error %d RecordType %02X not yet implemented\n", ERR_RECORD_TYPE_LOADFILE, RecordType);
                return( ERR_RECORD_TYPE_LOADFILE);
            }

            while (FileContent[Pos++] != 0x0a)      // Search till line end
            {
            }
        }

        DebugPrintf(2, "\tconverted to binary format...\n");

        // When debugging is switched on, output result of conversion to file debugout.bin
        if (debug_level >= 4)
        {
            int fdout;
            fdout = open("debugout.bin", O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0777);
            write(fdout, IspEnvironment->BinaryContent, IspEnvironment->BinaryLength);
            close(fdout);
        }

        free( FileContent);   // Done with file contents
    }
    else // FORMAT_BINARY
    {
        IspEnvironment->BinaryContent = FileContent;
        IspEnvironment->BinaryLength = FileLength;
    }

    DebugPrintf(2, "\timage size : %ld\n", IspEnvironment->BinaryLength);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x4210
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x610f
movq -0x18(%rbp), %rdx
movl $0x1, %edi
leaq 0x50bf(%rip), %rsi      # 0xb1bb
movb $0x0, %al
callq 0x44e0
movl $0x3d, -0x4(%rbp)
jmp 0x6a27
movl -0x20(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x40d0
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x38(%rbp)
jne 0x614a
movl $0x1, %edi
leaq 0x5098(%rip), %rsi      # 0xb1cf
movb $0x0, %al
callq 0x44e0
movl $0x3e, -0x4(%rbp)
jmp 0x6a27
movl -0x20(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x40d0
movq -0x38(%rbp), %rdi
callq 0x4180
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x618b
movl $0x1, %edi
leaq 0x506d(%rip), %rsi      # 0xb1e5
movb $0x0, %al
callq 0x44e0
movl $0x3f, -0x4(%rbp)
jmp 0x6a27
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %edi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4110
movl -0x20(%rbp), %edi
callq 0x4100
movq -0x18(%rbp), %rdx
movl $0x2, %edi
leaq 0x504b(%rip), %rsi      # 0xb211
movb $0x0, %al
callq 0x44e0
cmpl $0x1, -0x1c(%rbp)
jne 0x69ed
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rdx
movl $0x3, %edi
leaq 0x5037(%rip), %rsi      # 0xb226
movb $0x0, %al
callq 0x44e0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x698b
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x622b
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x61fe
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x624a
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x61fe
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x6290
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %edx
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movl $0x1, %edi
leaq 0x4fcf(%rip), %rsi      # 0xb24e
movb $0x0, %al
callq 0x44e0
movl $0x1, %edi
callq 0x4250
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movb %al, -0x49(%rbp)
movzbl -0x49(%rbp), %eax
shll $0x4, %eax
movb %al, -0x49(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzbl -0x49(%rbp), %eax
orl %ecx, %eax
movb %al, -0x49(%rbp)
movzbl -0x49(%rbp), %edx
movl $0x4, %edi
leaq 0x4f85(%rip), %rsi      # 0xb282
movb $0x0, %al
callq 0x44e0
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
movw %ax, -0x4c(%rbp)
movzwl -0x4c(%rbp), %eax
shll $0x4, %eax
movw %ax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzwl -0x4c(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x4c(%rbp)
movzwl -0x4c(%rbp), %eax
shll $0x4, %eax
movw %ax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzwl -0x4c(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x4c(%rbp)
movzwl -0x4c(%rbp), %eax
shll $0x4, %eax
movw %ax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzwl -0x4c(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x4c(%rbp)
movzwl -0x4c(%rbp), %edx
movl $0x4, %edi
leaq 0x4ec4(%rip), %rsi      # 0xb297
movb $0x0, %al
callq 0x44e0
movq -0x58(%rbp), %rax
movq -0x58(%rbp), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
subq %rcx, %rax
movzwl -0x4c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdx
movl $0x4, %edi
leaq 0x4ea6(%rip), %rsi      # 0xb2ad
movb $0x0, %al
callq 0x44e0
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movb %al, -0x59(%rbp)
movzbl -0x59(%rbp), %eax
shll $0x4, %eax
movb %al, -0x59(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzbl -0x59(%rbp), %eax
orl %ecx, %eax
movb %al, -0x59(%rbp)
movzbl -0x59(%rbp), %edx
movl $0x4, %edi
leaq 0x4e53(%rip), %rsi      # 0xb2c2
movb $0x0, %al
callq 0x44e0
movzbl -0x59(%rbp), %eax
cmpl $0x0, %eax
jne 0x65ce
movl $0x1, -0x28(%rbp)
movq -0x58(%rbp), %rax
movzbl -0x49(%rbp), %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
subq 0x68(%rcx), %rax
cmpq -0x48(%rbp), %rax
jbe 0x64e0
cmpq $0x0, -0x48(%rbp)
jne 0x64b7
movq -0x38(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
jmp 0x64c2
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x41b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
jmp 0x648a
movq -0x58(%rbp), %rax
movzbl -0x49(%rbp), %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
subq 0x68(%rcx), %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jbe 0x6533
movq -0x58(%rbp), %rcx
movzbl -0x49(%rbp), %eax
addq %rax, %rcx
movq -0x10(%rbp), %rax
subq 0x68(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdx
movl $0x3, %edi
leaq 0x4da9(%rip), %rsi      # 0xb2d5
movb $0x0, %al
callq 0x44e0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movzbl -0x49(%rbp), %ecx
cmpl %ecx, %eax
jge 0x65c9
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movb %al, -0x5a(%rbp)
movzbl -0x5a(%rbp), %eax
shll $0x4, %eax
movb %al, -0x5a(%rbp)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %ecx
movzbl -0x5a(%rbp), %eax
orl %ecx, %eax
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %dl
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x58(%rbp), %rcx
movslq -0x24(%rbp), %rsi
addq %rsi, %rcx
movq -0x10(%rbp), %rsi
subq 0x68(%rsi), %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x653a
jmp 0x6966
movzbl -0x59(%rbp), %eax
cmpl $0x1, %eax
jne 0x65dc
jmp 0x698b
movzbl -0x59(%rbp), %eax
cmpl $0x2, %eax
jne 0x6679
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movzbl -0x49(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x6668
movq -0x58(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x6634
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
movq %rax, -0x58(%rbp)
jmp 0x665b
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x665d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x65f0
movq -0x58(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x58(%rbp)
jmp 0x6962
movzbl -0x59(%rbp), %eax
cmpl $0x3, %eax
jne 0x675f
movq $0x0, -0x68(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movzbl -0x49(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x670d
movq -0x68(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x66d9
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
movq %rax, -0x68(%rbp)
jmp 0x6700
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x6702
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6695
movq -0x68(%rbp), %rax
shrq $0x10, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
andq $0xffff, %rax           # imm = 0xFFFF
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
shlq $0x4, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdx
movl $0x1, %edi
leaq 0x4ba3(%rip), %rsi      # 0xb2ea
movb $0x0, %al
callq 0x44e0
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x6960
movzbl -0x59(%rbp), %eax
cmpl $0x4, %eax
jne 0x6872
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movzbl -0x49(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x67eb
movq -0x58(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x67b7
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
movq %rax, -0x58(%rbp)
jmp 0x67de
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x67e0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6773
movq -0x58(%rbp), %rax
shlq $0x10, %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x6815
movabsq $0xffc00000, %rcx       # imm = 0xFFC00000
andq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
jmp 0x686d
movabsq $0xffc00000, %rax       # imm = 0xFFC00000
andq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x68(%rcx), %rax
je 0x686b
movl $0x1, %edi
leaq 0x4ac9(%rip), %rsi      # 0xb302
movb $0x0, %al
callq 0x44e0
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdx
movq -0x58(%rbp), %rcx
movl $0x1, %edi
leaq 0x4ae7(%rip), %rsi      # 0xb33f
movb $0x0, %al
callq 0x44e0
movl $0x45, -0x4(%rbp)
jmp 0x6a27
jmp 0x686d
jmp 0x695e
movzbl -0x59(%rbp), %eax
cmpl $0x5, %eax
jne 0x692b
movq $0x0, -0x68(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movzbl -0x49(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x6906
movq -0x68(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x68d2
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
movq %rax, -0x68(%rbp)
jmp 0x68f9
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %edi
callq 0x6a40
movzbl %al, %eax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x68fb
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x688e
movq -0x68(%rbp), %rdx
movl $0x1, %edi
leaq 0x49d4(%rip), %rsi      # 0xb2ea
movb $0x0, %al
callq 0x44e0
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x695c
movq -0x40(%rbp), %rdi
callq 0x4030
movzbl -0x59(%rbp), %ecx
movl $0x1, %edi
leaq 0x4a34(%rip), %rsi      # 0xb378
movl $0x37, %edx
movb $0x0, %al
callq 0x44e0
movl $0x37, -0x4(%rbp)
jmp 0x6a27
jmp 0x695e
jmp 0x6960
jmp 0x6962
jmp 0x6964
jmp 0x6966
jmp 0x6968
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x6986
jmp 0x6968
jmp 0x61fe
movl $0x2, %edi
leaq 0x4a0f(%rip), %rsi      # 0xb3a6
movb $0x0, %al
callq 0x44e0
cmpl $0x4, 0x97ab(%rip)      # 0x10150
jl 0x69e2
leaq 0x47d2(%rip), %rdi      # 0xb180
movl $0x242, %esi            # imm = 0x242
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x4210
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %edi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdx
callq 0x4090
movl -0x7c(%rbp), %edi
callq 0x4100
movq -0x40(%rbp), %rdi
callq 0x4030
jmp 0x6a05
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdx
movl $0x2, %edi
leaq 0x49ad(%rip), %rsi      # 0xb3c6
movb $0x0, %al
callq 0x44e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)