// File: /workspace/github_c_makefile_star2_O3/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 0x40f7
movq %rdi, %r13
leaq 0x10(%rsp), %r12
xorl %ebp, %ebp
movq %rbp, %rbx
negq %rbx
movq %r13, %r14
cmpq $0x1ffe, %rbp           # imm = 0x1FFE
jg 0x411b
leaq 0x1(%r14), %rcx
cmpb $0x25, %al
jne 0x3eea
cmpb $0x25, (%rcx)
jne 0x3f0a
movb $0x25, (%r12)
addq $0x2, %r14
movq %r14, %rcx
jmp 0x3ef1
movb %al, (%r12)
movq %rcx, %r14
incq %rbp
leaq (%rsp,%rbp), %r12
addq $0x10, %r12
movb (%rcx), %al
decq %rbx
testb %al, %al
jne 0x3ec2
jmp 0x40fe
movq %rsi, 0x8(%rsp)
movl $0x1, %ecx
movq %r14, %r15
movq %r15, %r13
movq %rcx, %rbp
incq %r15
movsbl 0x1(%r13), %esi
movl $0x6, %edx
leaq 0x554a(%rip), %rdi      # 0x947b
callq 0x2160
leaq 0x1(%rbp), %rcx
testq %rax, %rax
jne 0x3f17
callq 0x22f0
movq (%rax), %rax
movq %rbp, %rsi
movsbq 0x1(%r13), %rcx
incq %r13
incq %rbp
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x3f47
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 0x3f6a
movq %r14, %rdi
callq 0x2170
testq %rax, %rax
je 0x411b
movq %rax, %r15
movzbl %bpl, %eax
cmpl $0x60, %eax
jle 0x3fe4
addl $-0x61, %eax
cmpl $0x17, %eax
movq 0x8(%rsp), %rcx
ja 0x3ffb
leaq 0x50d3(%rip), %rdx      # 0x9080
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
testq %rcx, %rcx
je 0x414b
cmpl $0x0, 0x10(%rcx)
jne 0x414b
leaq 0x2000(%rbx), %rsi
cvttsd2si 0x8(%rcx), %ecx
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x4055
leal -0x45(%rax), %ecx
cmpl $0x3, %ecx
movq 0x8(%rsp), %rcx
jb 0x4029
cmpl $0x41, %eax
je 0x4029
cmpl $0x58, %eax
je 0x3fb6
movq %r15, %rdi
callq 0x20f0
movq %rax, %r14
movslq %r14d, %rax
leaq 0x2000(%rbx), %rcx
cmpq %rcx, %rax
jge 0x411e
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2060
jmp 0x4058
testq %rcx, %rcx
je 0x414b
cmpl $0x0, 0x10(%rcx)
jne 0x414b
leaq 0x2000(%rbx), %rsi
movsd 0x8(%rcx), %xmm0
movq %r12, %rdi
movq %r15, %rdx
movb $0x1, %al
callq 0x2130
movl %eax, %r14d
movslq %r14d, %r14
leaq 0x2001(%rbx), %rax
cmpq %r14, %rax
jl 0x411e
movq %r14, %rbp
subq %rbx, %rbp
movq 0x8(%rsp), %r12
movq (%r12), %r12
movq %r15, %rdi
callq 0x2030
movq %r12, %rsi
leaq (%rsp,%r14), %rcx
addq $0x10, %rcx
movq %rcx, %r12
subq %rbx, %r12
movb (%r13), %al
testb %al, %al
jne 0x3eb9
jmp 0x4103
testq %rcx, %rcx
je 0x414b
cmpl $0x0, 0x10(%rcx)
je 0x414b
leaq 0x2000(%rbx), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %ecx
jmp 0x3fd5
testq %rcx, %rcx
je 0x414b
cmpl $0x0, 0x10(%rcx)
je 0x414b
leaq 0x2000(%rbx), %rsi
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rcx
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x4055
leaq 0x10(%rsp), %rcx
jmp 0x4106
leaq 0x10(%rsp), %rcx
subq %rbx, %rcx
movb $0x0, (%rcx)
leaq 0x10(%rsp), %rdi
callq 0x22c0
movq %rax, %rbx
testq %rax, %rax
jne 0x4136
xorl %r15d, %r15d
movq %r15, %rdi
callq 0x2030
leaq 0x4fdb(%rip), %rdi      # 0x9108
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x270e
movq %rbx, %rax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2030
leaq 0x5327(%rip), %rdi      # 0x9481
jmp 0x412d