// File: /workspace/github_c_makefile_star2_O1/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
movq 0x2dcc(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
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
movl %esi, 0x4(%rsp)
jne 0x1253
leaq 0xdc2(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x126f
movl %esi, %r8d
leaq 0xdad(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %r8d, %ecx
xorl %eax, %eax
callq 0x10c0
leaq 0xd9b(%rip), %rsi       # 0x2011
xorl %r13d, %r13d
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
movl 0x2e9a(%rip), %eax      # 0x4128
cmpl 0x2e98(%rip), %eax      # 0x412c
je 0x12f5
leaq 0x2e93(%rip), %rbx      # 0x4130
leaq 0xd74(%rip), %r15       # 0x2018
leaq 0x10(%rsp), %r12
xorl %r13d, %r13d
incl %r13d
movslq %eax, %r14
movl (%rbx,%r14,4), %ecx
movq %r12, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10c0
movl %r14d, %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 %r14d, %eax
incl %eax
cmpl 0x2e39(%rip), %eax      # 0x412c
jne 0x12ac
orl 0x4(%rsp), %ebp
cmpl $0x8, %r13d
ja 0x1324
addl $-0x9, %r13d
leaq 0xd16(%rip), %r14       # 0x2020
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10c0
incl %r13d
jne 0x130f
leaq 0xcfc(%rip), %rsi       # 0x2027
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xccd(%rip), %rsi       # 0x2011
movq %r14, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x10c0
cmpl $-0x1, %ebp
je 0x1370
leaq 0xcad(%rip), %rsi       # 0x200a
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x10c0
jmp 0x1386
leaq 0xc8d(%rip), %rsi       # 0x2004
leaq 0x10(%rsp), %rdi
movq %rdi, %rdx
xorl %eax, %eax
callq 0x10c0
leaq 0xc9e(%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