// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x14(%rbp)
movq 0x2db3(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movq %rax, -0x428(%rbp)
cmpl $0x0, -0x4(%rbp)
jne 0x124a
movl -0x8(%rbp), %eax
movl %eax, -0xc(%rbp)
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
cmpl $0x1, -0x4(%rbp)
jne 0x125d
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %eax
movl %eax, -0x10(%rbp)
movb $0x0, -0x420(%rbp)
cmpl $-0x1, -0x10(%rbp)
jne 0x1288
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xd85(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10c0
jmp 0x12a7
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
movl -0x10(%rbp), %ecx
leaq 0xd6a(%rip), %rsi       # 0x200a
movb $0x0, %al
callq 0x10c0
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xd55(%rip), %rsi       # 0x2011
movb $0x0, %al
callq 0x10c0
movl $0x0, -0x18(%rbp)
movl 0x2e58(%rip), %eax      # 0x4128
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x2e50(%rip), %eax      # 0x412c
je 0x1324
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
movslq -0x14(%rbp), %rcx
leaq 0x2e30(%rip), %rax      # 0x4130
movl (%rax,%rcx,4), %ecx
leaq 0xd0e(%rip), %rsi       # 0x2018
movb $0x0, %al
callq 0x10c0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %edx, -0x14(%rbp)
jmp 0x12d3
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x9, -0x14(%rbp)
jge 0x1357
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xcdb(%rip), %rsi       # 0x2020
movb $0x0, %al
callq 0x10c0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x132a
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xcbb(%rip), %rsi       # 0x2027
movb $0x0, %al
callq 0x10c0
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xc89(%rip), %rsi       # 0x2011
movb $0x0, %al
callq 0x10c0
cmpl $-0x1, -0xc(%rbp)
jne 0x13b3
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xc5a(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10c0
jmp 0x13d2
leaq -0x420(%rbp), %rdi
leaq -0x420(%rbp), %rdx
movl -0xc(%rbp), %ecx
leaq 0xc3f(%rip), %rsi       # 0x200a
movb $0x0, %al
callq 0x10c0
movq -0x428(%rbp), %rdi
leaq -0x420(%rbp), %rdx
leaq 0xc44(%rip), %rsi       # 0x202b
movb $0x0, %al
callq 0x1070
movq -0x428(%rbp), %rdi
callq 0x10a0
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopw %cs:(%rax,%rax)