// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
xorl %ebp, %ebp
movzbl (%r15), %eax
cmpl $0x25, %eax
je 0x65c70
incl %ebp
testl %eax, %eax
jne 0x65f56
jmp 0x65f71
cmpl $0x2d, %eax
je 0x65c69
cmpl $0x2b, %eax
jne 0x65c8b
movl $0x1, %ecx
addl %ecx, %ebp
incq %r15
movzbl (%r15), %eax
cmpl $0x2a, %eax
jg 0x65c5f
cmpl $0x20, %eax
je 0x65c69
movl $0x2, %ecx
cmpl $0x23, %eax
je 0x65c6e
movq %r15, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x6a60
movq %rax, %r14
movq (%rsp), %rax
cmpq %rax, %r15
je 0x65cac
movq %rax, %r15
jmp 0x65ce4
movb (%r15), %cl
cmpb $0x2a, %cl
jne 0x65cca
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65ccf
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65cdb
xorl %r14d, %r14d
jmp 0x65ce6
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movslq (%rax), %r14
incq %r15
movq %r15, %rax
movb (%rax), %cl
cmpb $0x2e, %cl
jne 0x65d0d
leaq 0x1(%r15), %r13
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x6a60
movq (%rsp), %rcx
cmpq %r13, %rcx
je 0x65d14
movq %rcx, %r13
jmp 0x65d47
xorl %eax, %eax
movq %r14, %r12
jmp 0x65d58
cmpb $0x2a, (%r13)
jne 0x65d47
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65d31
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65d3d
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movslq (%rax), %rax
addq $0x2, %r15
movq %r15, %r13
cmpq %rax, %r14
movq %rax, %r12
cmovgq %r14, %r12
movb (%r13), %cl
movq %r13, %r15
movl $0x1, %esi
cmpb $0x68, %cl
setne %dl
je 0x65d79
cmpb $0x6c, %cl
jne 0x65d84
movb 0x1(%r15), %dil
movl $0x2, %esi
cmpb $0x6c, %dil
jne 0x65d8a
movb (%r15,%rsi), %dil
addq %rsi, %r15
xorl %esi, %esi
jmp 0x65d92
xorl %esi, %esi
movl %ecx, %edi
jmp 0x65d90
incq %r15
movb $0x1, %sil
xorl %edx, %edx
movzbl %dil, %edi
cmpl $0x57, %edi
jle 0x65dd3
leal -0x61(%rdi), %r8d
cmpl $0x17, %r8d
ja 0x65e34
leaq 0x33e38(%rip), %r9      # 0x99be8
movslq (%r9,%r8,4), %rdi
addq %r9, %rdi
jmpq *%rdi
movl (%rbx), %eax
cmpb $0x68, %cl
je 0x65dc7
testb %sil, %sil
jne 0x65dc7
testb %dl, %dl
cmpl $0x28, %eax
ja 0x65df8
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x65dfd
cmpl $0x25, %edi
je 0x65e22
cmpl $0x45, %edi
je 0x65de6
cmpl $0x47, %edi
jne 0x65f56
movl 0x4(%rbx), %eax
cmpl $0xa0, %eax
ja 0x65e08
addl $0x10, %eax
movl %eax, 0x4(%rbx)
jmp 0x65e0d
addq $0x8, 0x8(%rbx)
cmpq $0x18, %r12
movl $0x17, %eax
jmp 0x65e16
addq $0x8, 0x8(%rbx)
cmpq $0xe, %r12
movl $0xd, %eax
cmovlq %rax, %r12
addl %r12d, %ebp
jmp 0x65f56
cmpq $0x2, %r14
movl $0x1, %eax
cmovlq %rax, %r14
jmp 0x65f53
cmpl $0x58, %edi
je 0x65db9
jmp 0x65f56
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65ea1
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65ead
movl (%rbx), %edx
cmpq $0x28, %rdx
ja 0x65ed7
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x8, %edx
movl %edx, (%rbx)
jmp 0x65ee3
movl 0x4(%rbx), %edx
cmpq $0xa0, %rdx
ja 0x65f02
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x10, %edx
movl %edx, 0x4(%rbx)
jmp 0x65f0e
movl (%rbx), %eax
cmpl $0x28, %eax
ja 0x65f5e
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x65f63
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
cmpl $0x7f, (%rax)
jg 0x65ebf
cmpq $0x1, %r14
adcq $0x0, %r14
jmp 0x65f53
callq 0x60f0
cmpq %rax, %r14
ja 0x65f53
callq 0x60f0
movq %rax, %r14
jmp 0x65f53
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
testq %rax, %rax
jne 0x65e1a
movq (%rcx), %rdi
callq 0x62d0
cltq
cmpq %rax, %r12
cmovleq %rax, %r12
jmp 0x65e1a
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movsd (%rcx), %xmm0
movapd %xmm0, %xmm1
xorpd 0x31d22(%rip), %xmm1    # 0x97c40
maxsd %xmm1, %xmm0
ucomisd 0x33cb6(%rip), %xmm0    # 0x99be0
movl $0xf, %ecx
movl $0x13d, %edx            # imm = 0x13D
cmovaq %rdx, %rcx
addq $0x2, %r14
cmpq %r14, %rcx
cmovgq %rcx, %r14
leal -0x6(%rax), %ecx
testq %rax, %rax
movl $0x0, %eax
cmovel %eax, %ecx
addl %ecx, %ebp
addl %r14d, %ebp
incq %r15
jmp 0x65c47
addq $0x8, 0x8(%rbx)
cmpq $0x15, %r12
movl $0x14, %eax
jmp 0x65e16
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop