// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/avg_price.cc
// Function: main
int main() 
{
	// iterators that can read and write Sales_items
	istream_iterator<Sales_item> item_iter(cin), eof;
	ostream_iterator<Sales_item> out_iter(cout, "\n");

	// store the first transaction in sum and read the next record
	Sales_item sum = *item_iter++; 

	while (item_iter != eof) {
		// if the current transaction (which is in item_iter) 
		// has the same ISBN
	    if (item_iter->isbn() == sum.isbn())
	        sum += *item_iter++; // add it to sum 
		                         // and read the next transaction
	    else {
	        out_iter = sum;      // write the current sum
	        sum = *item_iter++;  // read the next transaction
	    }
	}
	out_iter = sum;  // remember to print the last set of records

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq 0x2ae6(%rip), %rsi      # 0x3fe0
leaq -0x108(%rbp), %rbx
movq %rbx, %rdi
callq 0x1868
leaq -0x138(%rbp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, -0x18(%r14)
movapd %xmm0, 0x8(%r14)
movapd %xmm0, -0x8(%r14)
movq %r14, -0x10(%r14)
movq $0x0, 0x18(%r14)
movb $0x0, 0x20(%r14)
movq 0x2a92(%rip), %rax      # 0x3fd0
movq %rax, -0xa8(%rbp)
leaq 0xaba(%rip), %rax       # 0x2006
movq %rax, -0xa0(%rbp)
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x18c8
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x1988
leaq -0x50(%rbp), %rax
movupd 0x10(%rax), %xmm0
movupd %xmm0, -0x78(%rbp)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15a6
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0x58(%rbp), %r15
leaq -0xb8(%rbp), %r12
leaq -0x68(%rbp), %r14
movb -0xd0(%rbp), %al
cmpb -0x118(%rbp), %al
jne 0x15df
testb %al, %al
je 0x1715
movq -0x108(%rbp), %rax
cmpq -0x150(%rbp), %rax
je 0x1715
movq %r15, -0x68(%rbp)
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x1988
movq %r12, -0xc8(%rbp)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x1988
movq -0x60(%rbp), %rdx
cmpq -0xc0(%rbp), %rdx
jne 0x164c
movq -0xc8(%rbp), %r13
testq %rdx, %rdx
je 0x1657
movq -0x68(%rbp), %rdi
movq %r13, %rsi
callq 0x10b0
testl %eax, %eax
sete %bl
jmp 0x1659
movq -0xc8(%rbp), %r13
xorl %ebx, %ebx
jmp 0x1659
movb $0x1, %bl
cmpq %r12, %r13
je 0x1670
movq -0xb8(%rbp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x10a0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x1685
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
testb %bl, %bl
je 0x16b1
movq %r14, %rdi
leaq -0x108(%rbp), %rsi
xorl %edx, %edx
callq 0x18c8
movl -0x40(%rbp), %eax
addl %eax, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x16f3
leaq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1942
movq %r14, %rdi
leaq -0x108(%rbp), %rsi
xorl %edx, %edx
callq 0x18c8
leaq -0x98(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1040
movupd 0x18(%r15), %xmm0
leaq -0x78(%rbp), %rax
movupd %xmm0, (%rax)
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x15b5
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x15b5
leaq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1942
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
leaq -0x138(%rbp), %rbx
je 0x1751
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x148(%rbp), %rdi
cmpq %rbx, %rdi
je 0x176c
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x178b
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x10a0
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17e0
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1826
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x1826
movq %rax, %rbx
jmp 0x1826
jmp 0x17e0
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x17fd
movq -0x50(%rbp), %rsi
jmp 0x17f5
jmp 0x17e0
jmp 0x17e0
movq %rax, %rbx
jmp 0x17fd
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x17fd
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x181f
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0x138(%rbp), %r14
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x1841
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1860
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x10a0
movq %rbx, %rdi
callq 0x1120