// File: /workspace/github_cpp_makefile_star2_O1/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 0x169c
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 0x1633
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 0x145c
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 0x17dc
addq $0x4, %r12
cmpq %r13, %r12
jne 0x1424
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rcx
subq %rsi, %rcx
cmpq %rcx, %rdx
jne 0x1490
cmpq %rdi, %rax
je 0x1518
callq 0x10e0
testl %eax, %eax
je 0x1518
movq 0x2b39(%rip), %r14      # 0x3fd0
leaq 0xb74(%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 0x2b07(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq -0x80(%rbp), %r12
movq -0x78(%rbp), %r13
cmpq %r13, %r12
je 0x155e
movq 0x2ae6(%rip), %r14      # 0x3fd0
leaq 0xb13(%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 0x14f1
jmp 0x155e
movq 0x2ab1(%rip), %r14      # 0x3fd0
leaq 0xae0(%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 0x2a7f(%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 0x2a54(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1080
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x159e
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x15b3
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x15c8
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 0x15f9
jmp 0x15df
jmp 0x15df
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x15fc
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x15fc
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x1616
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x1616
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x162b
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1130