// File: iZhangHui[P]CppPrimer/CH01_GettingStarted/examples/avg_price.cc
// Function: main
int main()
{
    Sales_item total; // variable to hold data for the next transaction

    // read the first transaction and ensure that there are data to process
    if (std::cin >> total) {
        Sales_item trans; // variable to hold the running sum
        // read and process the remaining transactions
        while (std::cin >> trans) {
            // if we're still processing the same book
            if (total.isbn() == trans.isbn()) {
                total += trans; // update the running total

            } else {
                // print results for the previous book
                std::cout << total << std::endl;
                total = trans;  // total now refers to the next book
            }
        }
        std::cout << total << std::endl; // print the last transaction

    } else {
        // no input! warn the user
        std::cerr << "No data?!" << std::endl;
        return -1;  // indicate failure
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x2860
movq -0xd0(%rbp), %rsi
movq 0x2a18(%rip), %rdi      # 0x4fd8
callq 0x2380
movq %rax, -0xc8(%rbp)
jmp 0x25ce
movq -0xc8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2120
movb %al, -0xd1(%rbp)
jmp 0x25ec
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x25fb
jmp 0x277e
leaq -0x78(%rbp), %rdi
callq 0x2860
movq 0x29cd(%rip), %rdi      # 0x4fd8
leaq -0x78(%rbp), %rsi
callq 0x2380
movq %rax, -0xe0(%rbp)
jmp 0x261d
movq -0xe0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2120
movb %al, -0xe1(%rbp)
jmp 0x263b
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x264a
jmp 0x273a
leaq -0x98(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x28e0
jmp 0x265c
leaq -0xb8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x28e0
jmp 0x266e
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x2910
movb %al, -0xe2(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x20a0
leaq -0x98(%rbp), %rdi
callq 0x20a0
movb -0xe2(%rbp), %al
testb $0x1, %al
jne 0x26ab
jmp 0x26f6
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x22e0
jmp 0x2735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x27e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2773
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x20a0
jmp 0x2773
movq 0x28cb(%rip), %rdi      # 0x4fc8
leaq -0x38(%rbp), %rsi
callq 0x2430
movq %rax, -0xf0(%rbp)
jmp 0x270f
movq -0xf0(%rbp), %rdi
movq 0x289b(%rip), %rsi      # 0x4fb8
callq 0x2100
jmp 0x2724
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x29a0
jmp 0x2733
jmp 0x2735
jmp 0x2604
movq 0x2887(%rip), %rdi      # 0x4fc8
leaq -0x38(%rbp), %rsi
callq 0x2430
movq %rax, -0xf8(%rbp)
jmp 0x2753
movq -0xf8(%rbp), %rdi
movq 0x2857(%rip), %rsi      # 0x4fb8
callq 0x2100
jmp 0x2768
leaq -0x78(%rbp), %rdi
callq 0x2840
jmp 0x27c2
leaq -0x78(%rbp), %rdi
callq 0x2840
jmp 0x27e8
movq 0x286b(%rip), %rdi      # 0x4ff0
leaq 0x87a(%rip), %rsi       # 0x3006
callq 0x20f0
movq %rax, -0x100(%rbp)
jmp 0x279a
movq -0x100(%rbp), %rdi
movq 0x2810(%rip), %rsi      # 0x4fb8
callq 0x2100
jmp 0x27af
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xbc(%rbp)
jmp 0x27d3
movl $0x0, -0x4(%rbp)
movl $0x1, -0xbc(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2840
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x2840
movq -0x40(%rbp), %rdi
callq 0x2180
nopw (%rax,%rax)