// File: /workspace/github_c_makefile_star2_O1/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 0x65c6b
incl %ebp
testl %eax, %eax
jne 0x65e1c
jmp 0x65f97
incq %r15
movq %r15, %r13
movzbl (%r13), %eax
cmpl $0x2a, %eax
jg 0x65c8c
cmpl $0x20, %eax
je 0x65c96
movl $0x2, %ecx
cmpl $0x23, %eax
je 0x65c9b
jmp 0x65ca2
cmpl $0x2d, %eax
je 0x65c96
cmpl $0x2b, %eax
jne 0x65ca2
movl $0x1, %ecx
addl %ecx, %ebp
incq %r13
jmp 0x65c71
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x6a60
movq (%rsp), %r15
cmpq %r15, %r13
je 0x65cc0
movq %rax, %r14
jmp 0x65cfa
cmpb $0x2a, (%r13)
jne 0x65cdd
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65ce5
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65cf1
movq %r13, %r15
xorl %r14d, %r14d
jmp 0x65cfa
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movslq (%rax), %r14
incq %r13
movq %r13, %r15
cmpb $0x2e, (%r15)
jne 0x65d22
leaq 0x1(%r15), %r13
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x6a60
movq (%rsp), %rcx
cmpq %r13, %rcx
je 0x65d29
movq %rcx, %r13
jmp 0x65d5c
xorl %eax, %eax
movq %r14, %r12
jmp 0x65d69
cmpb $0x2a, (%r13)
jne 0x65d5c
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65d46
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65d52
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
movq %r13, %r15
movb (%r15), %cl
cmpb $0x68, %cl
jne 0x65d76
incq %r15
jmp 0x65d91
cmpb $0x6c, %cl
jne 0x65d91
cmpb $0x6c, 0x1(%r15)
jne 0x65e24
addq $0x2, %r15
movb $0x1, %sil
xorl %edx, %edx
jmp 0x65d95
xorl %edx, %edx
xorl %esi, %esi
movzbl (%r15), %edi
cmpl $0x57, %edi
jle 0x65dd6
leal -0x61(%rdi), %r8d
cmpl $0x17, %r8d
ja 0x65e40
leaq 0x33c05(%rip), %r9      # 0x999b8
movslq (%r9,%r8,4), %rdi
addq %r9, %rdi
jmpq *%rdi
movl (%rbx), %eax
cmpb $0x68, %cl
je 0x65dca
testb %dl, %dl
jne 0x65dca
testb %sil, %sil
cmpl $0x28, %eax
ja 0x65df7
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x65dfc
cmpl $0x25, %edi
je 0x65e2e
cmpl $0x45, %edi
je 0x65de5
cmpl $0x47, %edi
jne 0x65e1c
movl 0x4(%rbx), %eax
cmpl $0xa0, %eax
ja 0x65e07
addl $0x10, %eax
movl %eax, 0x4(%rbx)
jmp 0x65e0c
addq $0x8, 0x8(%rbx)
cmpq $0x18, %r12
movl $0x17, %eax
jmp 0x65e15
addq $0x8, 0x8(%rbx)
cmpq $0xe, %r12
movl $0xd, %eax
cmovlq %rax, %r12
addl %r12d, %ebp
incq %r15
jmp 0x65c53
incq %r15
movb $0x1, %dl
jmp 0x65d93
cmpq $0x2, %r14
movl $0x1, %eax
cmovlq %rax, %r14
jmp 0x65f7c
cmpl $0x58, %edi
je 0x65dbc
jmp 0x65e1c
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x65eb5
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x65ec1
movl (%rbx), %edx
cmpq $0x28, %rdx
ja 0x65f00
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x8, %edx
movl %edx, (%rbx)
jmp 0x65f0c
movl 0x4(%rbx), %edx
cmpq $0xa0, %rdx
ja 0x65f2b
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x10, %edx
movl %edx, 0x4(%rbx)
jmp 0x65f37
movl (%rbx), %eax
cmpl $0x28, %eax
ja 0x65f84
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x65f89
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movl (%rax), %r12d
movl $0x1, %ecx
cmpl $0x80, %r12d
jl 0x65eda
callq 0x60f0
movq %rax, %rcx
cmpq %rcx, %r14
movl $0x1, %eax
cmovaq %r14, %rax
cmpl $0x80, %r12d
jl 0x65ef9
cmpq %rcx, %r14
ja 0x65ef9
callq 0x60f0
addl %eax, %ebp
jmp 0x65e1c
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
testq %rax, %rax
jne 0x65e19
movq (%rcx), %rdi
callq 0x62d0
cltq
cmpq %rax, %r12
cmovleq %rax, %r12
jmp 0x65e19
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movsd (%rcx), %xmm0
movapd %xmm0, %xmm1
xorpd 0x31c19(%rip), %xmm1    # 0x97b60
maxsd %xmm1, %xmm0
ucomisd 0x33a5d(%rip), %xmm0    # 0x999b0
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
jmp 0x65e1c
addq $0x8, 0x8(%rbx)
cmpq $0x15, %r12
movl $0x14, %eax
jmp 0x65e15
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq