// File: 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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movl %esi, 0x34(%rsp)
movl %edx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0x16158
movl $0x7ffffff0, 0x34(%rsp) # imm = 0x7FFFFFF0
jmp 0x16162
movl 0x34(%rsp), %eax
shll %eax
movl %eax, 0x34(%rsp)
jmp 0x16164
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x23b0
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movslq 0x20(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x16274
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x161c1
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x16264
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movq 0x28(%rsp), %rcx
movl 0x20(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
cmpl $0x17, %eax
jne 0x161f4
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x1620b
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x1623e
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %edx
subl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x1616c
movl 0x20(%rsp), %eax
movl 0x1c(%rsp), %ecx
addl 0x30(%rsp), %ecx
cmpl %ecx, %eax
jl 0x16375
cmpl $0x0, 0x18(%rsp)
je 0x162fa
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x162a6
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x162d9
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %edx
subl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
movl %eax, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
jmp 0x16373
jmp 0x162fc
movl 0x20(%rsp), %eax
movl 0x1c(%rsp), %ecx
addl 0x30(%rsp), %ecx
cmpl %ecx, %eax
jl 0x1636b
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x16323
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x16352
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x30(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x30(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x162fc
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x16375
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1638d
jmp 0x165f3
movl 0x20(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xf(%rsp)
je 0x163dc
callq 0x23b0
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movslq 0x20(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x163e6
jmp 0x163f3
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x16395
movl 0x20(%rsp), %eax
movl 0x1c(%rsp), %ecx
addl 0x30(%rsp), %ecx
cmpl %ecx, %eax
jle 0x165e6
movl 0x20(%rsp), %eax
subl 0x14(%rsp), %eax
cmpl 0x30(%rsp), %eax
jg 0x16477
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x1642c
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x1645f
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %edx
subl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x165e4
movl 0x10(%rsp), %eax
subl 0x1c(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x20(%rsp), %eax
subl 0x10(%rsp), %eax
cltd
idivl 0x30(%rsp)
movl 0x8(%rsp), %eax
addl %edx, %eax
cmpl 0x30(%rsp), %eax
jle 0x164a3
cmpl $0x0, 0x18(%rsp)
jne 0x1650a
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x164ba
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x164e9
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x30(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x30(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x16573
movl 0x14(%rsp), %eax
cmpl 0x1c(%rsp), %eax
je 0x16571
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x1652b
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x1655e
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%rsp), %edx
subl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x16573
jmp 0x16575
movl 0x1c(%rsp), %eax
addl 0x30(%rsp), %eax
cmpl 0x20(%rsp), %eax
jg 0x165e2
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x1659a
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x165c9
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x30(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x30(%rsp), %eax
addl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x16575
jmp 0x165e4
jmp 0x165e6
movl $0x1, 0x18(%rsp)
jmp 0x16164
movl 0x1c(%rsp), %eax
cmpl 0x20(%rsp), %eax
jge 0x1664f
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x16611
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x16659
cmpq $0x0, 0x38(%rsp)
je 0x16644
movl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movslq 0x24(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x20(%rsp), %edx
subl 0x1c(%rsp), %edx
movq 0x38(%rsp), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x24(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
sarl %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)