// File: /workspace/github_c_makefile_star2_O2/liuhaotian[P]xmppsh/libstrophe/src/snprintf.c
// Function: fmtint
static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
		   long value, int base, int min, int max, int flags)
{
  int signvalue = 0;
  unsigned long uvalue;
  char convert[20];
  int place = 0;
  int spadlen = 0; /* amount to space pad */
  int zpadlen = 0; /* amount to zero pad */
  int caps = 0;
  int total = 0;
  
  if (max < 0)
    max = 0;

  uvalue = value;

  if(!(flags & DP_F_UNSIGNED))
  {
    if( value < 0 ) {
      signvalue = '-';
      uvalue = -value;
    }
    else
      if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
	signvalue = '+';
    else
      if (flags & DP_F_SPACE)
	signvalue = ' ';
  }
  
  if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */

  do {
    convert[place++] =
      (caps? "0123456789ABCDEF":"0123456789abcdef")
      [uvalue % (unsigned)base  ];
    uvalue = (uvalue / (unsigned)base );
  } while(uvalue && (place < 20));
  if (place == 20) place--;
  convert[place] = 0;

  zpadlen = max - place;
  spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
  if (zpadlen < 0) zpadlen = 0;
  if (spadlen < 0) spadlen = 0;
  if (flags & DP_F_ZERO)
  {
    zpadlen = MAX(zpadlen, spadlen);
    spadlen = 0;
  }
  if (flags & DP_F_MINUS) 
    spadlen = -spadlen; /* Left Justifty */

#ifdef DEBUG_SNPRINTF
  dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
      zpadlen, spadlen, min, max, place));
#endif

  /* Spaces */
  while (spadlen > 0) 
  {
    total += dopr_outch (buffer, currlen, maxlen, ' ');
    --spadlen;
  }

  /* Sign */
  if (signvalue) 
    total += dopr_outch (buffer, currlen, maxlen, signvalue);

  /* Zeros */
  if (zpadlen > 0) 
  {
    while (zpadlen > 0)
    {
      total += dopr_outch (buffer, currlen, maxlen, '0');
      --zpadlen;
    }
  }

  /* Digits */
  while (place > 0) 
    total += dopr_outch (buffer, currlen, maxlen, convert[--place]);
  
  /* Left Justified spaces */
  while (spadlen < 0) {
    total += dopr_outch (buffer, currlen, maxlen, ' ');
    ++spadlen;
  }

  return total;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %r10
movq %rdx, %rcx
movl 0x40(%rsp), %r11d
movl 0x38(%rsp), %r14d
xorl %ebx, %ebx
testl %r14d, %r14d
cmovlel %ebx, %r14d
testb $0x40, %r11b
jne 0xa5c0
testq %r10, %r10
js 0xa5c5
testb $0x2, %r11b
jne 0xa5cc
movl %r11d, %ebx
andl $0x4, %ebx
sete %bpl
shlb $0x3, %bl
jmp 0xa5d0
movb $0x1, %bpl
jmp 0xa5d0
negq %r10
movb $0x2d, %bl
jmp 0xa5ce
movb $0x2b, %bl
xorl %ebp, %ebp
testb $0x20, %r11b
leaq 0x2b1e(%rip), %rax      # 0xd0f9
leaq 0x2b06(%rip), %r15      # 0xd0e8
cmoveq %rax, %r15
movl %r8d, %r8d
xorl %r12d, %r12d
movq %r10, %rax
xorl %edx, %edx
divq %r8
movb (%r15,%rdx), %r13b
leaq 0x1(%r12), %rdx
movb %r13b, -0x18(%rsp,%r12)
cmpq %r8, %r10
jb 0xa613
movq %rax, %r10
cmpq $0x13, %r12
movq %rdx, %r12
jb 0xa5ec
leaq -0x1(%rdx), %r8
cmpq $0x14, %rdx
cmovneq %rdx, %r8
movl %r8d, %edx
movb $0x0, -0x18(%rsp,%rdx)
movl %r14d, %eax
subl %r8d, %eax
cmovgl %r14d, %r8d
movl %ebp, %r10d
xorb $0x1, %r10b
movzbl %r10b, %r10d
subl %r10d, %r9d
subl %r8d, %r9d
xorl %r10d, %r10d
testl %r9d, %r9d
cmovlel %r10d, %r9d
testb $0x10, %r11b
movl $0x0, %r14d
cmovel %r9d, %r14d
movl %r14d, %r8d
negl %r8d
testb $0x1, %r11b
cmovel %r14d, %r8d
leal (%r8,%r10), %r14d
testl %r14d, %r14d
jle 0xa68a
movq (%rsi), %r14
leaq 0x1(%r14), %r15
cmpq %rcx, %r15
jae 0xa685
movq %r15, (%rsi)
movb $0x20, (%rdi,%r14)
decl %r10d
jmp 0xa668
xorl %r14d, %r14d
testl %eax, %eax
cmovgl %eax, %r14d
cmpl %r9d, %r14d
cmoval %r14d, %r9d
testb $0x10, %r11b
cmovel %r14d, %r9d
testb %bpl, %bpl
je 0xa6af
negl %r10d
movl %r10d, %eax
jmp 0xa6c9
movq (%rsi), %rax
leaq 0x1(%rax), %r11
cmpq %rcx, %r11
jae 0xa6c1
movq %r11, (%rsi)
movb %bl, (%rdi,%rax)
movl $0x1, %eax
subl %r10d, %eax
movl %r8d, %r10d
sarl $0x1f, %r10d
testl %r9d, %r9d
je 0xa6f1
addl %r9d, %eax
movq (%rsi), %r11
leaq 0x1(%r11), %rbx
cmpq %rcx, %rbx
jae 0xa6ec
movq %rbx, (%rsi)
movb $0x30, (%rdi,%r11)
decl %r9d
jne 0xa6d8
andl %r8d, %r10d
testl %edx, %edx
jle 0xa717
movq (%rsi), %r8
leaq 0x1(%r8), %r9
cmpq %rcx, %r9
jae 0xa710
movb -0x19(%rsp,%rdx), %r11b
movq %r9, (%rsi)
movb %r11b, (%rdi,%r8)
incl %eax
decq %rdx
jmp 0xa6f4
xorl %edx, %edx
cmpl %edx, %r10d
je 0xa736
movq (%rsi), %r8
leaq 0x1(%r8), %r9
cmpq %rcx, %r9
jae 0xa732
movq %r9, (%rsi)
movb $0x20, (%rdi,%r8)
decl %edx
jmp 0xa719
subl %edx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop