// File: /workspace/github_c_makefile_star2_O3/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), %rbx
cmpl $0x1, %edi
sete %al
xorl %ebp, %ebp
negl %edi
sbbl %ebp, %ebp
movb $0x0, 0x10(%rsp)
cmpl $-0x1, %esi
setne %cl
testb %cl, %al
jne 0x124d
leaq 0xdc8(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x1266
leaq 0xdb6(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x10c0
orl %r14d, %ebp
leaq 0xda1(%rip), %rsi       # 0x2011
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
movl 0x2ea0(%rip), %eax      # 0x4128
cmpl 0x2e9e(%rip), %eax      # 0x412c
je 0x1304
movq %rbx, 0x8(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0x2e8e(%rip), %r13      # 0x4130
leaq 0xd6f(%rip), %r14       # 0x2018
leaq 0x10(%rsp), %r15
movslq %eax, %rbx
movl (%r13,%rbx,4), %ecx
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10c0
movl %ebx, %eax
incl %eax
cltq
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
negl %eax
addl %ebx, %eax
incl %eax
incl %r12d
cmpl 0x2e38(%rip), %eax      # 0x412c
jne 0x12ae
cmpl $0x7, %r12d
movq 0x8(%rsp), %rbx
ja 0x1329
incl %r12d
addl $-0x9, %r12d
leaq 0xd11(%rip), %r14       # 0x2020
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10c0
incl %r12d
jne 0x1314
leaq 0xcf7(%rip), %rsi       # 0x2027
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xcc8(%rip), %rsi       # 0x2011
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
cmpl $-0x1, %ebp
je 0x1375
leaq 0xca8(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x10c0
jmp 0x138b
leaq 0xc88(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xc99(%rip), %rsi       # 0x202b
leaq 0x10(%rsp), %rdx
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