// File: 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
movq %rsp, %rbp
subq $0x530, %rsp            # imm = 0x530
movq %rsi, -0x4b8(%rbp)
movq %rdi, -0x4c0(%rbp)
movq %rdi, %rax
movq %rax, -0x4c8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x218(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x2290
leaq -0x238(%rbp), %rdi
callq 0x22f0
movq -0x4c0(%rbp), %rdi
movb $0x0, -0x239(%rbp)
callq 0x8d20
movq -0x4b8(%rbp), %rdi
callq 0x20e0
movq -0x4b0(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x2140
jmp 0x811f
leaq -0x288(%rbp), %rdi
callq 0x22f0
movl $0x0, -0x250(%rbp)
movl $0x0, -0x254(%rbp)
movl $0x0, -0x260(%rbp)
movl $0x0, -0x268(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2070
movq %rax, -0x4d0(%rbp)
jmp 0x816f
movq -0x4d0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x22d0
movb %al, -0x4d1(%rbp)
jmp 0x818d
movb -0x4d1(%rbp), %al
testb $0x1, %al
jne 0x819c
jmp 0x8451
movl -0x268(%rbp), %eax
incl %eax
movl %eax, -0x268(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x9960
movl %eax, -0x4d8(%rbp)
jmp 0x81c1
movl -0x4d8(%rbp), %edx
leaq -0x410(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2330
jmp 0x81dc
leaq -0x430(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x22f0
leaq -0x450(%rbp), %rdi
callq 0x22f0
movq -0x4e0(%rbp), %rsi
leaq -0x410(%rbp), %rdi
movl $0x9, %edx
callq 0x23b0
jmp 0x8215
leaq -0x410(%rbp), %rdi
leaq -0x450(%rbp), %rsi
movl $0x9, %edx
callq 0x23b0
jmp 0x822f
leaq -0x430(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2320
movl %eax, -0x258(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2320
movl %eax, -0x25c(%rbp)
movl -0x258(%rbp), %eax
incl %eax
movl %eax, -0x454(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x454(%rbp), %rsi
callq 0x9980
movq %rax, -0x4e8(%rbp)
jmp 0x828d
movq -0x4e8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x250(%rbp)
movl -0x25c(%rbp), %eax
incl %eax
movl %eax, -0x458(%rbp)
leaq -0x254(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x9980
movq %rax, -0x4f0(%rbp)
jmp 0x82c6
movq -0x4f0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x254(%rbp)
movl $0x0, -0x264(%rbp)
leaq -0x410(%rbp), %rdi
leaq -0x288(%rbp), %rsi
movl $0x9, %edx
callq 0x23b0
movq %rax, -0x4f8(%rbp)
jmp 0x8300
movq -0x4f8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x22d0
movb %al, -0x4f9(%rbp)
jmp 0x831e
movb -0x4f9(%rbp), %al
testb $0x1, %al
jne 0x832d
jmp 0x83d9
leaq -0x288(%rbp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2320
movq -0x4c0(%rbp), %rdi
movl %eax, -0x45c(%rbp)
leaq -0x45c(%rbp), %rsi
callq 0x8d40
jmp 0x835c
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x82df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x865e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x861c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x2130
leaq -0x430(%rbp), %rdi
callq 0x2130
leaq -0x410(%rbp), %rdi
callq 0x2190
jmp 0x861c
cmpl $0x0, -0x260(%rbp)
jle 0x841c
movl -0x260(%rbp), %eax
cmpl -0x264(%rbp), %eax
je 0x841c
movl -0x264(%rbp), %esi
movl -0x260(%rbp), %edx
movl -0x268(%rbp), %ecx
leaq 0x7f79(%rip), %rdi      # 0x10382
xorl %eax, %eax
callq 0x2040
jmp 0x8412
movl $0x1, %edi
callq 0x22b0
movl -0x264(%rbp), %eax
movl %eax, -0x260(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x2130
leaq -0x430(%rbp), %rdi
callq 0x2130
leaq -0x410(%rbp), %rdi
callq 0x2190
jmp 0x8153
leaq -0x218(%rbp), %rdi
callq 0x2080
jmp 0x845f
movq -0x4c0(%rbp), %rdi
callq 0x90a0
movl -0x250(%rbp), %ecx
imull -0x254(%rbp), %ecx
imull -0x260(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x84f9
movq -0x4c0(%rbp), %rdi
movl -0x250(%rbp), %eax
movl %eax, -0x50c(%rbp)
movl -0x254(%rbp), %edx
movl %edx, -0x508(%rbp)
movl -0x260(%rbp), %ecx
movl %ecx, -0x504(%rbp)
imull %edx, %eax
imull %ecx, %eax
movl %eax, -0x500(%rbp)
callq 0x90a0
movl -0x50c(%rbp), %esi
movl -0x508(%rbp), %edx
movl -0x504(%rbp), %ecx
movl -0x500(%rbp), %r8d
movq %rax, %r9
leaq 0x7ef6(%rip), %rdi      # 0x103dc
xorl %eax, %eax
callq 0x2040
jmp 0x84ef
movl $0x1, %edi
callq 0x22b0
movq -0x4c0(%rbp), %rdi
callq 0x8dd0
movq %rax, -0x470(%rbp)
leaq -0x468(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x9bc0
movq -0x4c0(%rbp), %rdi
movq -0x468(%rbp), %rsi
leaq -0x260(%rbp), %rdx
callq 0x99c0
movq %rax, -0x518(%rbp)
jmp 0x8542
movq -0x4c0(%rbp), %rdi
movq -0x518(%rbp), %rax
movq %rax, -0x478(%rbp)
callq 0x8dd0
movq %rax, -0x488(%rbp)
leaq -0x480(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x9bc0
movq -0x4c0(%rbp), %rdi
movq -0x480(%rbp), %rsi
leaq -0x254(%rbp), %rdx
callq 0x99c0
movq %rax, -0x520(%rbp)
jmp 0x8599
movq -0x4c0(%rbp), %rdi
movq -0x520(%rbp), %rax
movq %rax, -0x490(%rbp)
callq 0x8dd0
movq %rax, -0x4a0(%rbp)
leaq -0x498(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0x9bc0
movq -0x4c0(%rbp), %rdi
movq -0x498(%rbp), %rsi
leaq -0x250(%rbp), %rdx
callq 0x99c0
movq %rax, -0x528(%rbp)
jmp 0x85f0
movq -0x528(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movb $0x1, -0x239(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x2130
testb $0x1, -0x239(%rbp)
jne 0x8636
jmp 0x862a
leaq -0x288(%rbp), %rdi
callq 0x2130
jmp 0x865e
movq -0x4c0(%rbp), %rdi
callq 0x8f20
leaq -0x238(%rbp), %rdi
callq 0x2130
leaq -0x218(%rbp), %rdi
callq 0x2090
movq -0x4c8(%rbp), %rax
addq $0x530, %rsp            # imm = 0x530
popq %rbp
retq
movq -0x4c0(%rbp), %rdi
callq 0x8f20
leaq -0x238(%rbp), %rdi
callq 0x2130
leaq -0x218(%rbp), %rdi
callq 0x2090
movq -0x248(%rbp), %rdi
callq 0x2380
nop