// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movl %esi, %r15d
movq %rdi, %r14
leal (,%rbx,4), %edi
callq 0x2bda
movq %rax, %r13
movl %ebx, %eax
movl %r15d, -0x40(%rbp)
movl %r15d, %ecx
movq %rcx, -0x70(%rbp)
movq %rbx, -0x60(%rbp)
testl %ebx, %ebx
movq %r13, -0x38(%rbp)
movq %r14, -0x30(%rbp)
movq %rax, -0x58(%rbp)
jle 0x489e
leaq (,%rax,8), %r15
xorl %r12d, %r12d
movq %r14, %rbx
xorl %esi, %esi
movq %rsi, -0x48(%rbp)
movl $0x0, (%r13,%r12,4)
cmpl $0x0, -0x40(%rbp)
jle 0x4882
movq -0x70(%rbp), %r14
movq %rbx, %r13
movq (%r13), %rdi
testq %rdi, %rdi
je 0x487a
callq 0x20b0
movq -0x38(%rbp), %rcx
cmpl %eax, (%rcx,%r12,4)
jge 0x487a
movq -0x38(%rbp), %rcx
movl %eax, (%rcx,%r12,4)
addq %r15, %r13
decq %r14
jne 0x485a
movq -0x38(%rbp), %r13
movq -0x48(%rbp), %rsi
addl (%r13,%r12,4), %esi
incq %r12
addq $0x8, %rbx
cmpq -0x58(%rbp), %r12
jne 0x4840
jmp 0x48a0
xorl %esi, %esi
xorl %r14d, %r14d
movq -0x60(%rbp), %rbx
cmpl $0x2, %ebx
jl 0x48dc
movl $0x50, %eax
subl %esi, %eax
leal -0x1(%rbx), %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 %esi, %ecx
movl %ecx, %esi
jmp 0x48e4
movq $0x0, -0x48(%rbp)
movq -0x30(%rbp), %r15
leal -0x50(%rsi), %eax
negl %eax
shrl %eax
cmpl $0x50, %esi
cmovll %eax, %r14d
leal (%rsi,%r14), %edi
incl %edi
callq 0x2bda
movq %rax, -0x50(%rbp)
movq %rax, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x2100
cmpl $0x0, -0x40(%rbp)
jle 0x4a4b
movq -0x50(%rbp), %rax
addq %r14, %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x78(%rbp)
xorl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x68(%rbp), %r14
testl %ebx, %ebx
jle 0x4a25
xorl %r12d, %r12d
movq -0x68(%rbp), %r14
movq %r15, -0x30(%rbp)
testq %r12, %r12
je 0x4973
movq %r14, %rdi
movl $0x20, %esi
movq -0x48(%rbp), %rbx
movq %rbx, %rdx
callq 0x2100
addq %rbx, %r14
movq (%r15,%r12,8), %rbx
testq %rbx, %rbx
je 0x49ca
movq %rbx, %rdi
callq 0x20b0
movq %rax, %r15
movslq (%r13,%r12,4), %r13
movslq %r15d, %rax
subq %rax, %r13
movq -0x80(%rbp), %rax
movzbl (%rax,%r12), %eax
cmpl $0x1, %eax
je 0x49e6
testl %eax, %eax
jne 0x4a10
movq %r14, %rdi
movl $0x20, %esi
movq %r13, %rdx
callq 0x2100
addq %r13, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2060
movslq %r15d, %rax
addq %rax, %r14
jmp 0x4a10
movslq (%r13,%r12,4), %rdx
movq %r14, %rdi
movl $0x20, %esi
callq 0x2100
movslq (%r13,%r12,4), %rax
addq %rax, %r14
jmp 0x4a18
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2060
movslq %r15d, %rbx
addq %r14, %rbx
movslq %r13d, %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x2100
addq %r14, %rbx
movq %rbx, %r14
movq -0x30(%rbp), %r15
movq -0x38(%rbp), %r13
incq %r12
cmpq %r12, -0x58(%rbp)
jne 0x4957
movb $0x0, (%r14)
movq -0x50(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %rax
incq %rax
addq -0x78(%rbp), %r15
cmpq -0x70(%rbp), %rax
movq -0x60(%rbp), %rbx
jne 0x493c
movq -0x50(%rbp), %rdi
callq 0x2040
movq %r13, %rdi
callq 0x2040
movl $0xa, %edi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050