// File: /workspace/github_c_makefile_star2_O2/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 $0x2028, %rsp           # imm = 0x2028
movq %rdi, %r13
leaq 0x20(%rsp), %rdx
pushq $0x1
popq %rdi
leaq 0x5a47(%rip), %r15      # 0x9473
pushq $0x6
popq %rbx
xorl %ebp, %ebp
movq %rbp, %r8
negq %r8
movq %r13, %r14
movb (%r14), %al
testb %al, %al
je 0x3c75
cmpq $0x1ffe, %rbp           # imm = 0x1FFE
jg 0x3c8c
leaq 0x1(%r14), %rcx
cmpb $0x25, %al
jne 0x3a6a
cmpb $0x25, (%rcx)
jne 0x3a79
movb $0x25, 0x20(%rsp,%rbp)
addq $0x2, %r14
jmp 0x3a71
movb %al, 0x20(%rsp,%rbp)
movq %rcx, %r14
decq %r8
incq %rbp
jmp 0x3a3a
movq %rsi, 0x18(%rsp)
movq %r8, 0x10(%rsp)
subq %r8, %rdx
movq %rdx, 0x8(%rsp)
movq %rdi, %rcx
movq %r14, %r12
movq %r12, %r13
movq %rcx, %rbp
incq %r12
movsbl 0x1(%r13), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2160
leaq 0x1(%rbp), %rcx
testq %rax, %rax
jne 0x3a91
callq 0x22f0
movq (%rax), %rax
movq %rbp, %rsi
movsbq 0x1(%r13), %rcx
incq %r13
incq %rbp
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x3abb
xorl %edx, %edx
cmpb $0x2e, %cl
sete %dl
addq %rdx, %r13
addq %rdx, %rsi
movsbq (%r13), %rbp
incq %r13
incq %rsi
testb $0x8, 0x1(%rax,%rbp,2)
jne 0x3ade
movq %r14, %rdi
callq 0x2170
testq %rax, %rax
je 0x3c8c
movq %rax, %r12
movzbl %bpl, %eax
leal -0x61(%rax), %ecx
cmpl $0x17, %ecx
ja 0x3b60
leaq 0x5549(%rip), %rdx      # 0x9060
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
jmpq *%rax
testq %rcx, %rcx
je 0x3cbc
cmpl $0x0, 0x10(%rcx)
jne 0x3cbc
leaq 0x2000(%r8), %rsi
cvttsd2si 0x8(%rcx), %ecx
movq 0x8(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
movq %r8, %rbx
callq 0x2130
jmp 0x3be2
leal -0x45(%rax), %ecx
cmpl $0x3, %ecx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
jb 0x3bb1
cmpl $0x41, %eax
je 0x3bb1
cmpl $0x58, %eax
je 0x3b2a
movq %r12, %rdi
callq 0x20f0
movq 0x10(%rsp), %rbx
movq %rax, %rbp
movslq %ebp, %rax
leaq 0x2000(%rbx), %rcx
cmpq %rcx, %rax
jge 0x3c8f
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2060
jmp 0x3be4
testq %rcx, %rcx
je 0x3cbc
cmpl $0x0, 0x10(%rcx)
jne 0x3cbc
leaq 0x2000(%r8), %rsi
movsd 0x8(%rcx), %xmm0
movq 0x8(%rsp), %rdi
movq %r12, %rdx
movb $0x1, %al
movq %r8, %rbx
callq 0x2130
movl %eax, %ebp
movslq %ebp, %rbp
leaq 0x2001(%rbx), %rax
cmpq %rbp, %rax
jl 0x3c8f
subq %rbx, %rbp
movq 0x18(%rsp), %rbx
movq (%rbx), %rbx
movq %r12, %rdi
callq 0x2030
movq %rbx, %rsi
leaq 0x20(%rsp), %rdx
pushq $0x1
popq %rdi
pushq $0x6
popq %rbx
jmp 0x3a31
testq %rcx, %rcx
je 0x3cbc
cmpl $0x0, 0x10(%rcx)
je 0x3cbc
leaq 0x2000(%r8), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rcx
movq 0x8(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
movq %r8, %rbx
callq 0x2130
jmp 0x3be2
testq %rcx, %rcx
je 0x3cbc
cmpl $0x0, 0x10(%rcx)
je 0x3cbc
leaq 0x2000(%r8), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %ecx
jmp 0x3b49
movb $0x0, 0x20(%rsp,%rbp)
leaq 0x20(%rsp), %rdi
callq 0x22c0
movq %rax, %rbx
testq %rax, %rax
jne 0x3ca7
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x2030
leaq 0x5462(%rip), %rdi      # 0x9100
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2564
movq %rbx, %rax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x2030
leaq 0x57ae(%rip), %rdi      # 0x9479
jmp 0x3c9e