// File: 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
subq $0x210, %rsp            # imm = 0x210
movl $0x0, -0x4(%rbp)
movq 0x2a37(%rip), %rsi      # 0x3fe0
leaq -0x48(%rbp), %rdi
callq 0x19d0
leaq -0x88(%rbp), %rdi
callq 0x1a30
jmp 0x15c0
movq 0x2a09(%rip), %rsi      # 0x3fd0
leaq 0xa38(%rip), %rdx       # 0x2006
leaq -0xa8(%rbp), %rdi
callq 0x1a80
jmp 0x15dc
leaq -0x118(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x1ab0
jmp 0x15f0
leaq -0x118(%rbp), %rdi
callq 0x1b30
movq %rax, -0x1e0(%rbp)
jmp 0x1605
movq -0x1e0(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x18c0
jmp 0x161a
leaq -0x118(%rbp), %rdi
callq 0x1b50
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1b70
movb %al, -0x1e1(%rbp)
jmp 0x163e
movb -0x1e1(%rbp), %al
testb $0x1, %al
jne 0x164d
jmp 0x184a
leaq -0x48(%rbp), %rdi
callq 0x1c30
movq %rax, -0x1f0(%rbp)
jmp 0x165f
movq -0x1f0(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x19a0
jmp 0x1674
leaq -0x158(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x19a0
jmp 0x1689
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x1ba0
movb %al, -0x1f1(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x10b0
leaq -0x138(%rbp), %rdi
callq 0x10b0
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x16c9
jmp 0x17c4
leaq -0x198(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x1ab0
jmp 0x16dd
leaq -0x198(%rbp), %rdi
callq 0x1b30
movq %rax, -0x200(%rbp)
jmp 0x16f2
movq -0x200(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x12e0
leaq -0x198(%rbp), %rdi
callq 0x1b50
jmp 0x1845
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x18ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x189f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x1b50
jmp 0x189f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x1893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x10b0
jmp 0x1893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x1b50
jmp 0x1893
leaq -0xa8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x1c50
jmp 0x17d9
leaq -0x1d8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x1ab0
jmp 0x17ed
leaq -0x1d8(%rbp), %rdi
callq 0x1b30
movq %rax, -0x208(%rbp)
jmp 0x1802
movq -0x208(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1ca0
jmp 0x1817
leaq -0x1d8(%rbp), %rdi
callq 0x1b50
jmp 0x1845
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x1b50
jmp 0x1893
jmp 0x1626
leaq -0xa8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x1c50
jmp 0x185f
movl $0x0, -0x4(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x1900
leaq -0x88(%rbp), %rdi
callq 0x1b50
leaq -0x48(%rbp), %rdi
callq 0x1b50
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0x1900
leaq -0x88(%rbp), %rdi
callq 0x1b50
leaq -0x48(%rbp), %rdi
callq 0x1b50
movq -0x90(%rbp), %rdi
callq 0x1180