// File: /workspace/github_cpp_makefile_star2_O1/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 0x18a0
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xd41(%rip), %rsi       # 0x2030
leaq 0xd4c(%rip), %rdx       # 0x2042
leaq -0x48(%rbp), %rdi
callq 0x18a0
movq -0x60(%rbp), %rbx
movq -0x40(%rbp), %r14
cmpq %rbx, %r14
movq %rbx, %rdx
cmovbq %r14, %rdx
testq %rdx, %rdx
je 0x1325
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdi
callq 0x1060
jmp 0x1327
xorl %eax, %eax
testl %eax, %eax
jne 0x134f
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 0x137f
movq -0x48(%rbp), %rsi
movq 0x2c7a(%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 0x13a9
movq -0x68(%rbp), %rsi
movq 0x2c4e(%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 0xc6d(%rip), %xmm0      # 0x2030
leaq -0xc0(%rbp), %r14
movaps %xmm0, (%r14)
movl $0x676e69, 0xf(%r14)    # imm = 0x676E69
movq %r14, %rdi
callq 0x1050
movq 0x2bf3(%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 0x2bc7(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq 0xbeb(%rip), %rdi       # 0x2010
leaq -0xc0(%rbp), %rsi
callq 0x1100
movq 0x2ba0(%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 0xba0(%rip), %rsi       # 0x2010
leaq -0xc0(%rbp), %rdi
callq 0x1100
movq 0x2b55(%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 0x2b1d(%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 0x2ae5(%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 0xae2(%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 0x2a6a(%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 0x2a3e(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1090
movups 0xad1(%rip), %xmm0      # 0x207f
leaq -0xf0(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movups 0xaaf(%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 0x29ce(%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 0x29a2(%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 0x1806
leaq 0x9da(%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), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x16b6
movq %rdx, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x16bd
movups (%rcx), %xmm0
movups %xmm0, (%r14)
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 0x16ef
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq 0x28d4(%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 0x174e
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x1763
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x1778
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 0x178e
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r13, %rdi
je 0x17d3
movq -0x78(%rbp), %rsi
jmp 0x17c0
jmp 0x17d0
movq %rax, %rbx
jmp 0x17e8
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r14, %rdi
je 0x17d3
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x10e0
jmp 0x17d3
jmp 0x17d0
jmp 0x17d0
jmp 0x17d0
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x17e8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x10e0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x17fd
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10e0
movq %rbx, %rdi
callq 0x1130
nop