// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movslq 0x8(%rdi), %rax
movslq 0xc(%rdi), %rbp
imulq %rax, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rcx
movq -0x18(%rcx), %rcx
cmpl $0x0, 0x20(%rbx,%rcx)
je 0x3b03
movl $0x28, %edx
movq 0x450d(%rip), %rdi      # 0x7ff0
leaq 0x15ee(%rip), %rsi      # 0x50d8
callq 0x21d0
xorl %eax, %eax
testb %al, %al
je 0x3cef
cmpq %rbp, %r12
jb 0x3abc
jmp 0x3cef
testb %al, %al
js 0x3bbb
incl %eax
andl $0xff, %eax
setne %dl
je 0x3cb4
leal -0x1(%rax), %ecx
addq %r12, %rcx
incq %rcx
movq %rcx, 0x20(%rsp)
xorl %ebx, %ebx
movb %dl, 0x7(%rsp)
movq %r12, 0x8(%rsp)
movq %rax, %r12
movq %rbp, %r13
movslq 0x10(%r14), %rdx
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x21f0
movq (%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbp,%rax)
jne 0x3c76
cmpl $0x0, 0x10(%r14)
movq %r13, %rbp
jle 0x3b90
xorl %esi, %esi
movq %r12, %rax
movb 0x10(%rsp,%rsi), %cl
movq (%r14), %rdx
addq %r15, %rdx
movb %cl, (%rsi,%rdx)
incq %rsi
movslq 0x10(%r14), %rcx
cmpq %rcx, %rsi
jl 0x3b72
addq %rsi, %r15
jmp 0x3b93
movq %r12, %rax
movq 0x8(%rsp), %r12
incq %r12
cmpq %rbp, %r12
ja 0x3c98
incl %ebx
cmpl %eax, %ebx
setb %dl
jne 0x3b2b
movq 0x20(%rsp), %r12
jmp 0x3cb4
movq %r12, 0x8(%rsp)
movq %rax, %r12
movslq 0x10(%r14), %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%rbx,%rax)
je 0x3c0b
movl $0x2a, %edx
movq 0x43fd(%rip), %rdi      # 0x7ff0
leaq 0x1492(%rip), %rsi      # 0x508c
callq 0x21d0
xorl %eax, %eax
movq 0x8(%rsp), %r12
jmp 0x3af1
movq %r12, %r8
addl $0x81, %r8d
andl $0xff, %r8d
setne %r13b
je 0x3cbf
leal -0x1(%r8), %eax
movq 0x8(%rsp), %r12
addq %r12, %rax
incq %rax
xorl %ecx, %ecx
cmpl $0x0, 0x10(%r14)
jle 0x3c5e
xorl %edx, %edx
movb 0x10(%rsp,%rdx), %sil
movq (%r14), %rdi
addq %r15, %rdi
movb %sil, (%rdx,%rdi)
incq %rdx
movslq 0x10(%r14), %rsi
cmpq %rsi, %rdx
jl 0x3c40
addq %rdx, %r15
incq %r12
cmpq %rbp, %r12
ja 0x3cc6
incl %ecx
cmpl %r8d, %ecx
setb %r13b
jne 0x3c37
movq %rax, %r12
jmp 0x3cde
movl $0x2a, %edx
movq 0x436e(%rip), %rdi      # 0x7ff0
leaq 0x1403(%rip), %rsi      # 0x508c
callq 0x21d0
movq %r13, %rbp
movq 0x8(%rsp), %r12
jmp 0x3cb0
movl $0x15, %edx
movq 0x434c(%rip), %rdi      # 0x7ff0
leaq 0x146f(%rip), %rsi      # 0x511a
callq 0x21d0
movb 0x7(%rsp), %dl
testb $0x1, %dl
jne 0x3aef
jmp 0x3ce8
movq 0x8(%rsp), %r12
jmp 0x3cde
movl $0x15, %edx
movq 0x431e(%rip), %rdi      # 0x7ff0
leaq 0x1441(%rip), %rsi      # 0x511a
callq 0x21d0
testb $0x1, %r13b
jne 0x3aef
movb $0x1, %al
jmp 0x3af1
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq