// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rcx, %r14
movl %edx, %r15d
movq %rdi, %rbx
addl %esi, %esi
testq %rdi, %rdi
movl $0x7ffffff0, %ebp       # imm = 0x7FFFFFF0
cmovnel %esi, %ebp
callq 0x23c0
movq (%rax), %rsi
movl %ebp, 0x8(%rsp)
movslq %ebp, %rdi
leaq 0x1(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %r9d, %r9d
movslq %r10d, %rax
movsbq (%r14,%rax), %rdx
testb $0x20, 0x1(%rsi,%rdx,2)
jne 0xd0a3
movl %r10d, %r12d
jmp 0xd107
movl %r10d, %eax
cmpb $0xd, %dl
je 0xd0b5
movzbl %dl, %r8d
cmpl $0xa, %r8d
jne 0xd0f2
movsbl %dl, %edx
cltq
leaq 0x1(%rax), %r8
movsbl 0x1(%r14,%rax), %ebp
addl %edx, %ebp
cmpl $0x17, %ebp
cmovel %r8d, %eax
cmpl %edi, %ecx
jge 0xd14a
testq %rbx, %rbx
je 0xd0e5
movslq %ecx, %rdx
movl %r11d, (%rbx,%rdx,4)
subl %r11d, %r10d
movl %r10d, 0x4(%rbx,%rdx,4)
addl $0x2, %ecx
leal 0x1(%rax), %r11d
xorl %r9d, %r9d
movl %r11d, %r10d
cltq
movsbq 0x1(%r14,%rax), %rdx
incq %rax
testb $0x20, 0x1(%rsi,%rdx,2)
movl %eax, %r12d
jne 0xd0a6
leal (%r11,%r15), %edx
cmpl %edx, %r12d
jge 0xd115
movl %r10d, %r8d
jmp 0xd18a
testl %r9d, %r9d
je 0xd158
movl $0x1, %r9d
cmpl %edi, %ecx
jge 0xd21a
testq %rbx, %rbx
je 0xd13c
movslq %ecx, %rdx
movl %r11d, (%rbx,%rdx,4)
subl %r11d, %r10d
movl %r10d, 0x4(%rbx,%rdx,4)
addl $0x2, %ecx
xorl %r9d, %r9d
movl %r12d, %r11d
movl %r12d, %r8d
jmp 0xd18a
movl $0x1, %r13d
movl %eax, %r10d
jmp 0xd2ee
cmpl %edx, %r12d
jl 0xd187
movslq %ecx, %rcx
cmpq %rdi, %rcx
jge 0xd271
testq %rbx, %rbx
je 0xd177
movl %r11d, (%rbx,%rcx,4)
movl %r15d, 0x4(%rbx,%rcx,4)
addq $0x2, %rcx
addl %r15d, %r11d
leal (%r15,%r11), %edx
cmpl %edx, %r12d
jge 0xd160
movl %r11d, %r8d
cmpb $0x0, (%r14,%rax)
je 0xd20c
movslq %r12d, %rax
movb (%r14,%rax), %dl
movl %r12d, %r10d
testb %dl, %dl
je 0xd1be
addq 0x10(%rsp), %rax
movl %r12d, %r10d
movsbq %dl, %rdx
testb $0x20, 0x1(%rsi,%rdx,2)
jne 0xd1be
incl %r10d
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0xd1a7
leal (%r11,%r15), %ebp
xorl %r13d, %r13d
cmpl %ebp, %r10d
jle 0xd29f
movl %r10d, %eax
subl %r8d, %eax
cmpl %r15d, %eax
jle 0xd222
movl %r8d, 0xc(%rsp)
movl %r12d, %r8d
subl %r11d, %r8d
movl %r10d, %eax
subl %r12d, %eax
cltd
idivl %r15d
addl %r8d, %edx
cmpl %r15d, %edx
jle 0xd251
testl %r9d, %r9d
je 0xd251
movl 0xc(%rsp), %edx
subl %r11d, %edx
jne 0xd279
movl %r11d, %ebp
jmp 0xd293
movl $0x2, %r13d
movl %r12d, %r10d
jmp 0xd2ee
movl %r12d, %r10d
jmp 0xd2e8
cmpl 0x8(%rsp), %ecx
jge 0xd2e8
testq %rbx, %rbx
je 0xd240
movslq %ecx, %rax
movl %r11d, (%rbx,%rax,4)
subl %r11d, %r8d
movl %r8d, 0x4(%rbx,%rax,4)
addl $0x2, %ecx
movl $0x1, %r9d
movl %r12d, %r11d
jmp 0xd2ee
cmpl 0x8(%rsp), %ecx
jge 0xd2e8
testq %rbx, %rbx
je 0xd26c
movslq %ecx, %rax
movl %r11d, (%rbx,%rax,4)
movl %r15d, 0x4(%rbx,%rax,4)
addl $0x2, %ecx
jmp 0xd293
movl $0x1, %r13d
jmp 0xd212
cmpl %edi, %ecx
jge 0xd2e2
testq %rbx, %rbx
je 0xd28d
movslq %ecx, %rax
movl %r11d, (%rbx,%rax,4)
movl %edx, 0x4(%rbx,%rax,4)
addl $0x2, %ecx
movl %r12d, %ebp
leal (%r15,%rbp), %eax
cmpl %r10d, %eax
jle 0xd2a7
movl %ebp, %r11d
movl $0x1, %r9d
jmp 0xd2ee
movslq %ecx, %rcx
cmpq %rdi, %rcx
jge 0xd2d7
testq %rbx, %rbx
je 0xd2bc
movl %ebp, (%rbx,%rcx,4)
movl %r15d, 0x4(%rbx,%rcx,4)
addq $0x2, %rcx
addl %r15d, %ebp
leal (%r15,%rbp), %eax
cmpl %r10d, %eax
jle 0xd2aa
xorl %r13d, %r13d
movl $0x1, %r9d
jmp 0xd2dd
movl $0x1, %r13d
movl %ebp, %r11d
jmp 0xd2ee
movl $0x1, %r9d
movl $0x1, %r13d
testl %r13d, %r13d
je 0xd08f
cmpl $0x2, %r13d
jne 0xd327
subl %r11d, %r10d
jle 0xd321
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x8(%rsp), %ecx
jge 0xd32c
testq %rbx, %rbx
je 0xd31e
movslq %ecx, %rax
movl %r11d, (%rbx,%rax,4)
movl %r10d, 0x4(%rbx,%rax,4)
addl $0x2, %ecx
sarl %ecx
movl %ecx, %eax
jmp 0xd32c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq