// File: /workspace/github_c_makefile_star2_O2/eric-lo[P]3150/8-Synchronization/pthread_producer_consumer.c
// Function: drawing
void drawing(int turn, int item) {
	int last_produce = -1;
	int last_consume = -1;
	int i = 0, count;
	char print_buf[PRINT_BUF_SIZE];
	FILE *f = stdout;

	if(turn == PRODUCER_TURN) {
		last_produce = item;
		last_consume = -1;
	}

	if(turn == CONSUMER_TURN) {
		last_produce = -1;
		last_consume = item;
	}

/* format the output */

	print_buf[0] = '\0';

	// Consumer...

	if(last_consume == -1)
		sprintf(print_buf, "%s[ ]", print_buf);
	else
		sprintf(print_buf, "%s[%c]", print_buf, last_consume);

	sprintf(print_buf, "%s<---", print_buf);

	// The slots...

	count = 0;
	for(i = head; i != tail; i = (i+1)%N) {
		count++;
		sprintf(print_buf, "%s| %c ", print_buf, buffer[i]);
	}

	for(i = count; i < N-1; i++)
		sprintf(print_buf, "%s|   ", print_buf);
	sprintf(print_buf, "%s|", print_buf);

	// Producer...

	sprintf(print_buf, "%s<---", print_buf);
	if(last_produce == -1)
		sprintf(print_buf, "%s[ ]", print_buf);
	else
		sprintf(print_buf, "%s[%c]", print_buf, last_produce);

/* print the output */

	fprintf(f, "%s\n", print_buf);
	fflush(f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movl %esi, %r14d
movq 0x2dc9(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, %edi
sete %al
xorl %ebx, %ebx
negl %edi
sbbl %ebx, %ebx
movb $0x0, 0x10(%rsp)
cmpl $-0x1, %esi
setne %cl
testb %cl, %al
jne 0x1252
leaq 0xdc3(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x126b
leaq 0xdb1(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x10c0
orl %r14d, %ebx
movl %ebx, 0x4(%rsp)
leaq 0xd98(%rip), %rsi       # 0x2011
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
movl 0x2e96(%rip), %r12d     # 0x4128
leaq 0x2e97(%rip), %rbx      # 0x4130
leaq 0xd78(%rip), %r15       # 0x2018
pushq $0xa
popq %rbp
xorl %r13d, %r13d
cmpl 0x2e7f(%rip), %r12d     # 0x412c
je 0x12d6
incl %r13d
movslq %r12d, %rax
movl (%rbx,%rax,4), %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
incl %r12d
movl %r12d, %eax
cltd
idivl %ebp
movl %edx, %r12d
jmp 0x12a6
leaq 0xd43(%rip), %r14       # 0x2020
leaq 0x10(%rsp), %r15
movl 0x4(%rsp), %ebx
cmpl $0x8, %r13d
ja 0x1301
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10c0
incl %r13d
jmp 0x12e6
leaq 0xd1f(%rip), %rsi       # 0x2027
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xcf0(%rip), %rsi       # 0x2011
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
cmpl $-0x1, %ebx
je 0x134d
leaq 0xcd0(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x10c0
jmp 0x1363
leaq 0xcb0(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xcc1(%rip), %rsi       # 0x202b
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
callq 0x10a0
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq