// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH03_StringsVectorsAndArrays/examples/cctype.cc
// Function: main
int main()
{
	string s("Hello World!!!");
	// punct_cnt has the same type that s.size returns
	decltype(s.size()) punct_cnt = 0; 
	
	// count the number of punctuation characters in s
	for (auto c : s)         // for every char in s
		if (ispunct(c))      // if the character is punctuation
			++punct_cnt;     // increment the punctuation counter
	
	cout << punct_cnt 
	     << " punctuation characters in " << s << endl;
	
	// convert s to uppercase
	string orig = s;
	for (auto &c : s)   // for every char in s (note: c is a reference)
		// c is a reference, so this assignment changes the char in s
		c = toupper(c);
	cout << s << endl;
	
	// convert first word in s to uppercase
	s = orig;  // restore s to original case
	decltype(s.size()) index = 0;

	// process characters in s until we run out of characters 
	// or we hit a whitespace
	while (index != s.size() && !isspace(s[index])) {

	    // s[index] returns a reference so we can change 
		// the underlying character
		s[index] = toupper(s[index]);

		// increment the index to look at the next character 
		// on the next iteration
		++index; 
	}
	cout << s << endl;
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xd78(%rip), %rsi       # 0x2004
leaq 0xd7f(%rip), %rdx       # 0x2012
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x1576
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x12cc
movq -0x48(%rbp), %r15
xorl %r12d, %r12d
xorl %ebx, %ebx
movsbl (%r15,%r12), %edi
callq 0x1120
cmpl $0x1, %eax
sbbq $-0x1, %rbx
incq %r12
cmpq %r12, %r14
jne 0x12b1
jmp 0x12ce
xorl %ebx, %ebx
movq 0x2d03(%rip), %rdi      # 0x3fd8
movq %rbx, %rsi
callq 0x1060
movq %rax, %rbx
leaq 0xd2c(%rip), %rsi       # 0x2013
movl $0x1b, %edx
movq %rax, %rdi
callq 0x10d0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x10d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x14dc
movq -0x40(%rbp), %rbx
testq %rbx, %rbx
je 0x1370
movq -0x48(%rbp), %r14
xorl %r15d, %r15d
movsbl (%r14,%r15), %edi
callq 0x1110
movb %al, (%r14,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x135a
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x2c59(%rip), %rdi      # 0x3fd8
callq 0x10d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x1050
movq -0x40(%rbp), %rbx
testq %rbx, %rbx
je 0x1416
movq -0x48(%rbp), %r13
movsbl (%r13), %r14d
movl %r14d, %edi
callq 0x1040
testl %eax, %eax
jne 0x1416
movl $0x1, %r15d
xorl %r12d, %r12d
movl %r14d, %edi
callq 0x1110
movb %al, (%r13)
movq -0x40(%rbp), %rbx
cmpq %rbx, %r15
je 0x1416
incq %r12
movq -0x48(%rbp), %r13
movsbl (%r13,%r15), %r14d
addq %r12, %r13
movl %r14d, %edi
callq 0x1040
incq %r15
testl %eax, %eax
je 0x13e2
movq -0x48(%rbp), %rsi
movq 0x2bb7(%rip), %rdi      # 0x3fd8
movq %rbx, %rdx
callq 0x10d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
leaq -0x38(%rbp), %rbx
je 0x1470
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10c0
movq -0x48(%rbp), %rdi
cmpq %rbx, %rdi
je 0x1485
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10c0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14b8
jmp 0x149a
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x14bb
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10c0
jmp 0x14bb
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x14d4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x10f0