// File: /workspace/github_c_makefile_star2_O3/georgeweigt[P]sassafras/sassafras.c
// Function: print_table
void
print_table(char **a, int nrow, int ncol, char *fmt)
{
	int c, i, j, k, n, nsp = 0, t, *w;
	char *b, *buf, *s;

	w = (int *) xmalloc(ncol * sizeof (int));

	// measure column widths

	t = 0;

	for (j = 0; j < ncol; j++) {
		w[j] = 0;
		for (i = 0; i < nrow; i++) {
			s = A(i, j);
			if (s == NULL)
				continue;
			n = (int) strlen(s);
			if (n > w[j])
				w[j] = n;
		}
		t += w[j];
	}

	// spaces between columns

	if (ncol > 1) {
		nsp = (80 - t) / (ncol - 1);
		if (nsp < 2)
			nsp = 2;
		if (nsp > 5)
			nsp = 5;
		t += (ncol - 1) * nsp;
	}

	// number of spaces to center the line

	if (t < 80)
		c = (80 - t) / 2;
	else
		c = 0;

	// alloc line buffer

	buf = (char *) xmalloc(c + t + 1);

	// leading spaces

	memset(buf, ' ', c);

	// for each row

	for (i = 0; i < nrow; i++) {

		b = buf + c;

		// for each column

		for (j = 0; j < ncol; j++) {

			// space between columns

			if (j > 0) {
				memset(b, ' ', nsp);
				b += nsp;
			}

			s = A(i, j);

			if (s == NULL) {
				memset(b, ' ', w[j]);
				b += w[j];
			} else {

				n = (int) strlen(s);

				k = w[j] - n;

				switch (fmt[j]) {

				// right aligned

				case 0:
					memset(b, ' ', k);
					b += k;
					strcpy(b, s);
					b += n;
					break;

				// left aligned

				case 1:
					strcpy(b, s);
					b += n;
					memset(b, ' ', k);
					b += k;
					break;
				}
			}
		}

		*b = 0;

		emit_line(buf);
	}

	free(buf);
	free(w);

	emit_line("");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x80(%rbp)
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, %r12
leal (,%r15,4), %edi
callq 0x2bd8
movq %rax, -0x50(%rbp)
xorl %edi, %edi
movl %r15d, %eax
movl %ebx, -0x40(%rbp)
movl %ebx, %ecx
movq %rcx, -0x70(%rbp)
testl %r15d, %r15d
movq %rax, -0x38(%rbp)
movq %r15, -0x68(%rbp)
jle 0x4861
leaq (,%rax,8), %rbx
movq %r12, -0x30(%rbp)
movq %r12, %r15
xorl %r12d, %r12d
movq %rdi, -0x48(%rbp)
movq -0x50(%rbp), %rax
movl $0x0, (%rax,%r12,4)
cmpl $0x0, -0x40(%rbp)
movq %r15, -0x60(%rbp)
jle 0x4830
xorl %r13d, %r13d
movq -0x70(%rbp), %r14
movq (%r15), %rdi
testq %rdi, %rdi
je 0x4826
callq 0x20b0
cmpl %eax, %r13d
jge 0x4826
movq -0x50(%rbp), %rcx
movl %eax, (%rcx,%r12,4)
movl %eax, %r13d
addq %rbx, %r15
decq %r14
jne 0x4809
jmp 0x4833
xorl %r13d, %r13d
movq -0x48(%rbp), %rdi
addl %r13d, %edi
incq %r12
movq -0x60(%rbp), %r15
addq $0x8, %r15
cmpq -0x38(%rbp), %r12
jne 0x47e8
xorl %ebx, %ebx
movq -0x68(%rbp), %r15
cmpl $0x1, %r15d
jne 0x4875
movq $0x0, -0x48(%rbp)
jmp 0x48a4
movl $0x28, %ebx
movl $0x1, %edi
movq $0x0, -0x48(%rbp)
jmp 0x48b7
movl $0x50, %eax
subl %edi, %eax
leal -0x1(%r15), %ecx
cltd
idivl %ecx
cmpl $0x3, %eax
movl $0x2, %edx
cmovgel %eax, %edx
cmpl $0x5, %edx
movl $0x5, %eax
cmovll %edx, %eax
movq %rax, -0x48(%rbp)
imull %eax, %ecx
addl %edi, %ecx
movl %ecx, %edi
movq -0x30(%rbp), %r12
leal -0x50(%rdi), %eax
negl %eax
shrl %eax
cmpl $0x50, %edi
cmovll %eax, %ebx
incl %edi
addl %ebx, %edi
callq 0x2bd8
movl %ebx, %ebx
movq %rax, -0x58(%rbp)
movq %rax, %rdi
movl $0x20, %esi
movq %rbx, %rdx
callq 0x2100
cmpl $0x0, -0x40(%rbp)
jle 0x4a13
movq -0x58(%rbp), %rax
addq %rbx, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x78(%rbp)
xorl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %r14
testl %r15d, %r15d
movq -0x38(%rbp), %r15
jle 0x49ed
xorl %r13d, %r13d
movq -0x40(%rbp), %r14
movq %r12, -0x30(%rbp)
testq %r13, %r13
je 0x4937
movq %r14, %rdi
movl $0x20, %esi
movq -0x48(%rbp), %rbx
movq %rbx, %rdx
callq 0x2100
addq %rbx, %r14
movq (%r12,%r13,8), %rbx
testq %rbx, %rbx
je 0x4991
movq %rbx, %rdi
callq 0x20b0
movq %rax, %r15
movq -0x50(%rbp), %rax
movslq (%rax,%r13,4), %r12
movslq %r15d, %rax
subq %rax, %r12
movq -0x80(%rbp), %rax
movzbl (%rax,%r13), %eax
cmpl $0x1, %eax
je 0x49af
testl %eax, %eax
jne 0x49d9
movq %r14, %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0x2100
addq %r12, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2060
movslq %r15d, %rax
addq %rax, %r14
jmp 0x49d9
movq -0x50(%rbp), %rbx
movslq (%rbx,%r13,4), %rdx
movq %r14, %rdi
movl $0x20, %esi
callq 0x2100
movslq (%rbx,%r13,4), %rax
addq %rax, %r14
jmp 0x49e1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2060
movslq %r15d, %rbx
addq %r14, %rbx
movslq %r12d, %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x2100
addq %r14, %rbx
movq %rbx, %r14
movq -0x30(%rbp), %r12
movq -0x38(%rbp), %r15
incq %r13
cmpq %r13, %r15
jne 0x491b
movb $0x0, (%r14)
movq -0x58(%rbp), %rdi
callq 0x2070
movq -0x60(%rbp), %rax
incq %rax
addq -0x78(%rbp), %r12
cmpq -0x70(%rbp), %rax
movq -0x68(%rbp), %r15
jne 0x48fb
movq -0x58(%rbp), %rdi
callq 0x2040
movq -0x50(%rbp), %rdi
callq 0x2040
movl $0xa, %edi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050