// File: /workspace/github_cpp_makefile_star2_O1/dgboy2000[P]compress/compress.cpp
// Function: read_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
vector<int> read_data(string filename) {
    ifstream data_file;
    string data_line;
    vector<int> data;
    
    data_file.open(filename.c_str());
    
    int x, y, x_ind, y_ind, L, valCnt, lineCnt;
    string pHval;
    x = 0;
    y = 0;
    L = 0;
    lineCnt = 0;
    while (getline(data_file, data_line)) {
        lineCnt++;
        stringstream line_stream(data_line);
        
        string x_str, y_str;
        getline(line_stream, x_str, '\t');
        getline(line_stream, y_str, '\t');
        x_ind = atoi(x_str.c_str());
        y_ind = atoi(y_str.c_str());
        x = max(x, x_ind + 1);
        y = max(y, y_ind + 1);
        
        valCnt = 0;
        while (getline(line_stream, pHval, '\t')) {
            int val = atoi(pHval.c_str());
            data.push_back(val);
            valCnt++;
        }
        if (L > 0 && L != valCnt) {
            printf("ERROR: wrong number of values on this line! Got %d values, expected %d values on line %d\n", valCnt, L, lineCnt);
            exit(1);
        }
        L = valCnt;
    }
    data_file.close();
    
    if (data.size() != x * y  * L) {
        printf("ERROR: read in wrong amount of data! Expected %d*%d*%d = %d pH values, but read %ld\n", x, y, L, x*y*L, data.size());
        exit(1);
    }
    
    data.insert(data.begin(), L);
    data.insert(data.begin(), y);
    data.insert(data.begin(), x);    
    
    //printf("Read in %ld pH values with (x, y, L) = (%d, %d, %d)\n", data.size() - 3, x, y, L);
    
    return data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x220(%rsp), %r12
movq %r12, %rdi
callq 0x21d0
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb $0x0, (%rax)
movq %r15, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq (%r14), %rsi
movq %r12, %rdi
movl $0x8, %edx
callq 0x2100
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %r15d, 0xc(%rsp)
movl %r15d, 0x8(%rsp)
movl %r15d, 0x4(%rsp)
leaq 0x78(%rsp), %rbp
leaq 0x98(%rsp), %r13
leaq 0x58(%rsp), %r15
leaq 0x14(%rsp), %r14
movl $0x0, 0x10(%rsp)
movq 0x220(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x22d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5e43
movq %r13, %rdi
movq %rbp, %rsi
movl $0x18, %edx
callq 0x2260
movq %r12, %rbp
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movb %al, 0x48(%rsp)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb %al, 0x28(%rsp)
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
movl $0x9, %edx
callq 0x22d0
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
movl $0x9, %edx
callq 0x22d0
incl 0x10(%rsp)
movq 0x38(%rsp), %rdi
callq 0x2250
movl %eax, %r12d
movq 0x18(%rsp), %rdi
callq 0x2250
incl %r12d
movl 0xc(%rsp), %ecx
cmpl %r12d, %ecx
cmovgl %ecx, %r12d
movl %r12d, 0xc(%rsp)
incl %eax
movl 0x8(%rsp), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, 0x8(%rsp)
xorl %r12d, %r12d
movq %r13, %rdi
movq %r15, %rsi
movl $0x9, %edx
callq 0x22d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5dc6
movq 0x58(%rsp), %rdi
callq 0x2250
movl %eax, 0x14(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x5db6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x5dc1
movq %rbx, %rdi
movq %r14, %rdx
callq 0x62c2
incl %r12d
jmp 0x5d74
movl 0x4(%rsp), %edx
testl %edx, %edx
setle %al
cmpl %r12d, %edx
sete %cl
orb %al, %cl
je 0x5f0e
movl %r12d, 0x4(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x5dfe
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
movq %rbp, %r12
je 0x5e1d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r13, %rdi
movq 0x5199(%rip), %rsi      # 0xafc0
callq 0x2140
leaq 0x118(%rsp), %rdi
callq 0x20a0
leaq 0x78(%rsp), %rbp
jmp 0x5c9c
leaq 0x220(%rsp), %rdi
callq 0x2070
movq (%rbx), %rsi
movq 0x8(%rbx), %r9
subq %rsi, %r9
sarq $0x2, %r9
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %edx
movl %edx, %r8d
imull %eax, %r8d
movl 0x4(%rsp), %ecx
imull %ecx, %r8d
movslq %r8d, %rdi
cmpq %rdi, %r9
jne 0x5f2d
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x61d0
movq (%rbx), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x61d0
movq (%rbx), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x61d0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x5eca
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x5eec
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x220(%rsp), %rdi
callq 0x2080
movq %rbx, %rax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2206(%rip), %rdi      # 0x811b
movl %r12d, %esi
movl 0x10(%rsp), %ecx
xorl %eax, %eax
callq 0x2050
movl $0x1, %edi
callq 0x2200
leaq 0x2241(%rip), %rdi      # 0x8175
movl %eax, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x5f23
jmp 0x5f53
jmp 0x5f53
jmp 0x5f53
jmp 0x5f53
movq %rax, %r14
jmp 0x5fd2
jmp 0x5f53
jmp 0x5f5a
movq %rax, %r14
jmp 0x5fb6
jmp 0x5f5a
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x5f79
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x5f95
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x5024(%rip), %rsi      # 0xafc0
leaq 0x98(%rsp), %rdi
callq 0x2140
leaq 0x118(%rsp), %rdi
callq 0x20a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x5fd2
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5fe6
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x6008
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x220(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x22c0