// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/absInt.cc
// Function: main
int main() {
	vector<int> vi;
	int i;
	while (cin >> i)
		vi.push_back(i);
	// pass a lambda to for_each to print each element in vi
	for_each(vi.begin(), vi.end(), [](int i) { cout << i << " "; });
	cout << endl;

	vector<int> orig = vi; // save original data in vi

	// replace negative values by their absolute value
	transform(vi.begin(), vi.end(), vi.begin(),
	          [](int i) { return i < 0 ? -i : i; });
	// print the elements now in vi
	for_each(vi.begin(), vi.end(), [](int i) { cout << i << " "; });
	cout << endl;

	vi = orig;  // start afresh
	// use a lambda with a specified return type to transform vi
	transform(vi.begin(), vi.end(), vi.begin(),
	          [](int i) -> int 
	          { if (i < 0) return -i; else return i; });
	// print the elements now in vi
	for_each(vi.begin(), vi.end(), [](int i) { cout << i << " "; });
	cout << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq 0x2d4a(%rip), %r14      # 0x3fe0
leaq -0x44(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x12d9
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x12cc
movl -0x44(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x129a
movq %rbx, %rdi
movq %r15, %rdx
callq 0x1658
jmp 0x129a
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
cmpq %r12, %r15
je 0x1318
movq 0x2ce3(%rip), %rbx      # 0x3fd0
leaq 0xd2a(%rip), %r14       # 0x201e
movl (%r15), %esi
movq %rbx, %rdi
callq 0x1100
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x10d0
addq $0x4, %r15
cmpq %r12, %r15
jne 0x12f4
movq 0x2cb1(%rip), %rdi      # 0x3fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2c96(%rip), %rbx      # 0x3fd0
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x14ea
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
cmpq %r13, %r12
je 0x13ae
movq %r12, %rax
movl (%rax), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %edx, (%rax)
addq $0x4, %rax
cmpq %r13, %rax
jne 0x1367
movq 0x2c4e(%rip), %r14      # 0x3fd0
leaq 0xc95(%rip), %r15       # 0x201e
movl (%r12), %esi
movq %r14, %rdi
callq 0x1100
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x1389
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2c04(%rip), %rbx      # 0x3fd0
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x156a
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
cmpq %r13, %r12
je 0x1440
movq %r12, %rax
movl (%rax), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %edx, (%rax)
addq $0x4, %rax
cmpq %r13, %rax
jne 0x13f9
movq 0x2bbc(%rip), %r14      # 0x3fd0
leaq 0xc03(%rip), %r15       # 0x201e
movl (%r12), %esi
movq %r14, %rdi
callq 0x1100
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x10d0
addq $0x4, %r12
cmpq %r13, %r12
jne 0x141b
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2b72(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1480
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1495
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14ca
jmp 0x14ca
jmp 0x14ae
jmp 0x14ae
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x14cd
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
jmp 0x14cd
jmp 0x14ca
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x14e2
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1110