// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0xd0, %rsp
leaq 0xd3f(%rip), %rsi       # 0x2010
leaq -0xe0(%rbp), %rbx
leaq -0x60(%rbp), %rdx
movq %rbx, %rdi
callq 0x1050
leaq 0xd45(%rip), %rsi       # 0x2030
leaq -0xc0(%rbp), %r14
leaq -0x60(%rbp), %rdx
movq %r14, %rdi
callq 0x1050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1533
testb %al, %al
cmovneq %rbx, %r14
movq 0x2cc2(%rip), %rdi      # 0x3fd8
movq %r14, %rsi
callq 0x10d0
movq %rax, %rdi
callq 0x1090
movaps 0xd03(%rip), %xmm0      # 0x2030
leaq -0x30(%rbp), %rsi
movaps %xmm0, (%rsi)
movl $0x676e69, 0xf(%rsi)    # imm = 0x676E69
movq 0x2c96(%rip), %rdi      # 0x3fd8
callq 0x10e0
movq %rax, %rdi
callq 0x1090
leaq 0xcba(%rip), %rdi       # 0x2010
leaq -0x30(%rbp), %rsi
callq 0x1110
movq 0x2c72(%rip), %rdi      # 0x3fd8
movl %eax, %esi
callq 0x1130
movq %rax, %rdi
callq 0x1090
leaq 0xc94(%rip), %rsi       # 0x2010
leaq -0x30(%rbp), %rdi
callq 0x1110
movq 0x2c4c(%rip), %rdi      # 0x3fd8
movl %eax, %esi
callq 0x1130
movq %rax, %rdi
callq 0x1090
movq 0x2c36(%rip), %rdi      # 0x3fd8
xorl %esi, %esi
callq 0x1130
movq %rax, %rdi
callq 0x1090
movq 0x2c20(%rip), %rdi      # 0x3fd8
pushq $0x10
popq %rsi
callq 0x10b0
movq %rax, %rdi
callq 0x1090
movaps 0xc41(%rip), %xmm0      # 0x2010
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
movb $0x0, 0x10(%rbx)
movq %rbx, %rdi
callq 0x1070
movw $0x20, -0x60(%rbp,%rax)
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1150
movq 0x2bdc(%rip), %rdi      # 0x3fd8
movq %rbx, %rsi
callq 0x10e0
movq %rax, %rdi
callq 0x1090
movups 0xc42(%rip), %xmm0      # 0x2055
movaps %xmm0, 0x10(%rbx)
movups 0xc27(%rip), %xmm0      # 0x2045
movaps %xmm0, (%rbx)
andl $0x0, 0x20(%rbx)
movq %rbx, %rdi
callq 0x1070
movw $0x20, -0x60(%rbp,%rax)
movq %rbx, %rdi
callq 0x1070
pushq $0x24
popq %rdx
subq %rax, %rdx
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x10a0
movq 0x2b83(%rip), %rdi      # 0x3fd8
movq %rbx, %rsi
callq 0x10e0
movq %rax, %rdi
callq 0x1090
leaq 0xbd7(%rip), %rdx       # 0x2043
leaq -0x80(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x1572
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x1549
leaq -0x80(%rbp), %rdi
callq 0x1080
movq 0x2b35(%rip), %rdi      # 0x3fd8
leaq -0xa0(%rbp), %rsi
callq 0x10d0
movq %rax, %rdi
callq 0x1090
leaq -0xa0(%rbp), %rdi
callq 0x1080
leaq -0xc0(%rbp), %rdi
callq 0x1080
leaq -0xe0(%rbp), %rdi
callq 0x1080
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x1503
jmp 0x1510
movq %rax, %rbx
jmp 0x151f
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x1080
jmp 0x1513
jmp 0x1510
jmp 0x1510
jmp 0x1510
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x1080
leaq -0xe0(%rbp), %rdi
callq 0x1080
movq %rbx, %rdi
callq 0x1140