// File: /workspace/github_c_makefile_star2_O3/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), %ebp
movl 0x38(%rsp), %r14d
xorl %r11d, %r11d
testl %r14d, %r14d
cmovlel %r11d, %r14d
testb $0x40, %bpl
jne 0xa829
testq %r10, %r10
js 0xa82d
testb $0x2, %bpl
jne 0xa835
movl %ebp, %r11d
andl $0x4, %r11d
sete %bl
shlb $0x3, %r11b
jmp 0xa83a
movb $0x1, %bl
jmp 0xa83a
negq %r10
movb $0x2d, %r11b
jmp 0xa838
movb $0x2b, %r11b
xorl %ebx, %ebx
testb $0x20, %bpl
leaq 0x38b4(%rip), %rax      # 0xe0f9
leaq 0x389c(%rip), %r15      # 0xe0e8
cmoveq %rax, %r15
movl %r8d, %r8d
xorl %r12d, %r12d
movq %r10, %rax
xorl %edx, %edx
divq %r8
movb (%r15,%rdx), %dl
leaq 0x1(%r12), %r13
movb %dl, -0x18(%rsp,%r12)
cmpq %r8, %r10
jb 0xa87d
movq %rax, %r10
cmpq $0x13, %r12
movq %r13, %r12
jb 0xa856
leaq -0x1(%r13), %rdx
cmpq $0x14, %r13
cmovneq %r13, %rdx
movl %edx, %r10d
movl %r14d, %eax
subl %edx, %eax
cmovlel %edx, %r14d
movl %ebx, %r8d
xorb $0x1, %r8b
movzbl %r8b, %r8d
subl %r8d, %r9d
subl %r14d, %r9d
xorl %r8d, %r8d
testl %eax, %eax
cmovlel %r8d, %eax
testl %r9d, %r9d
cmovlel %r8d, %r9d
cmpl %r9d, %eax
movl %r9d, %r14d
cmoval %eax, %r14d
movb $0x0, -0x18(%rsp,%r10)
testb $0x10, %bpl
cmovnel %r8d, %r9d
cmovel %eax, %r14d
movl %r9d, %eax
negl %eax
testb $0x1, %bpl
cmovel %r9d, %eax
testl %eax, %eax
jle 0xa904
movl %eax, %r8d
movq (%rsi), %r9
leaq 0x1(%r9), %r15
cmpq %rcx, %r15
jae 0xa8fa
movq %r15, (%rsi)
movb $0x20, (%rdi,%r9)
decl %r8d
jne 0xa8e6
xorl %r8d, %r8d
jmp 0xa909
movl %eax, %r8d
xorl %eax, %eax
testb %bl, %bl
jne 0xa922
movq (%rsi), %r9
leaq 0x1(%r9), %rbx
cmpq %rcx, %rbx
jae 0xa920
movq %rbx, (%rsi)
movb %r11b, (%rdi,%r9)
incl %eax
testl %r14d, %r14d
je 0xa94e
leal 0x1(%r14), %r9d
movq (%rsi), %r11
leaq 0x1(%r11), %rbx
cmpq %rcx, %rbx
jae 0xa93f
movq %rbx, (%rsi)
movb $0x30, (%rdi,%r11)
decl %r9d
cmpl $0x1, %r9d
jg 0xa92b
addl %eax, %r14d
movl %r14d, %eax
testl %edx, %edx
je 0xa981
incl %edx
leaq -0x18(%rsp), %r9
addq %r10, %r9
decq %r9
movq (%rsi), %r10
leaq 0x1(%r10), %r11
cmpq %rcx, %r11
jae 0xa975
movb (%r9), %bl
movq %r11, (%rsi)
movb %bl, (%rdi,%r10)
incl %eax
decl %edx
decq %r9
cmpl $0x1, %edx
jg 0xa95f
testl %r8d, %r8d
jns 0xa9a4
movl %r8d, %edx
movq (%rsi), %r9
leaq 0x1(%r9), %r10
cmpq %rcx, %r10
jae 0xa99d
movq %r10, (%rsi)
movb $0x20, (%rdi,%r9)
incl %edx
jne 0xa989
subl %r8d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop