// File: /workspace/github_cpp_makefile_star2_O3/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), %rbp
movq %rbp, %rdi
callq 0x21d0
leaq 0x78(%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 %rbp, %rdi
movl $0x8, %edx
callq 0x2100
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %r15d, 0x1c(%rsp)
movl %r15d, 0x18(%rsp)
movl %r15d, 0x14(%rsp)
leaq 0x2b0(%rsp), %r14
leaq 0x88(%rsp), %r13
leaq 0x24(%rsp), %r15
movl $0x0, 0x8(%rsp)
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %edx
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq 0x22d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x609d
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movl $0x18, %edx
callq 0x2260
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movb %al, 0x58(%rsp)
leaq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movb %al, 0x38(%rsp)
movq %r14, %rdi
leaq 0x48(%rsp), %rsi
movl $0x9, %edx
callq 0x22d0
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movl $0x9, %edx
callq 0x22d0
incl 0x10(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2250
movl %eax, %ebp
movq 0x28(%rsp), %rdi
callq 0x2250
incl %ebp
movl 0xc(%rsp), %ecx
cmpl %ebp, %ecx
cmovlel %ebp, %ecx
movl %ecx, 0xc(%rsp)
movl %ecx, 0x1c(%rsp)
incl %eax
cmpl %eax, %r12d
cmovlel %eax, %r12d
movl %r12d, 0x20(%rsp)
movl %r12d, 0x18(%rsp)
xorl %ebp, %ebp
movl 0x8(%rsp), %r12d
movq %r14, %rdi
movq %r13, %rsi
movl $0x9, %edx
callq 0x22d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x601b
movq 0x88(%rsp), %rdi
callq 0x2250
movl %eax, 0x24(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x600c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x6017
movq %rbx, %rdi
movq %r15, %rdx
callq 0x652a
incl %ebp
jmp 0x5fc7
testl %r12d, %r12d
sete %al
cmpl %ebp, %r12d
sete %cl
orb %al, %cl
je 0x6167
movl %ebp, 0x14(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x604f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x606b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r14, %rdi
movq 0x4f4b(%rip), %rsi      # 0xafc0
callq 0x2140
leaq 0x330(%rsp), %rdi
callq 0x20a0
movl %ebp, 0x8(%rsp)
leaq 0xa8(%rsp), %rbp
movl 0x20(%rsp), %r12d
jmp 0x5ee7
leaq 0xa8(%rsp), %rdi
callq 0x2070
movq (%rbx), %rsi
movq 0x8(%rbx), %r9
subq %rsi, %r9
sarq $0x2, %r9
movl %r12d, %r8d
movl 0xc(%rsp), %edx
imull %edx, %r8d
movl 0x8(%rsp), %ecx
imull %ecx, %r8d
movslq %r8d, %rax
cmpq %rax, %r9
jne 0x6188
leaq 0x14(%rsp), %rdx
movq %rbx, %rdi
callq 0x6438
movq (%rbx), %rsi
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x6438
movq (%rbx), %rsi
leaq 0x1c(%rsp), %rdx
movq %rbx, %rdi
callq 0x6438
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x6129
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x6145
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21b0
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 0x1fcd(%rip), %rdi      # 0x813b
movl %ebp, %esi
movl %r12d, %edx
movl 0x10(%rsp), %ecx
xorl %eax, %eax
callq 0x2050
movl $0x1, %edi
callq 0x2200
leaq 0x2006(%rip), %rdi      # 0x8195
movl %edx, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2050
jmp 0x617e
jmp 0x61b1
jmp 0x61b1
jmp 0x61b1
jmp 0x61b1
movq %rax, %r14
jmp 0x624d
jmp 0x61b1
jmp 0x61b8
movq %rax, %r14
jmp 0x6214
jmp 0x61b8
movq %rax, %r14
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x61d7
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x61f3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x4dc6(%rip), %rsi      # 0xafc0
leaq 0x2b0(%rsp), %rdi
callq 0x2140
leaq 0x330(%rsp), %rdi
callq 0x20a0
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x6239
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x624d
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
leaq 0x78(%rsp), %rax
movq 0x68(%rsp), %rdi
cmpq %rax, %rdi
je 0x6269
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0xa8(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x22c0