// File: /workspace/github_cpp_makefile_star2_O3/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 0x2aa0(%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 0x15a2
movq 0x2a97(%rip), %rbx      # 0x3ff0
leaq 0xaa6(%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 0x2a65(%rip), %rdi      # 0x3ff0
callq 0x1030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x1070
jmp 0x1787
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), %r14
movq 0x29fc(%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 0x1727
movq %r14, -0xa8(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x181a
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x181a
movq -0xa0(%rbp), %rdx
cmpq -0xc0(%rbp), %rdx
jne 0x1666
movq -0xc8(%rbp), %r12
testq %rdx, %rdx
je 0x1672
movq -0xa8(%rbp), %rdi
movq %r12, %rsi
callq 0x10d0
testl %eax, %eax
sete %r15b
jmp 0x1675
movq -0xc8(%rbp), %r12
xorl %r15d, %r15d
jmp 0x1675
movb $0x1, %r15b
leaq -0xb8(%rbp), %rax
cmpq %rax, %r12
je 0x1693
movq -0xb8(%rbp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x10c0
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x16ae
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10c0
testb %r15b, %r15b
je 0x16cd
movl -0x68(%rbp), %eax
addl %eax, -0x38(%rbp)
movsd -0x60(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15cc
movq %r13, %rdi
leaq -0x58(%rbp), %rsi
callq 0x13d5
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 0x15cc
movq 0x289a(%rip), %rbx      # 0x3fc8
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x13d5
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2870(%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 0x1785
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10c0
xorl %ebx, %ebx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x179c
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 0x17d9
movq %rax, %rbx
jmp 0x17f8
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x17dc
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10c0
jmp 0x17dc
jmp 0x17d9
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x17f8
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1811
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1140
nop