// File: /workspace/github_cpp_makefile_star2_O2/attractivechaos[P]udb2/stb/./stb.h
// Function: stb_wordwrap
int stb_wordwrap(int *pairs, int pair_max, int count, char *str)
{
   int n=0,i=0, start=0,nonwhite=0;
   if (pairs == NULL) pair_max = 0x7ffffff0;
   else pair_max *= 2;
   // parse 
   for(;;) {
      int s=i; // first whitespace char; last nonwhite+1
      int w;   // word start
      // accept whitespace
      while (isspace(str[i])) {
         if (str[i] == '\n' || str[i] == '\r') {
            if (str[i] + str[i+1] == '\n' + '\r') ++i;
            if (n >= pair_max) return -1;
            if (pairs) pairs[n] = start, pairs[n+1] = s-start;
            n += 2;
            nonwhite=0;
            start = i+1;
            s = start;
         }
         ++i;
      }
      if (i >= start+count) {
         // we've gone off the end using whitespace
         if (nonwhite) {
            if (n >= pair_max) return -1;
            if (pairs) pairs[n] = start, pairs[n+1] = s-start;
            n += 2;
            start = s = i;
            nonwhite=0;
         } else {
            // output all the whitespace
            while (i >= start+count) {
               if (n >= pair_max) return -1;
               if (pairs) pairs[n] = start, pairs[n+1] = count;
               n += 2;
               start += count;
            }
            s = start;
         }
      }

      if (str[i] == 0) break;
      // now scan out a word and see if it fits
      w = i;
      while (str[i] && !isspace(str[i])) {
         ++i;
      }
      // wrapped?
      if (i > start + count) {
         // huge?
         if (i-s <= count) {
            if (n >= pair_max) return -1;
            if (pairs) pairs[n] = start, pairs[n+1] = s-start;
            n += 2;
            start = w;
         } else {
            // This word is longer than one line. If we wrap it onto N lines
            // there are leftover chars. do those chars fit on the cur line?
            // But if we have leading whitespace, we force it to start here.
            if ((w-start) + ((i-w) % count) <= count || !nonwhite) {
               // output a full line
               if (n >= pair_max) return -1;
               if (pairs) pairs[n] = start, pairs[n+1] = count;
               n += 2;
               start += count;
               w = start;
            } else {
               // output a partial line, trimming trailing whitespace
               if (s != start) {
                  if (n >= pair_max) return -1;
                  if (pairs) pairs[n] = start, pairs[n+1] = s-start;
                  n += 2;
                  start = w;
               }
            }
            // now output full lines as needed
            while (start + count <= i) {
               if (n >= pair_max) return -1;
               if (pairs) pairs[n] = start, pairs[n+1] = count;
               n += 2;
               start += count;
            }
         }
      }
      nonwhite=1;
   }
   if (start < i) {
      if (n >= pair_max) return -1;
      if (pairs) pairs[n] = start, pairs[n+1] = i-start;
      n += 2;
   }
   return n>>1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %r15d
movq %rdi, %rbx
addl %esi, %esi
testq %rdi, %rdi
movl $0x7ffffff0, %ebp       # imm = 0x7FFFFFF0
cmovnel %esi, %ebp
callq 0x23b0
movq (%rax), %rsi
movslq %ebp, %rdi
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %r9d, %r9d
xorl %r12d, %r12d
movl %ebp, 0x4(%rsp)
movslq %r12d, %r11
movsbq (%r14,%r11), %rdx
testb $0x20, 0x1(%rsi,%rdx,2)
movslq %r8d, %rax
je 0xb9c3
cmpb $0xa, %dl
je 0xb981
movzbl %dl, %ecx
cmpl $0xd, %ecx
je 0xb981
incq %r11
jmp 0xb960
leal 0x1(%r11), %ecx
movslq %ecx, %rcx
movsbl (%r14,%rcx), %r9d
addl %edx, %r9d
cmpl $0x17, %r9d
cmovnel %r11d, %ecx
cmpl %ebp, %r8d
jge 0xbb39
testq %rbx, %rbx
je 0xb9b2
movl %r10d, (%rbx,%rax,4)
subl %r10d, %r12d
movl %r12d, 0x4(%rbx,%rax,4)
addl $0x2, %r8d
incl %ecx
movl %ecx, %r10d
xorl %r9d, %r9d
movl %ecx, %r12d
jmp 0xb95d
leal (%r10,%r15), %ecx
cmpl %ecx, %r11d
jl 0xba2a
testl %r9d, %r9d
je 0xba18
cmpl %ebp, %r8d
jge 0xbb39
testq %rbx, %rbx
je 0xb9eb
movl %r10d, (%rbx,%rax,4)
subl %r10d, %r12d
movl %r12d, 0x4(%rbx,%rax,4)
addl $0x2, %r8d
xorl %r9d, %r9d
movl %r11d, %r10d
movl %r11d, %r12d
jmp 0xba2a
cmpq %rdi, %rax
jge 0xbb39
testq %rbx, %rbx
je 0xba11
movl %r10d, (%rbx,%rax,4)
movl %r15d, 0x4(%rbx,%rax,4)
addq $0x2, %rax
movl %ecx, %r10d
leal (%r10,%r15), %ecx
cmpl %ecx, %r11d
jge 0xb9fa
xorl %r9d, %r9d
movl %eax, %r8d
movl %r10d, %r12d
movb (%r14,%r11), %dl
movslq %r8d, %rcx
testb %dl, %dl
je 0xbb4b
xorl %eax, %eax
movq %r11, %r13
testb %dl, %dl
je 0xba59
movsbq %dl, %rdx
testb $0x20, 0x1(%rsi,%rdx,2)
jne 0xba59
movb 0x1(%r14,%r13), %dl
incq %r13
incl %eax
jmp 0xba3e
leal (%r10,%r15), %ebp
cmpl %r13d, %ebp
jge 0xba92
movl %r13d, %edx
subl %r12d, %edx
cmpl %r15d, %edx
jle 0xbaa2
cltd
idivl %r15d
subl %r10d, %edx
leal (%r11,%rdx), %eax
cmpl %r15d, %eax
setg %al
testl %r9d, %r9d
setne %dl
testb %dl, %al
je 0xbad3
subl %r10d, %r12d
jne 0xbaee
movl %r10d, %ebp
jmp 0xbb0a
pushq $0x1
popq %r9
movl %r13d, %r12d
movl 0x4(%rsp), %ebp
jmp 0xb95d
movl 0x4(%rsp), %ebp
cmpl %ebp, %r8d
jge 0xbb39
testq %rbx, %rbx
je 0xbac0
movl %r10d, (%rbx,%rcx,4)
subl %r10d, %r12d
movl %r12d, 0x4(%rbx,%rcx,4)
addl $0x2, %r8d
movl %r11d, %r10d
pushq $0x1
popq %r9
movl %r13d, %r12d
jmp 0xb95d
cmpl 0x4(%rsp), %r8d
jge 0xbb39
testq %rbx, %rbx
je 0xbae8
movl %r10d, (%rbx,%rcx,4)
movl %r15d, 0x4(%rbx,%rcx,4)
addl $0x2, %r8d
jmp 0xbb0a
cmpl 0x4(%rsp), %r8d
jge 0xbb39
testq %rbx, %rbx
je 0xbb03
movl %r10d, (%rbx,%rcx,4)
movl %r12d, 0x4(%rbx,%rcx,4)
addl $0x2, %r8d
movl %r11d, %ebp
movslq %r8d, %r8
movl %ebp, %r10d
movl 0x4(%rsp), %ebp
leal (%r10,%r15), %eax
cmpl %r13d, %eax
jg 0xbac7
cmpq %rdi, %r8
jge 0xbb39
testq %rbx, %rbx
je 0xbb30
movl %r10d, (%rbx,%r8,4)
movl %r15d, 0x4(%rbx,%r8,4)
addq $0x2, %r8
movl %eax, %r10d
jmp 0xbb14
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r11d, %r10d
jge 0xbb6d
cmpl %ebp, %r8d
pushq $-0x1
popq %rax
jge 0xbb3c
testq %rbx, %rbx
je 0xbb69
movl %r10d, (%rbx,%rcx,4)
subl %r10d, %r11d
movl %r11d, 0x4(%rbx,%rcx,4)
addl $0x2, %r8d
sarl %r8d
movl %r8d, %eax
jmp 0xbb3c