// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xd41(%rip), %rsi       # 0x2010
leaq 0xd4a(%rip), %rdx       # 0x2020
leaq -0x68(%rbp), %rdi
callq 0x18a2
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xd41(%rip), %rsi       # 0x2030
leaq 0xd4c(%rip), %rdx       # 0x2042
leaq -0x48(%rbp), %rdi
callq 0x18a2
movq -0x60(%rbp), %rbx
movq -0x40(%rbp), %r14
cmpq %rbx, %r14
movq %rbx, %rdx
cmovbq %r14, %rdx
testq %rdx, %rdx
je 0x1327
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdi
callq 0x1060
testl %eax, %eax
jne 0x134b
movq %rbx, %rcx
subq %r14, %rcx
cmpq $-0x7fffffff, %rcx      # imm = 0x80000001
movq $-0x80000000, %rax      # imm = 0x80000000
cmovgeq %rcx, %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
cmovgeq %rcx, %rax
testl %eax, %eax
js 0x137b
movq -0x48(%rbp), %rsi
movq 0x2c7e(%rip), %rdi      # 0x3fd8
movq %r14, %rdx
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
jmp 0x13a5
movq -0x68(%rbp), %rsi
movq 0x2c52(%rip), %rdi      # 0x3fd8
movq %rbx, %rdx
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movaps 0xc71(%rip), %xmm0      # 0x2030
leaq -0xc0(%rbp), %r14
movaps %xmm0, (%r14)
movl $0x676e69, 0xf(%r14)    # imm = 0x676E69
movq %r14, %rdi
callq 0x1050
movq 0x2bf7(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x2bcb(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq 0xbef(%rip), %rdi       # 0x2010
leaq -0xc0(%rbp), %rsi
callq 0x1100
movq 0x2ba4(%rip), %rdi      # 0x3fd8
movl %eax, %esi
callq 0x1120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq 0xba4(%rip), %rsi       # 0x2010
leaq -0xc0(%rbp), %rdi
callq 0x1100
movq 0x2b59(%rip), %rdi      # 0x3fd8
movl %eax, %esi
callq 0x1120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x2b21(%rip), %rdi      # 0x3fd8
xorl %esi, %esi
callq 0x1120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq 0x2ae9(%rip), %rdi      # 0x3fd8
movl $0x10, %esi
callq 0x1080
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movaps 0xae6(%rip), %xmm0      # 0x2010
leaq -0xf0(%rbp), %r14
movaps %xmm0, (%r14)
movb $0x0, 0x10(%r14)
movq %r14, %rdi
callq 0x1050
movw $0x20, -0xf0(%rbp,%rax)
leaq -0xc0(%rbp), %rsi
movq %r14, %rdi
callq 0x1140
movq %r14, %rdi
callq 0x1050
movq 0x2a6e(%rip), %rbx      # 0x3fd8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x2a42(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1090
movups 0xad5(%rip), %xmm0      # 0x207f
leaq -0xf0(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movups 0xab3(%rip), %xmm0      # 0x206f
movaps %xmm0, (%rbx)
movl $0x0, 0x20(%rbx)
movq %rbx, %rdi
callq 0x1050
movw $0x20, -0xf0(%rbp,%rax)
movq %rbx, %rdi
callq 0x1050
movl $0x24, %edx
subq %rax, %rdx
leaq -0xc0(%rbp), %rsi
movq %rbx, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1050
movq 0x29d2(%rip), %r14      # 0x3fd8
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x10f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x29a6(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq -0x78(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x1804
leaq 0x9de(%rip), %rsi       # 0x2043
leaq -0x88(%rbp), %rdi
callq 0x1160
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x1040
leaq -0x98(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x16b2
movq %rsi, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x16bc
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rsi
movq 0x8(%rax), %rdx
movq %rdx, -0xa0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x88(%rbp), %rdi
cmpq %r13, %rdi
je 0x16fc
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq 0x28d5(%rip), %rdi      # 0x3fd8
callq 0x10f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x174d
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x1762
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x1777
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10e0
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x178d
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r13, %rdi
je 0x17d2
movq -0x78(%rbp), %rsi
jmp 0x17bf
jmp 0x17cf
movq %rax, %rbx
jmp 0x17e7
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x17d2
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10e0
jmp 0x17d2
jmp 0x17cf
jmp 0x17cf
jmp 0x17cf
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x17e7
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x17fc
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1130