// File: /workspace/github_c_makefile_star2_O1/phillbush[P]hoc/code.c
// Function: format
static char *
format(char *s, Datum *p)
{
	char buf[BUFSIZ];
	char *fmt, *save, *t;
	int n;

	fmt = NULL;
	t = buf; 
	while (*s) {
		if (t + 1 >= buf + sizeof buf)
			goto error;
		if (*s != '%') {
			*t++ = *s++;
			continue;
		}
		if (*(s+1) == '%') {
			*t++ = '%';
			s += 2;
			continue;
		}
		save = s++;
		while (strchr("#-+ 0", *s))
			s++;
		while (isdigit(*s))
			s++;
		if (*s == '.')
			s++;
		while (isdigit(*s))
			s++;
		if ((fmt = strndup(save, s - save + 1)) == NULL)
			goto error;
		switch (*s) {
		case 'd':
		case 'i':
		case 'o':
		case 'u':
		case 'X':
		case 'x':
			/* int */
			if (!p || p->isstr)
				goto wrong;
			n = snprintf(t, BUFSIZ - (t - buf), fmt, (int)p->u.val);
			break;
		case 'f':
		case 'F':
		case 'e':
		case 'E':
		case 'g':
		case 'G':
		case 'a':
		case 'A':
			/* double */
			if (!p || p->isstr)
				goto wrong;
			n = snprintf(t, BUFSIZ - (t - buf), fmt, p->u.val);
			break;
		case 'c':
			/* char */
			if (!p || !p->isstr)
				goto wrong;
			n = snprintf(t, BUFSIZ - (t - buf), fmt, *p->u.str->s);
			break;
		case 's':
			/* string */
			if (!p || !p->isstr)
				goto wrong;
			n = snprintf(t, BUFSIZ - (t - buf), fmt, p->u.str->s);
			break;
		default:
			if ((n = strlen(fmt)) < BUFSIZ - (t - buf))
				strncpy(t, fmt, strlen(fmt));
			else
				goto error;
			break;
		}
		s++;
		if (n > BUFSIZ - (t - buf) + 1)
			goto error;
		t += n;
		p = p->next;
		free(fmt);
		fmt = NULL;
	}
	*t = '\0';
	if ((s = strdup(buf)) == NULL)
		goto error;
	return s;

wrong:
	free(fmt);
	warning("wrong format");
	return NULL;

error:
	free(fmt);
	warning("out of memory");
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movb (%rdi), %al
testb %al, %al
je 0x416f
movq %rdi, %rbp
leaq 0x10(%rsp), %r13
xorl %ebx, %ebx
movq %rbx, %r14
negq %r14
movq %rbp, %r15
cmpq $0x1ffe, %rbx           # imm = 0x1FFE
jg 0x4176
leaq 0x1(%r15), %rcx
cmpb $0x25, %al
jne 0x3f5e
cmpb $0x25, (%rcx)
jne 0x3f7e
movb $0x25, (%r13)
addq $0x2, %r15
movq %r15, %rcx
jmp 0x3f65
movb %al, (%r13)
movq %rcx, %r15
incq %rbx
leaq (%rsp,%rbx), %r13
addq $0x10, %r13
movb (%rcx), %al
decq %r14
testb %al, %al
jne 0x3f36
jmp 0x4182
movq %rsi, 0x8(%rsp)
movl $0x1, %ecx
movq %r15, %r12
movq %r12, %rbp
movq %rcx, %rbx
incq %r12
movsbl 0x1(%rbp), %esi
movl $0x6, %edx
leaq 0x54d7(%rip), %rdi      # 0x947b
callq 0x2160
leaq 0x1(%rbx), %rcx
testq %rax, %rax
jne 0x3f8b
callq 0x22f0
movq (%rax), %rax
movq %rbx, %rsi
movsbq 0x1(%rbp), %rcx
incq %rbp
incq %rbx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x3fba
xorl %edx, %edx
cmpb $0x2e, %cl
sete %dl
addq %rdx, %rbp
addq %rdx, %rsi
movsbq (%rbp), %rbx
incq %rbp
incq %rsi
testb $0x8, 0x1(%rax,%rbx,2)
jne 0x3fdd
movq %r15, %rdi
callq 0x2170
testq %rax, %rax
je 0x4176
movq %rax, %r12
movzbl %bl, %eax
cmpl $0x60, %eax
jle 0x4056
addl $-0x61, %eax
cmpl $0x17, %eax
movq 0x8(%rsp), %rcx
ja 0x406d
leaq 0x5061(%rip), %rdx      # 0x9080
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
testq %rcx, %rcx
je 0x41d2
cmpl $0x0, 0x10(%rcx)
jne 0x41d2
leaq 0x2000(%r14), %rsi
cvttsd2si 0x8(%rcx), %ecx
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x40c7
leal -0x45(%rax), %ecx
cmpl $0x3, %ecx
movq 0x8(%rsp), %rcx
jb 0x409b
cmpl $0x41, %eax
je 0x409b
cmpl $0x58, %eax
je 0x4028
movq %r12, %rdi
callq 0x20f0
movq %rax, %rbx
movslq %ebx, %rax
leaq 0x2000(%r14), %rcx
cmpq %rcx, %rax
jge 0x4179
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2060
jmp 0x40c9
testq %rcx, %rcx
je 0x41d2
cmpl $0x0, 0x10(%rcx)
jne 0x41d2
leaq 0x2000(%r14), %rsi
movsd 0x8(%rcx), %xmm0
movq %r13, %rdi
movq %r12, %rdx
movb $0x1, %al
callq 0x2130
movl %eax, %ebx
movslq %ebx, %r15
leaq 0x2001(%r14), %rax
cmpq %r15, %rax
jl 0x4179
movq %r15, %rbx
subq %r14, %rbx
movq 0x8(%rsp), %r13
movq (%r13), %r13
movq %r12, %rdi
callq 0x2030
movq %r13, %rsi
leaq (%rsp,%r15), %rcx
addq $0x10, %rcx
movq %rcx, %r13
subq %r14, %r13
movb (%rbp), %al
testb %al, %al
jne 0x3f2d
jmp 0x4187
testq %rcx, %rcx
je 0x41d2
cmpl $0x0, 0x10(%rcx)
je 0x41d2
leaq 0x2000(%r14), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %ecx
jmp 0x4047
testq %rcx, %rcx
je 0x41d2
cmpl $0x0, 0x10(%rcx)
je 0x41d2
leaq 0x2000(%r14), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rcx
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x40c7
leaq 0x10(%rsp), %rcx
jmp 0x418a
xorl %r12d, %r12d
leaq 0x4f88(%rip), %r14      # 0x9108
jmp 0x41a9
leaq 0x10(%rsp), %rcx
subq %r14, %rcx
movb $0x0, (%rcx)
leaq 0x10(%rsp), %rdi
callq 0x22c0
movq %rax, %rbx
testq %rax, %rax
jne 0x41bd
leaq 0x4f62(%rip), %r14      # 0x9108
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2722
movq %rbx, %rax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x52a8(%rip), %r14      # 0x9481
jmp 0x41a9