// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/cram/vlen.c
// Function: vflen
int vflen(char *fmt, va_list ap)
{
    int len = 0;
    char *cp, c;
    long long l;
    int i;
    double d; 

    /*
     * This code modifies 'ap', but we do not know if va_list is a structure
     * or a pointer to an array so we do not know if it is a local variable
     * or not.
     * C99 gets around this by defining va_copy() to make copies of ap, but
     * this does not exist on all systems.
     * For now, I just assume that when va_list is a pointer the system also
     * provides a va_copy macro to work around this problem. The only system
     * I have seen needing this so far was Linux on AMD64.
     */
#if defined(HAVE_VA_COPY)
    va_list ap_local;
    va_copy(ap_local, ap);
#    define ap ap_local
#endif

    for(cp = fmt; *cp; cp++) {
	switch(*cp) {

	/* A format specifier */
	case '%': {
	    char *endp;
	    long conv_len1=0, conv_len2=0, conv_len=0;
	    signed int arg_size;

	    /* Firstly, strip the modifier flags (+-#0 and [space]) */
	    for(; (c=*++cp);) {
		if ('#' == c)
		    len+=2; /* Worst case of "0x" */
		else if ('-' == c || '+' == c || ' ' == c)
		    len++;
		else
		    break;
	    }

	    /* Width specifier */
	    l = strtol(cp, &endp, 10);
	    if (endp != cp) {
		cp = endp;
		conv_len = conv_len1 = l;
	    } else if (*cp == '*') {
		conv_len = conv_len1 = (int)va_arg(ap, int);
		cp++;
	    }

	    /* Precision specifier */
	    if ('.' == *cp) {
		cp++;
		conv_len2 = strtol(cp, &endp, 10);
		if (endp != cp) {
		    cp = endp;
		} else if (*cp == '*') {
		    conv_len2 = (int)va_arg(ap, int);
		    cp++;
		}
		conv_len = MAX(conv_len1, conv_len2);
	    }

	    /* Short/long identifier */
	    if ('h' == *cp) {
		arg_size = -1; /* short */
		cp++;
	    } else if ('l' == *cp) {
		arg_size = 1; /* long */
		cp++;
		if ('l' == *cp) {
		    arg_size = 2; /* long long */
		    cp++;
		}
	    } else {
		arg_size = 0; /* int */
	    }

	    /* The actual type */
	    switch (*cp) {
	    case '%':
		/*
		 * Not real ANSI I suspect, but we'll allow for the
		 * completely daft "%10%" example.
		 */
		len += MAX(conv_len1, 1);
		break;

	    case 'd':
	    case 'i':
	    case 'u':
	    case 'a':
	    case 'x':
	    case 'X':
		/* Remember: char and short are sent as int on the stack */
		if (arg_size == -1)
		    l = (long)va_arg(ap, int);
		else if (arg_size == 1)
		    l = va_arg(ap, long); 
		else if (arg_size == 2)
		    l = va_arg(ap, long long); 
		else 
		    l = (long)va_arg(ap, int);

		DEBUG_printf("%d", l);

		/*
		 * No number can be more than 24 characters so we'll take
		 * the max of conv_len and 24 (23 is len(2^64) in octal).
		 * All that work above and we then go and estimate ;-),
		 * but it's needed incase someone does %500d.
		 */
		len += MAX(conv_len, 23);
		break;

	    case 'c':
		i = va_arg(ap, int);
		DEBUG_printf("%c", i);
		/*
		 * Note that %10c and %.10c act differently.
		 * Besides, I think precision is not really allowed for %c.
		 */
		len += MAX(conv_len1, i>=0x80 ?MB_CUR_MAX :1);
		break;

	    case 'f':
		d = va_arg(ap, double);
		DEBUG_printf("%f", d);
		/*
		 * Maybe "Inf" or "NaN", but we'll not worry about that.
		 * Again, err on side of caution and take max of conv_len
		 * and max length of a double. The worst case I can
		 * think of is 317 characters (-1[308 zeros].000000)
		 * without using precision codes. That's horrid. I
		 * cheat and either use 317 or 15 depending on how
		 * large the number is as I reckon 99% of floats
		 * aren't that long.
		 */
		l = (ABS(d) > 1000000) ? 317 : 15;
		l = MAX(l, conv_len1 + 2);
		if (conv_len2) l += conv_len2 - 6;
		len += l;
		break;

	    case 'e':
	    case 'E':
	    case 'g':
	    case 'G':
		d = va_arg(ap, double);
		DEBUG_printf("%g", d);
		/*
		 * Maybe "Inf" or "NaN", but we'll not worry about that
		 * Again, err on side of caution and take max of conv_len
		 * and max length of a double (which defaults to only
		 * '-' + 6 + '.' + 'E[+-]xxx' == 13.
		 */
		len += MAX(conv_len, 13);
		break;

	    case 'p':
		l = (long)va_arg(ap, void *);
		/*
		 * Max pointer is 64bits == 16 chars (on alpha),
		 * == 20 with + "0x".
		 */
		DEBUG_printf("%p", (void *)l);
		len += MAX(conv_len, 20);
		break;

	    case 'n':
		/* produces no output */
		break;

	    case 's': {
		char *s = (char *)va_arg(ap, char *);
		DEBUG_printf("%s", s);

		if (!conv_len2) {
		    len += MAX(conv_len, (int)strlen(s));
		} else {
		    len += conv_len;
		}
		break;
	    }

	    default:
		/* wchar_t types of 'C' and 'S' aren't supported */
		DEBUG_printf("Arg is %c\n", *cp);
	    }
	    
	}

	case '\0':
	    break;

	default:
	    DEBUG_printf("%c", *cp);
	    len++;
	}
    }

    va_end(ap);

    return len+1; /* one for the null character */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r12
pushq $0x2
popq %rbp
pushq $0x1
popq %rbx
xorl %r15d, %r15d
movq %rsi, 0x8(%rsp)
movzbl (%r12), %eax
cmpl $0x25, %eax
je 0x5afb1
incl %r15d
testl %eax, %eax
jne 0x5b2d7
jmp 0x5b2df
movl %ebx, %ecx
addl %ecx, %r15d
incq %r12
movzbl (%r12), %eax
cmpl $0x20, %eax
je 0x5afac
movl %ebp, %ecx
cmpl $0x23, %eax
je 0x5afae
cmpl $0x2d, %eax
je 0x5afac
cmpl $0x2b, %eax
je 0x5afac
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x6a60
movq %rax, %r10
movq 0x10(%rsp), %rax
cmpq %rax, %r12
je 0x5aff1
movq %rax, %r12
jmp 0x5b02c
movb (%r12), %cl
cmpb $0x2a, %cl
jne 0x5b012
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5b017
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5b023
xorl %r10d, %r10d
jmp 0x5b02e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movslq (%rax), %r10
incq %r12
movq %r12, %rax
movb (%rax), %cl
cmpb $0x2e, %cl
jne 0x5b05d
movq %r10, %r13
leaq 0x1(%r12), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x6a60
movq 0x10(%rsp), %rcx
cmpq %r14, %rcx
je 0x5b064
movq %rcx, %r14
movq %r13, %r10
jmp 0x5b09e
xorl %eax, %eax
movq %r10, %r13
jmp 0x5b0b3
cmpb $0x2a, (%r14)
movq %r13, %r10
jne 0x5b09e
movq 0x8(%rsp), %rdx
movl (%rdx), %ecx
cmpq $0x28, %rcx
ja 0x5b088
movq %rcx, %rax
addq 0x10(%rdx), %rax
addl $0x8, %ecx
movl %ecx, (%rdx)
jmp 0x5b094
movq 0x8(%rdx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rdx)
movslq (%rax), %rax
addq $0x2, %r12
movq %r12, %r14
cmpq %rax, %r10
movq %rax, %r13
cmovgq %r10, %r13
movb (%r14), %cl
movq %r14, %r12
movq 0x8(%rsp), %r14
pushq $0x1
popq %rsi
cmpb $0x68, %cl
setne %dl
je 0x5b0d1
cmpb $0x6c, %cl
jne 0x5b0dc
movb 0x1(%r12), %dil
pushq $0x2
popq %rsi
cmpb $0x6c, %dil
jne 0x5b0e2
movb (%r12,%rsi), %dil
addq %rsi, %r12
xorl %esi, %esi
jmp 0x5b0ea
xorl %esi, %esi
movl %ecx, %edi
jmp 0x5b0e8
incq %r12
movb $0x1, %sil
xorl %edx, %edx
movzbl %dil, %edi
leal -0x61(%rdi), %r8d
cmpl $0x17, %r8d
ja 0x5b124
leaq 0x2d879(%rip), %r9      # 0x88978
movslq (%r9,%r8,4), %rdi
addq %r9, %rdi
jmpq *%rdi
movl (%r14), %eax
cmpb $0x68, %cl
je 0x5b117
testb %sil, %sil
jne 0x5b117
testb %dl, %dl
cmpl $0x28, %eax
ja 0x5b160
addl $0x8, %eax
movl %eax, (%r14)
jmp 0x5b165
cmpl $0x58, %edi
je 0x5b108
cmpl $0x45, %edi
je 0x5b14c
cmpl $0x47, %edi
je 0x5b14c
cmpl $0x25, %edi
jne 0x5b2d7
cmpq $0x2, %r10
pushq $0x1
popq %rax
cmovlq %rax, %r10
jmp 0x5b2bf
movl 0x4(%r14), %eax
cmpl $0xa0, %eax
ja 0x5b170
addl $0x10, %eax
movl %eax, 0x4(%r14)
jmp 0x5b175
addq $0x8, 0x8(%r14)
cmpq $0x18, %r13
pushq $0x17
jmp 0x5b2cf
addq $0x8, 0x8(%r14)
cmpq $0xe, %r13
pushq $0xd
jmp 0x5b2cf
movl (%r14), %edx
cmpq $0x28, %rdx
ja 0x5b1eb
movq %rdx, %rcx
addq 0x10(%r14), %rcx
addl $0x8, %edx
movl %edx, (%r14)
jmp 0x5b1f7
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5b216
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5b222
movl 0x4(%r14), %edx
cmpq $0xa0, %rdx
ja 0x5b26f
movq %rdx, %rcx
addq 0x10(%r14), %rcx
addl $0x10, %edx
movl %edx, 0x4(%r14)
jmp 0x5b27b
movl (%r14), %eax
cmpl $0x28, %eax
ja 0x5b2c4
addl $0x8, %eax
movl %eax, (%r14)
jmp 0x5b2c9
movq 0x8(%r14), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r14)
testq %rax, %rax
jne 0x5b2d4
movq (%rcx), %rdi
callq 0x62d0
cltq
cmpq %rax, %r13
cmovleq %rax, %r13
jmp 0x5b2d4
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %r14d
cmpl $0x7f, %r14d
jg 0x5b23d
cmpq $0x1, %r10
adcq $0x0, %r10
movq %r10, %rax
movq 0x8(%rsp), %r14
jmp 0x5b26a
movq %r10, %r13
callq 0x60f0
movq %rax, %rcx
cmpq %rax, %r13
pushq $0x1
popq %rax
cmovaq %r13, %rax
cmpl $0x80, %r14d
jl 0x5b236
cmpq %rcx, %r13
movq 0x8(%rsp), %r14
ja 0x5b26a
callq 0x60f0
addl %eax, %r15d
jmp 0x5b2d7
movq 0x8(%r14), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r14)
movsd (%rcx), %xmm0
movapd %xmm0, %xmm1
xorpd 0x2b8b5(%rip), %xmm1    # 0x86b40
maxsd %xmm1, %xmm0
ucomisd 0x2d6d9(%rip), %xmm0    # 0x88970
pushq $0xf
popq %rcx
movl $0x13d, %edx            # imm = 0x13D
cmovaq %rdx, %rcx
addq $0x2, %r10
cmpq %r10, %rcx
cmovgq %rcx, %r10
leal -0x6(%rax), %ecx
testq %rax, %rax
movl $0x0, %eax
cmovel %eax, %ecx
addl %ecx, %r15d
addl %r10d, %r15d
jmp 0x5b2d7
addq $0x8, 0x8(%r14)
cmpq $0x15, %r13
pushq $0x14
popq %rax
cmovlq %rax, %r13
addl %r13d, %r15d
incq %r12
jmp 0x5af92
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)