// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
leaq -0x48(%rbp), %r14
movq %r14, -0x10(%r14)
xorl %eax, %eax
movq %rax, -0x8(%r14)
movb $0x0, (%r14)
movl $0x0, 0x10(%r14)
movq %rax, 0x18(%r14)
movq 0x2a94(%rip), %rbx      # 0x3fd8
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x1313
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x20(%rbx,%rax)
je 0x15ae
movq 0x2a8b(%rip), %rbx      # 0x3ff0
leaq 0xa9a(%rip), %rsi       # 0x2006
movl $0x9, %edx
movq %rbx, %rdi
callq 0x10e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2a59(%rip), %rdi      # 0x3ff0
callq 0x1030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x1070
jmp 0x1786
leaq -0x78(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movl $0x0, 0x10(%rcx)
movq %rax, 0x18(%rcx)
leaq -0x98(%rbp), %r12
leaq -0xb8(%rbp), %r15
movq 0x29e9(%rip), %r13      # 0x3fc8
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
callq 0x1313
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x20(%rbx,%rax)
jne 0x1726
movq %r12, -0xa8(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x1818
movq %r15, -0xc8(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x1818
movq -0xa0(%rbp), %rdx
cmpq -0xc0(%rbp), %rdx
jne 0x166f
testq %rdx, %rdx
je 0x1674
movq -0xc8(%rbp), %rsi
movq -0xa8(%rbp), %rdi
callq 0x10d0
testl %eax, %eax
sete %r14b
jmp 0x1677
xorl %r14d, %r14d
jmp 0x1677
movb $0x1, %r14b
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0x1692
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x16ad
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10c0
testb %r14b, %r14b
je 0x16cc
movl -0x68(%rbp), %eax
addl %eax, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15df
movq %r13, %rdi
leaq -0x58(%rbp), %rsi
callq 0x13e1
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x58(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1040
leaq -0x78(%rbp), %rax
movupd 0x10(%rax), %xmm0
leaq -0x38(%rbp), %rax
movupd %xmm0, (%rax)
jmp 0x15df
movq 0x289b(%rip), %rbx      # 0x3fc8
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x13e1
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2871(%rip), %rdi      # 0x3fc8
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
leaq -0x48(%rbp), %r14
je 0x1784
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10c0
xorl %ebx, %ebx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x179b
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x10c0
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17d8
movq %rax, %rbx
jmp 0x17f7
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r12, %rdi
je 0x17db
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10c0
jmp 0x17db
jmp 0x17d8
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x17f7
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1810
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1140