// File: /workspace/github_cpp_makefile_star2_O2/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 $0x438, %rsp            # imm = 0x438
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x21c0
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq (%r14), %rsi
pushq $0x8
popq %rdx
movq %r15, %rdi
callq 0x2100
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
andl $0x0, 0x20(%rsp)
andl $0x0, 0x1c(%rsp)
movb $0x0, (%rax)
andl $0x0, 0x18(%rsp)
leaq 0x2b0(%rsp), %r12
pushq $0x9
popq %r13
leaq 0x68(%rsp), %r15
leaq 0x24(%rsp), %rbp
movl $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x14(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5095
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x2240
movl %r14d, 0x10(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
xorl %eax, %eax
movb %al, 0x58(%rsp)
leaq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb %al, 0x38(%rsp)
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
movl %r13d, %edx
callq 0x22b0
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
movl %r13d, %edx
callq 0x22b0
incl 0x14(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2230
movl %eax, %r14d
movq 0x28(%rsp), %rdi
callq 0x2230
incl %r14d
movl 0xc(%rsp), %ecx
cmpl %r14d, %ecx
cmovlel %r14d, %ecx
movl %ecx, 0xc(%rsp)
movl %ecx, 0x20(%rsp)
incl %eax
movl 0x10(%rsp), %ecx
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl %ecx, 0x10(%rsp)
movl %ecx, 0x1c(%rsp)
xorl %r14d, %r14d
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x22b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x504e
movq 0x68(%rsp), %rdi
callq 0x2230
movl %eax, 0x24(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x51de
incl %r14d
jmp 0x5014
movl 0x8(%rsp), %edx
testl %edx, %edx
sete %al
cmpl %r14d, %edx
sete %cl
orb %al, %cl
je 0x5135
movl %r14d, 0x18(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x48(%rsp), %rdi
callq 0x20c0
movq %r12, %rdi
callq 0x2130
movl %r14d, 0x8(%rsp)
movl 0x10(%rsp), %r14d
jmp 0x4f44
leaq 0xa8(%rsp), %rdi
callq 0x2070
movq (%rbx), %rsi
movq 0x8(%rbx), %r9
subq %rsi, %r9
sarq $0x2, %r9
movl %r14d, %r8d
movl 0xc(%rsp), %edx
imull %edx, %r8d
movl 0x8(%rsp), %ecx
imull %ecx, %r8d
movslq %r8d, %rax
cmpq %rax, %r9
jne 0x5152
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x539a
movq (%rbx), %rsi
leaq 0x1c(%rsp), %rdx
movq %rbx, %rdi
callq 0x539a
movq (%rbx), %rsi
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
callq 0x539a
leaq 0x68(%rsp), %rdi
callq 0x20c0
leaq 0x88(%rsp), %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
callq 0x2080
movq %rbx, %rax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fdf(%rip), %rdi      # 0x711b
movl %r14d, %esi
movl 0x14(%rsp), %ecx
xorl %eax, %eax
callq 0x2040
pushq $0x1
popq %rdi
callq 0x21e0
leaq 0x201c(%rip), %rdi      # 0x7175
movl %edx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2040
jmp 0x514a
jmp 0x5176
jmp 0x5176
jmp 0x5176
jmp 0x5176
movq %rax, %r14
jmp 0x51ad
jmp 0x5176
movq %rax, %r14
jmp 0x51a3
jmp 0x517f
jmp 0x517f
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x48(%rsp), %rdi
callq 0x20c0
leaq 0x2b0(%rsp), %rdi
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x5466
leaq 0x88(%rsp), %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x22a0