// File: 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
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x1130
movq -0xb8(%rbp), %rdx
leaq 0xd24(%rip), %rsi       # 0x2004
leaq -0x28(%rbp), %rdi
callq 0x1100
jmp 0x12eb
leaq -0x29(%rbp), %rdi
callq 0x10f0
movq $0x0, -0x48(%rbp)
leaq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x10a0
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1070
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1640
testb $0x1, %al
jne 0x1331
jmp 0x1382
leaq -0x58(%rbp), %rdi
callq 0x1680
movb (%rax), %al
movb %al, -0x61(%rbp)
movsbl -0x61(%rbp), %edi
callq 0x1150
cmpl $0x0, %eax
je 0x1375
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x10f0
jmp 0x1631
jmp 0x1377
leaq -0x58(%rbp), %rdi
callq 0x16a0
jmp 0x131e
movq -0x48(%rbp), %rsi
movq 0x2c4b(%rip), %rdi      # 0x3fd8
callq 0x1050
movq %rax, -0xc0(%rbp)
jmp 0x139b
movq -0xc0(%rbp), %rdi
leaq 0xc6a(%rip), %rsi       # 0x2013
callq 0x10d0
movq %rax, -0xc8(%rbp)
jmp 0x13b7
movq -0xc8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x10c0
movq %rax, -0xd0(%rbp)
jmp 0x13d0
movq -0xd0(%rbp), %rdi
movq 0x2bea(%rip), %rsi      # 0x3fc8
callq 0x10e0
jmp 0x13e5
leaq -0x88(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1060
jmp 0x13f7
leaq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x10a0
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
callq 0x1070
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1640
testb $0x1, %al
jne 0x1441
jmp 0x148d
leaq -0x98(%rbp), %rdi
callq 0x1680
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movsbl (%rax), %edi
callq 0x1140
movb %al, %cl
movq -0xa8(%rbp), %rax
movb %cl, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x16a0
jmp 0x1428
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1628
movq 0x2b44(%rip), %rdi      # 0x3fd8
leaq -0x28(%rbp), %rsi
callq 0x10c0
movq %rax, -0xd8(%rbp)
jmp 0x14a6
movq -0xd8(%rbp), %rdi
movq 0x2b14(%rip), %rsi      # 0x3fc8
callq 0x10e0
jmp 0x14bb
leaq -0x28(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1030
jmp 0x14cd
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1090
movq -0xe8(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0xd9(%rbp)
je 0x153c
movq -0xb0(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1160
movq %rax, -0xf0(%rbp)
jmp 0x151f
movq -0xf0(%rbp), %rax
movsbl (%rax), %edi
callq 0x1040
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x154b
jmp 0x15d2
movq -0xb0(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1160
movq %rax, -0xf8(%rbp)
jmp 0x1564
movq -0xf8(%rbp), %rax
movsbl (%rax), %edi
callq 0x1140
movb %al, -0x101(%rbp)
movq -0xb0(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x1160
movq %rax, -0x100(%rbp)
jmp 0x1592
movq -0x100(%rbp), %rax
movb -0x101(%rbp), %cl
movb %cl, (%rax)
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x14d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x1080
jmp 0x1628
movq 0x29ff(%rip), %rdi      # 0x3fd8
leaq -0x28(%rbp), %rsi
callq 0x10c0
movq %rax, -0x110(%rbp)
jmp 0x15eb
movq -0x110(%rbp), %rdi
movq 0x29cf(%rip), %rsi      # 0x3fc8
callq 0x10e0
jmp 0x1600
movl $0x0, -0x4(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x1080
leaq -0x28(%rbp), %rdi
callq 0x1080
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x1080
movq -0x38(%rbp), %rdi
callq 0x1120
nopw (%rax,%rax)