// File: /workspace/github_cpp_makefile_star2_O1/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 0x1654
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 0x14f4
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
cmpq %r13, %r12
je 0x13b3
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
cmpq %r13, %r12
je 0x13b3
movq 0x2c49(%rip), %r14      # 0x3fd0
leaq 0xc90(%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 0x138e
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2bff(%rip), %rbx      # 0x3fd0
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1574
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
cmpq %r13, %r12
je 0x144a
movq %r12, %rax
movl (%rax), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
movl %edx, (%rax)
addq $0x4, %rax
cmpq %r13, %rax
jne 0x13fe
cmpq %r13, %r12
je 0x144a
movq 0x2bb2(%rip), %r14      # 0x3fd0
leaq 0xbf9(%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 0x1425
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq 0x2b68(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x148a
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x149f
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 0x14d4
jmp 0x14d4
jmp 0x14b8
jmp 0x14b8
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x14d7
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
jmp 0x14d7
jmp 0x14d4
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x14ec
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x1110