// File: /workspace/github_cpp_makefile_star2_O3/shinerd[P]BriefRenderer/tgaimage.cpp
// Function: TGAImage::load_rle_data(std::basic_ifstream<char, std::char_traits<char>>&)
bool TGAImage::load_rle_data(std::ifstream &in) {
    unsigned long pixelcount = width*height;
    unsigned long currentpixel = 0;
    unsigned long currentbyte  = 0;
    TGAColor colorbuffer;
    do {
        unsigned char chunkheader = 0;
        chunkheader = in.get();
        if (!in.good()) {
            std::cerr << "an error occured while reading the data\n";
            return false;
        }
        if (chunkheader<128) {
            chunkheader++;
            for (int i=0; i<chunkheader; i++) {
                in.read((char *)colorbuffer.raw, bytespp);
                if (!in.good()) {
                    std::cerr << "an error occured while reading the header\n";
                    return false;
                }
                for (int t=0; t<bytespp; t++)
                    data[currentbyte++] = colorbuffer.raw[t];
                currentpixel++;
                if (currentpixel>pixelcount) {
                    std::cerr << "Too many pixels read\n";
                    return false;
                }
            }
        } else {
            chunkheader -= 127;
            in.read((char *)colorbuffer.raw, bytespp);
            if (!in.good()) {
                std::cerr << "an error occured while reading the header\n";
                return false;
            }
            for (int i=0; i<chunkheader; i++) {
                for (int t=0; t<bytespp; t++)
                    data[currentbyte++] = colorbuffer.raw[t];
                currentpixel++;
                if (currentpixel>pixelcount) {
                    std::cerr << "Too many pixels read\n";
                    return false;
                }
            }
        }
    } while (currentpixel < pixelcount);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x8(%rdi), %rax
movslq 0xc(%rdi), %r13
imulq %rax, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rsp, %rcx
movq %rax, (%rcx)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x21e0
movl %eax, %r12d
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbx,%rax)
jne 0x3c26
testb %r12b, %r12b
js 0x3b7e
incl %r12d
andl $0xff, %r12d
je 0x3bef
movq %r13, 0x8(%rsp)
leal -0x1(%r12), %eax
addq %rbp, %rax
incq %rax
movq %rax, 0x10(%rsp)
movl 0x10(%r14), %eax
xorl %r13d, %r13d
movslq %eax, %rdx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbx,%rax)
jne 0x3c11
movl 0x10(%r14), %eax
testl %eax, %eax
jle 0x3b5c
xorl %ecx, %ecx
movb (%rsp,%rcx), %al
movq (%r14), %rdx
addq %r15, %rdx
movb %al, (%rcx,%rdx)
incq %rcx
movslq 0x10(%r14), %rax
cmpq %rax, %rcx
jl 0x3b41
addq %rcx, %r15
incq %rbp
cmpq 0x8(%rsp), %rbp
ja 0x3bfc
incl %r13d
cmpl %r12d, %r13d
jne 0x3b17
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r13
jmp 0x3bef
movslq 0x10(%r14), %rdx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbx,%rax)
jne 0x3c11
addl $0x81, %r12d
andl $0xff, %r12d
je 0x3bef
leal -0x1(%r12), %eax
addq %rbp, %rax
incq %rax
movl 0x10(%r14), %edx
xorl %ecx, %ecx
testl %edx, %edx
jle 0x3bdd
xorl %esi, %esi
movb (%rsp,%rsi), %dl
movq (%r14), %rdi
addq %r15, %rdi
movb %dl, (%rsi,%rdi)
incq %rsi
movslq 0x10(%r14), %rdx
cmpq %rdx, %rsi
jl 0x3bc2
addq %rsi, %r15
incq %rbp
cmpq %r13, %rbp
ja 0x3bfc
incl %ecx
cmpl %r12d, %ecx
jne 0x3bbc
movq %rax, %rbp
cmpq %r13, %rbp
jb 0x3ac5
movb $0x1, %al
jmp 0x3c40
movq 0x43ed(%rip), %rdi      # 0x7ff0
leaq 0x1510(%rip), %rsi      # 0x511a
movl $0x15, %edx
jmp 0x3c39
movq 0x43d8(%rip), %rdi      # 0x7ff0
leaq 0x146d(%rip), %rsi      # 0x508c
movl $0x2a, %edx
jmp 0x3c39
movq 0x43c3(%rip), %rdi      # 0x7ff0
leaq 0x14a4(%rip), %rsi      # 0x50d8
movl $0x28, %edx
callq 0x21d0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop