// File: /workspace/github_cpp_makefile_star2_O1/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 0x428e7
incl %ebp
testl %eax, %eax
jne 0x42a98
jmp 0x42c13
incq %r15
movq %r15, %r13
movzbl (%r13), %eax
cmpl $0x2a, %eax
jg 0x42908
cmpl $0x20, %eax
je 0x42912
movl $0x2, %ecx
cmpl $0x23, %eax
je 0x42917
jmp 0x4291e
cmpl $0x2d, %eax
je 0x42912
cmpl $0x2b, %eax
jne 0x4291e
movl $0x1, %ecx
addl %ecx, %ebp
incq %r13
jmp 0x428ed
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x4760
movq (%rsp), %r15
cmpq %r15, %r13
je 0x4293c
movq %rax, %r14
jmp 0x42976
cmpb $0x2a, (%r13)
jne 0x42959
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x42961
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x4296d
movq %r13, %r15
xorl %r14d, %r14d
jmp 0x42976
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movslq (%rax), %r14
incq %r13
movq %r13, %r15
cmpb $0x2e, (%r15)
jne 0x4299e
leaq 0x1(%r15), %r13
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x4760
movq (%rsp), %rcx
cmpq %r13, %rcx
je 0x429a5
movq %rcx, %r13
jmp 0x429d8
xorl %eax, %eax
movq %r14, %r12
jmp 0x429e5
cmpb $0x2a, (%r13)
jne 0x429d8
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x429c2
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x429ce
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 0x429f2
incq %r15
jmp 0x42a0d
cmpb $0x6c, %cl
jne 0x42a0d
cmpb $0x6c, 0x1(%r15)
jne 0x42aa0
addq $0x2, %r15
movb $0x1, %sil
xorl %edx, %edx
jmp 0x42a11
xorl %edx, %edx
xorl %esi, %esi
movzbl (%r15), %edi
cmpl $0x57, %edi
jle 0x42a52
leal -0x61(%rdi), %r8d
cmpl $0x17, %r8d
ja 0x42abc
leaq 0x12e09(%rip), %r9      # 0x55838
movslq (%r9,%r8,4), %rdi
addq %r9, %rdi
jmpq *%rdi
movl (%rbx), %eax
cmpb $0x68, %cl
je 0x42a46
testb %dl, %dl
jne 0x42a46
testb %sil, %sil
cmpl $0x28, %eax
ja 0x42a73
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x42a78
cmpl $0x25, %edi
je 0x42aaa
cmpl $0x45, %edi
je 0x42a61
cmpl $0x47, %edi
jne 0x42a98
movl 0x4(%rbx), %eax
cmpl $0xa0, %eax
ja 0x42a83
addl $0x10, %eax
movl %eax, 0x4(%rbx)
jmp 0x42a88
addq $0x8, 0x8(%rbx)
cmpq $0x18, %r12
movl $0x17, %eax
jmp 0x42a91
addq $0x8, 0x8(%rbx)
cmpq $0xe, %r12
movl $0xd, %eax
cmovlq %rax, %r12
addl %r12d, %ebp
incq %r15
jmp 0x428cf
incq %r15
movb $0x1, %dl
jmp 0x42a0f
cmpq $0x2, %r14
movl $0x1, %eax
cmovlq %rax, %r14
jmp 0x42bf8
cmpl $0x58, %edi
je 0x42a38
jmp 0x42a98
movl (%rbx), %ecx
cmpq $0x28, %rcx
ja 0x42b31
movq %rcx, %rax
addq 0x10(%rbx), %rax
addl $0x8, %ecx
movl %ecx, (%rbx)
jmp 0x42b3d
movl (%rbx), %edx
cmpq $0x28, %rdx
ja 0x42b7c
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x8, %edx
movl %edx, (%rbx)
jmp 0x42b88
movl 0x4(%rbx), %edx
cmpq $0xa0, %rdx
ja 0x42ba7
movq %rdx, %rcx
addq 0x10(%rbx), %rcx
addl $0x10, %edx
movl %edx, 0x4(%rbx)
jmp 0x42bb3
movl (%rbx), %eax
cmpl $0x28, %eax
ja 0x42c00
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x42c05
movq 0x8(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rbx)
movl (%rax), %r12d
movl $0x1, %ecx
cmpl $0x80, %r12d
jl 0x42b56
callq 0x40b0
movq %rax, %rcx
cmpq %rcx, %r14
movl $0x1, %eax
cmovaq %r14, %rax
cmpl $0x80, %r12d
jl 0x42b75
cmpq %rcx, %r14
ja 0x42b75
callq 0x40b0
addl %eax, %ebp
jmp 0x42a98
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
testq %rax, %rax
jne 0x42a95
movq (%rcx), %rdi
callq 0x4230
cltq
cmpq %rax, %r12
cmovleq %rax, %r12
jmp 0x42a95
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movsd (%rcx), %xmm0
movapd %xmm0, %xmm1
xorpd 0x12c5d(%rip), %xmm1    # 0x55820
maxsd %xmm1, %xmm0
ucomisd 0x12c61(%rip), %xmm0    # 0x55830
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 0x42a98
addq $0x8, 0x8(%rbx)
cmpq $0x15, %r12
movl $0x14, %eax
jmp 0x42a91
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq