// File: iZhangHui[P]CppPrimer/CH04_Expressions/examples/shift-prec.cc
// Function: main
int main()
{
	int grade = 75;
	cout << ((grade < 60) ?  "fail" : "pass"); // prints pass or fail
	cout << endl;

	cout << (grade < 60) ?  "fail" : "pass";   // prints 1 or 0!
	cout << endl;

	// previous expression is equivalent to the following
	cout << (grade < 60);    // prints 1 or 0
	cout ?  "fail" : "pass"; // test cout and then yield one of the two literals
	                         // depending on whether cout is true or false
	cout << endl;
	int i = 15, j = 20;
	cout << (i < j ? i : j);  // ok: prints smaller of i and j
	cout << endl;

	cout << (i < j) ? i : j;  // ok: prints 1 or 0!
	cout << endl;
	
	// previous expression is equivalent to the following
	cout << (i < j); // prints 1 or 0
	cout ? i : j;    // test cout and then evaluate i or j
	                 // depending on whether cout evaluates to true or false
	cout << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl $0x4b, -0x8(%rbp)
cmpl $0x3c, -0x8(%rbp)
jge 0x1209
leaq 0xe01(%rip), %rax       # 0x2004
movq %rax, -0x18(%rbp)
jmp 0x1216
leaq 0xdf9(%rip), %rax       # 0x2009
movq %rax, -0x18(%rbp)
jmp 0x1216
movq -0x18(%rbp), %rsi
movq 0x2db7(%rip), %rdi      # 0x3fd8
callq 0x1040
movq 0x2dab(%rip), %rdi      # 0x3fd8
movq 0x2d94(%rip), %rsi      # 0x3fc8
callq 0x1050
cmpl $0x3c, -0x8(%rbp)
setl %al
movzbl %al, %esi
andl $0x1, %esi
movq 0x2d8b(%rip), %rdi      # 0x3fd8
callq 0x1090
movq %rax, %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x1060
testb $0x1, %al
jne 0x1267
jmp 0x1269
jmp 0x126b
jmp 0x126b
movq 0x2d66(%rip), %rdi      # 0x3fd8
movq 0x2d4f(%rip), %rsi      # 0x3fc8
callq 0x1050
cmpl $0x3c, -0x8(%rbp)
setl %al
movzbl %al, %esi
andl $0x1, %esi
movq 0x2d46(%rip), %rdi      # 0x3fd8
callq 0x1090
movq 0x2d3a(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movq 0x2d30(%rip), %rdi      # 0x3fd8
addq -0x18(%rax), %rdi
callq 0x1060
testb $0x1, %al
jne 0x12b7
jmp 0x12b9
jmp 0x12bb
jmp 0x12bb
movq 0x2d16(%rip), %rdi      # 0x3fd8
movq 0x2cff(%rip), %rsi      # 0x3fc8
callq 0x1050
movl $0xf, -0xc(%rbp)
movl $0x14, -0x10(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x12ec
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x12f2
movl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movq 0x2cdc(%rip), %rdi      # 0x3fd8
callq 0x1080
movq 0x2cd0(%rip), %rdi      # 0x3fd8
movq 0x2cb9(%rip), %rsi      # 0x3fc8
callq 0x1050
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
setl %al
movzbl %al, %esi
andl $0x1, %esi
movq 0x2cae(%rip), %rdi      # 0x3fd8
callq 0x1090
movq %rax, %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x1060
testb $0x1, %al
jne 0x1344
jmp 0x1346
jmp 0x1348
jmp 0x1348
movq 0x2c89(%rip), %rdi      # 0x3fd8
movq 0x2c72(%rip), %rsi      # 0x3fc8
callq 0x1050
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
setl %al
movzbl %al, %esi
andl $0x1, %esi
movq 0x2c67(%rip), %rdi      # 0x3fd8
callq 0x1090
movq 0x2c5b(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movq 0x2c51(%rip), %rdi      # 0x3fd8
addq -0x18(%rax), %rdi
callq 0x1060
testb $0x1, %al
jne 0x1396
jmp 0x1398
jmp 0x139a
jmp 0x139a
movq 0x2c37(%rip), %rdi      # 0x3fd8
movq 0x2c20(%rip), %rsi      # 0x3fc8
callq 0x1050
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq