// File: iZhangHui[P]CppPrimer/CH03_StringsVectorsAndArrays/examples/cstring_hdr.cc
// Function: main
int main() {
	string s1 = "A string example";
	string s2 = "A different string";
	
	if (s1 < s2)  // false: s2 is less than s1
		cout << s1 << endl;
	else
		cout << s2 << endl;
	const char ca1[] = "A string example";
	const char ca2[] = "A different string";
	
	if (strcmp(ca1, ca2) < 0) // same effect as string comparison s1 < s2
		cout << ca1 << endl;
	else
		cout << ca2 << endl;
	
	const char *cp1 = ca1, *cp2 = ca2;
	cout << strcmp(cp1, cp2) << endl; // output is positive
	cout << strcmp(cp2, cp1) << endl; // output is negative
	cout << strcmp(cp1, cp1) << endl; // output is zero
	
	
	cout << strlen(cp1) << endl; // prints 16; strlen ignores the null
	
	const unsigned sz = 16 + 18 + 2;
	char largeStr[sz];      // will hold the result
	// disastrous if we miscalculated the size of largeStr
	strcpy(largeStr, ca1);  // copies ca1 into largeStr
	strcat(largeStr, " ");  // adds a space at the end of largeStr
	strcat(largeStr, ca2);  // concatenates ca2 onto largeStr
	// prints A string example A different string
	cout << largeStr << endl;       
	
	strncpy(largeStr, ca1, sz); // size to copy includes the null
	if (strlen(ca1) > sz)
		largeStr[sz-1] = '\0';
	strncat(largeStr, " ", 2);  // pedantic, but a good habit
	strncat(largeStr, ca2, sz - strlen(largeStr)); 
	cout << largeStr << endl;       
	
	// initialize large_string as a concatenation of s1, a space, and s2
	string large_string = s1 + " " + s2; 
	cout << large_string << endl;       
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x1180
movq -0x128(%rbp), %rdx
leaq 0xcd4(%rip), %rsi       # 0x2004
leaq -0x28(%rbp), %rdi
callq 0x1130
jmp 0x133b
leaq -0x29(%rbp), %rdi
callq 0x1120
leaq -0x61(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x1180
movq -0x130(%rbp), %rdx
leaq 0xcb3(%rip), %rsi       # 0x2015
leaq -0x60(%rbp), %rdi
callq 0x1130
jmp 0x136d
leaq -0x61(%rbp), %rdi
callq 0x1120
leaq -0x28(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1790
testb $0x1, %al
jne 0x1389
jmp 0x13fe
movq 0x2c48(%rip), %rdi      # 0x3fd8
leaq -0x28(%rbp), %rsi
callq 0x10e0
movq %rax, -0x138(%rbp)
jmp 0x13a2
movq -0x138(%rbp), %rdi
movq 0x2c18(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x13b7
jmp 0x142e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x1120
jmp 0x1782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x1120
jmp 0x1779
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1770
movq 0x2bd3(%rip), %rdi      # 0x3fd8
leaq -0x60(%rbp), %rsi
callq 0x10e0
movq %rax, -0x140(%rbp)
jmp 0x1417
movq -0x140(%rbp), %rdi
movq 0x2ba3(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x142c
jmp 0x142e
movaps 0xbfb(%rip), %xmm0      # 0x2030
movaps %xmm0, -0x80(%rbp)
movb $0x0, -0x70(%rbp)
movaps 0xc0c(%rip), %xmm0      # 0x2050
movaps %xmm0, -0xa0(%rbp)
movl $0x676e69, -0x91(%rbp)  # imm = 0x676E69
movq 0x2b7c(%rip), %rdi      # 0x3fd8
leaq -0xa0(%rbp), %rsi
callq 0x1100
movq %rax, -0x148(%rbp)
jmp 0x1471
movq -0x148(%rbp), %rdi
movq 0x2b49(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x1486
leaq -0x80(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x1140
movl %eax, %esi
movq 0x2b1d(%rip), %rdi      # 0x3fd8
callq 0x1160
movq %rax, -0x150(%rbp)
jmp 0x14c9
movq -0x150(%rbp), %rdi
movq 0x2af1(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x14de
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x1140
movl %eax, %esi
movq 0x2ade(%rip), %rdi      # 0x3fd8
callq 0x1160
movq %rax, -0x158(%rbp)
jmp 0x1508
movq -0x158(%rbp), %rdi
movq 0x2ab2(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x151d
movq -0xa8(%rbp), %rsi
movq %rsi, %rdi
callq 0x1140
movl %eax, %esi
movq 0x2aa3(%rip), %rdi      # 0x3fd8
callq 0x1160
movq %rax, -0x160(%rbp)
jmp 0x1543
movq -0x160(%rbp), %rdi
movq 0x2a77(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x1558
movq -0xa8(%rbp), %rdi
callq 0x1080
movq %rax, %rsi
movq 0x2a6a(%rip), %rdi      # 0x3fd8
callq 0x1040
movq %rax, -0x168(%rbp)
jmp 0x157c
movq -0x168(%rbp), %rdi
movq 0x2a3e(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x1591
movl $0x24, -0xb4(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x178(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x10f0
movq -0x178(%rbp), %rdi
leaq 0xa68(%rip), %rsi       # 0x2028
callq 0x1190
movq -0x178(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1190
movq -0x178(%rbp), %rsi
movq 0x29f2(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, -0x170(%rbp)
jmp 0x15f4
movq -0x170(%rbp), %rdi
movq 0x29c6(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x1609
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x188(%rbp)
leaq -0x80(%rbp), %rsi
movl $0x24, %edx
movq %rdx, -0x190(%rbp)
callq 0x1090
movq -0x188(%rbp), %rdi
leaq 0x9ee(%rip), %rsi       # 0x2028
movl $0x2, %edx
callq 0x10c0
movq -0x188(%rbp), %rdi
callq 0x1080
movq -0x190(%rbp), %rdx
movq -0x188(%rbp), %rdi
subq %rax, %rdx
leaq -0xa0(%rbp), %rsi
callq 0x10c0
movq -0x188(%rbp), %rsi
movq 0x295d(%rip), %rdi      # 0x3fd8
callq 0x1100
movq %rax, -0x180(%rbp)
jmp 0x1689
movq -0x180(%rbp), %rdi
movq 0x2931(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x169e
leaq 0x983(%rip), %rdx       # 0x2028
leaq -0x120(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1820
jmp 0x16b7
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x17d0
jmp 0x16d0
leaq -0x120(%rbp), %rdi
callq 0x10b0
movq 0x28f5(%rip), %rdi      # 0x3fd8
leaq -0x100(%rbp), %rsi
callq 0x10e0
movq %rax, -0x198(%rbp)
jmp 0x16f8
movq -0x198(%rbp), %rdi
movq 0x28c2(%rip), %rsi      # 0x3fc8
callq 0x1110
jmp 0x170d
movl $0x0, -0x4(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x10b0
leaq -0x60(%rbp), %rdi
callq 0x10b0
leaq -0x28(%rbp), %rdi
callq 0x10b0
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x10b0
jmp 0x1770
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x10b0
leaq -0x60(%rbp), %rdi
callq 0x10b0
leaq -0x28(%rbp), %rdi
callq 0x10b0
movq -0x38(%rbp), %rdi
callq 0x1170
nopl (%rax,%rax)