// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH14_OverloadedOperationsAndConversions/examples/absInt.cc
// Function: main
int main()
{
    int i = -42;
    absInt absObj;           // object that has a function-call operator
    unsigned ui = absObj(i); // passes i to absObj.operator()
    cout << i << " " << ui << endl;

	// store collection of positive and negative integers in vi
	vector<int> vi;
	while (cin >> i)
		vi.push_back(i);

	// call absInt to store the absolute value of those ints in vu
	vector<unsigned> vu;
	transform(vi.begin(), vi.end(), back_inserter(vu), absInt());

	// print contents of vu using a lambda
	for_each(vu.begin(), vu.end(), [](unsigned i) { cout << i << " "; });
	cout << endl;

	vector<unsigned> vu2;
	// similar transformation but using a lambda
	transform(vi.begin(), vi.end(), back_inserter(vu2),
	          [](int i) { return i < 0 ? -i : i; });
	if (vu == vu2)
		cout << "as expected" << endl;
	else {
		cout << "something's wrong, vectors differ" << endl;
		for_each(vu.begin(), vu.end(), [](unsigned i) { cout << i << " "; });
	}
	cout << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq -0x64(%rbp), %r14
movl $0xffffffd6, (%r14)     # imm = 0xFFFFFFD6
movq 0x2d11(%rip), %rbx      # 0x3fd0
movq %rbx, %rdi
movl $0xffffffd6, %esi       # imm = 0xFFFFFFD6
callq 0x1120
movq %rax, %r15
leaq 0xd2e(%rip), %rsi       # 0x2004
movl $0x1, %edx
movq %rax, %rdi
callq 0x10f0
movl $0x2a, %esi
movq %r15, %rdi
callq 0x1070
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq 0x2cac(%rip), %r12      # 0x3fe0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1373
movq -0x58(%rbp), %rsi
cmpq -0x50(%rbp), %rsi
je 0x1366
movl -0x64(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x58(%rbp)
jmp 0x1334
movq %r15, %rdi
movq %r14, %rdx
callq 0x16a2
jmp 0x1334
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1639
movq -0x80(%rbp), %r12
movq -0x78(%rbp), %r13
cmpq %r13, %r12
je 0x13d2
movq 0x2c2a(%rip), %r14      # 0x3fd0
leaq 0xc57(%rip), %r15       # 0x2004
movl (%r12), %esi
movq %r14, %rdi
callq 0x1070
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10f0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x13ad
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2be0(%rip), %rbx      # 0x3fd0
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %r13
cmpq %r13, %r12
je 0x1466
leaq -0x40(%rbp), %r14
leaq -0x68(%rbp), %r15
movl (%r12), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x1448
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x1453
movq %r14, %rdi
movq %r15, %rdx
callq 0x17e2
addq $0x4, %r12
cmpq %r13, %r12
jne 0x1424
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
jmp 0x146a
xorl %esi, %esi
xorl %eax, %eax
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rcx
movq %rcx, %rdx
subq %rdi, %rdx
subq %rsi, %rax
cmpq %rax, %rdx
jne 0x1496
cmpq %rdi, %rcx
je 0x151e
callq 0x10e0
testl %eax, %eax
je 0x151e
movq 0x2b33(%rip), %r14      # 0x3fd0
leaq 0xb6e(%rip), %rsi       # 0x2012
movl $0x21, %edx
movq %r14, %rdi
callq 0x10f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2b01(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq -0x80(%rbp), %r12
movq -0x78(%rbp), %r13
cmpq %r13, %r12
je 0x1564
movq 0x2ae0(%rip), %r14      # 0x3fd0
leaq 0xb0d(%rip), %r15       # 0x2004
movl (%r12), %esi
movq %r14, %rdi
callq 0x1070
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10f0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x14f7
jmp 0x1564
movq 0x2aab(%rip), %r14      # 0x3fd0
leaq 0xada(%rip), %rsi       # 0x2006
movl $0xb, %edx
movq %r14, %rdi
callq 0x10f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2a79(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq 0x2a4e(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x15a4
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x15b9
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x15ce
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15ff
jmp 0x15e5
jmp 0x15e5
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1602
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x1602
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x161c
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x161c
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1631
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1130