// File: /workspace/github_c_makefile_star2_O2/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, -0x78(%rbp)
movl %edx, %r15d
movl %esi, %r14d
movq %rdi, %r12
leal (,%r15,4), %edi
callq 0x2a9b
movslq %r15d, %rcx
xorl %ebx, %ebx
testl %r14d, %r14d
cmovlel %ebx, %r14d
movq %r14, -0x50(%rbp)
testl %ecx, %ecx
movl $0x0, %edx
movq %r15, -0x40(%rbp)
cmovgl %r15d, %edx
movq %rdx, -0x68(%rbp)
movq %rax, -0x30(%rbp)
shlq $0x3, %rcx
movq %rcx, -0x58(%rbp)
movq %r12, -0x60(%rbp)
xorl %edi, %edi
cmpq -0x68(%rbp), %rbx
je 0x454c
movq %rdi, -0x38(%rbp)
movq -0x30(%rbp), %rax
andl $0x0, (%rax,%rbx,4)
xorl %r15d, %r15d
movq %r12, %r13
movq -0x50(%rbp), %r14
xorl %ecx, %ecx
subq $0x1, %r14
jb 0x453d
movq (%r13), %rdi
testq %rdi, %rdi
je 0x4537
callq 0x20b0
movl %r15d, %ecx
cmpl %eax, %r15d
jge 0x4537
movq -0x30(%rbp), %rcx
movl %eax, (%rcx,%rbx,4)
movl %eax, %r15d
movl %eax, %ecx
addq -0x58(%rbp), %r13
jmp 0x450f
movq -0x38(%rbp), %rdi
addl %ecx, %edi
incq %rbx
addq $0x8, %r12
jmp 0x44f1
xorl %r14d, %r14d
movq -0x40(%rbp), %rsi
cmpl $0x2, %esi
jl 0x4581
pushq $0x50
popq %rax
subl %edi, %eax
decl %esi
cltd
idivl %esi
cmpl $0x3, %eax
pushq $0x2
popq %rcx
cmovgel %eax, %ecx
cmpl $0x5, %ecx
pushq $0x5
popq %rax
cmovll %ecx, %eax
movq %rax, -0x38(%rbp)
imull %eax, %esi
addl %edi, %esi
movl %esi, %edi
jmp 0x4589
movq $0x0, -0x38(%rbp)
leal -0x50(%rdi), %ebx
negl %ebx
shrl %ebx
cmpl $0x50, %edi
cmovgel %r14d, %ebx
addl %ebx, %edi
incl %edi
callq 0x2a9b
movq %rax, %r15
pushq $0x20
popq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x2100
movq %r15, -0x48(%rbp)
addq %rbx, %r15
movq %r15, -0x70(%rbp)
cmpq -0x50(%rbp), %r14
je 0x46ba
movq %r14, -0x40(%rbp)
xorl %r13d, %r13d
movq -0x70(%rbp), %rbx
cmpq %r13, -0x68(%rbp)
je 0x469a
testq %r13, %r13
je 0x45f5
movq %rbx, %rdi
pushq $0x20
popq %rsi
movq -0x38(%rbp), %r14
movq %r14, %rdx
callq 0x2100
addq %r14, %rbx
movq -0x60(%rbp), %rax
movq (%rax,%r13,8), %r15
testq %r15, %r15
je 0x464e
movq %r15, %rdi
callq 0x20b0
movq %rax, %r14
movq -0x30(%rbp), %rax
movslq (%rax,%r13,4), %r12
movslq %r14d, %rax
subq %rax, %r12
movq -0x78(%rbp), %rax
movzbl (%rax,%r13), %eax
cmpl $0x1, %eax
je 0x466a
testl %eax, %eax
jne 0x4692
movq %rbx, %rdi
pushq $0x20
popq %rsi
movq %r12, %rdx
callq 0x2100
addq %r12, %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2060
movslq %r14d, %rax
jmp 0x4665
movq -0x30(%rbp), %r14
movslq (%r14,%r13,4), %rdx
movq %rbx, %rdi
pushq $0x20
popq %rsi
callq 0x2100
movslq (%r14,%r13,4), %rax
addq %rax, %rbx
jmp 0x4692
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2060
movslq %r14d, %r14
addq %rbx, %r14
movslq %r12d, %rbx
movq %r14, %rdi
pushq $0x20
popq %rsi
movq %rbx, %rdx
callq 0x2100
addq %rbx, %r14
movq %r14, %rbx
incq %r13
jmp 0x45d1
movb $0x0, (%rbx)
movq -0x48(%rbp), %rdi
callq 0x2070
movq -0x40(%rbp), %r14
incq %r14
movq -0x58(%rbp), %rax
addq %rax, -0x60(%rbp)
jmp 0x45bc
movq -0x48(%rbp), %rdi
callq 0x2040
movq -0x30(%rbp), %rdi
callq 0x2040
pushq $0xa
popq %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050