// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x418c8
incl %ebp
testl %eax, %eax
jne 0x41bae
jmp 0x41bc9
cmpl $0x2d, %eax
je 0x418c1
cmpl $0x2b, %eax
jne 0x418e3
movl $0x1, %ecx
addl %ecx, %ebp
incq %r15
movzbl (%r15), %eax
cmpl $0x2a, %eax
jg 0x418b7
cmpl $0x20, %eax
je 0x418c1
movl $0x2, %ecx
cmpl $0x23, %eax
je 0x418c6
movq %r15, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x4760
movq %rax, %r14
movq (%rsp), %rax
cmpq %rax, %r15
je 0x41904
movq %rax, %r15
jmp 0x4193c
movb (%r15), %cl
cmpb $0x2a, %cl
jne 0x41922
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x41927
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x41933
xorl %r14d, %r14d
jmp 0x4193e
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 0x41965
leaq 0x1(%r15), %r13
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x4760
movq (%rsp), %rcx
cmpq %r13, %rcx
je 0x4196c
movq %rcx, %r13
jmp 0x4199f
xorl %eax, %eax
movq %r14, %r12
jmp 0x419b0
cmpb $0x2a, (%r13)
jne 0x4199f
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x41989
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x41995
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 0x419d1
cmpb $0x6c, %cl
jne 0x419dc
movb 0x1(%r15), %dil
movl $0x2, %esi
cmpb $0x6c, %dil
jne 0x419e2
movb (%r15,%rsi), %dil
addq %rsi, %r15
xorl %esi, %esi
jmp 0x419ea
xorl %esi, %esi
movl %ecx, %edi
jmp 0x419e8
incq %r15
movb $0x1, %sil
xorl %edx, %edx
movzbl %dil, %edi
cmpl $0x57, %edi
jle 0x41a2b
leal -0x61(%rdi), %r8d
cmpl $0x17, %r8d
ja 0x41a8c
leaq 0x120f0(%rip), %r9      # 0x53af8
movslq (%r9,%r8,4), %rdi
addq %r9, %rdi
jmpq *%rdi
movl (%rbx), %eax
cmpb $0x68, %cl
je 0x41a1f
testb %sil, %sil
jne 0x41a1f
testb %dl, %dl
cmpl $0x28, %eax
ja 0x41a50
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x41a55
cmpl $0x25, %edi
je 0x41a7a
cmpl $0x45, %edi
je 0x41a3e
cmpl $0x47, %edi
jne 0x41bae
movl 0x4(%rbx), %eax
cmpl $0xa0, %eax
ja 0x41a60
addl $0x10, %eax
movl %eax, 0x4(%rbx)
jmp 0x41a65
addq $0x8, 0x8(%rbx)
cmpq $0x18, %r12
movl $0x17, %eax
jmp 0x41a6e
addq $0x8, 0x8(%rbx)
cmpq $0xe, %r12
movl $0xd, %eax
cmovlq %rax, %r12
addl %r12d, %ebp
jmp 0x41bae
cmpq $0x2, %r14
movl $0x1, %eax
cmovlq %rax, %r14
jmp 0x41bab
cmpl $0x58, %edi
je 0x41a11
jmp 0x41bae
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x41af9
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x41b05
movl (%rbx), %edx
cmpq $0x28, %rdx
ja 0x41b2f
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x8, %edx
movl %edx, (%rbx)
jmp 0x41b3b
movl 0x4(%rbx), %edx
cmpq $0xa0, %rdx
ja 0x41b5a
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x10, %edx
movl %edx, 0x4(%rbx)
jmp 0x41b66
movl (%rbx), %eax
cmpl $0x28, %eax
ja 0x41bb6
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x41bbb
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
cmpl $0x7f, (%rax)
jg 0x41b17
cmpq $0x1, %r14
adcq $0x0, %r14
jmp 0x41bab
callq 0x40b0
cmpq %rax, %r14
ja 0x41bab
callq 0x40b0
movq %rax, %r14
jmp 0x41bab
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
testq %rax, %rax
jne 0x41a72
movq (%rcx), %rdi
callq 0x4230
cltq
cmpq %rax, %r12
cmovleq %rax, %r12
jmp 0x41a72
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movsd (%rcx), %xmm0
movapd %xmm0, %xmm1
xorpd 0x11f6a(%rip), %xmm1    # 0x53ae0
maxsd %xmm1, %xmm0
ucomisd 0x11f6e(%rip), %xmm0    # 0x53af0
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 0x4189f
addq $0x8, 0x8(%rbx)
cmpq $0x15, %r12
movl $0x14, %eax
jmp 0x41a6e
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop