user: Demonstrate the C code that generates the assembly output below:

```asm
<img_rle_compact>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%r9
  mov    %rdx,%rdi
  mov    %ecx,%edx
  cmp    $0x1,%esi
  sete   %al
  cmp    $0x1,%ecx
  sete   %cl
  test   %al,%al
  je     L489
  test   %cl,%cl
  je     L489
  movslq %r8d,%r8
  lea    (%r9,%r8,1),%r10
  cmp    %r10,%r9
  jae    L297
  mov    %rdi,%rdx
  jmp    L584
L30:
  add    $0x1,%r8
  cmp    %r8,%r10
  je     L575
L324:
  movzbl -0x1(%r8),%eax
  cmp    %al,-0x2(%r8)
  jne    L30
  cmp    (%r8),%al
  jne    L30
  jmp    L715
L575:
  mov    %r10,%r8
L715:
  lea    -0x2(%r8),%rbp
  mov    %rbp,%rax
  sub    %r9,%rax
  mov    %eax,%r11d
  test   %eax,%eax
  je     L286
L761:
  mov    $0x7e,%eax
  cmp    %eax,%r11d
  cmovle %r11d,%eax
  movswl %ax,%ecx
  sub    %ecx,%r11d
  lea    0x1(%rdx),%r12
  mov    %eax,%ecx
  or     $0xffffff80,%ecx
  mov    %cl,(%rdx)
  lea    -0x1(%rax),%esi
  test   %ax,%ax
  je     L426
  movzwl %si,%esi
  lea    0x1(%rsi),%rbx
  mov    $0x0,%eax
L873:
  movzbl (%r9,%rax,1),%ecx
  mov    %cl,0x1(%rdx,%rax,1)
  mov    %rax,%rcx
  add    $0x1,%rax
  cmp    %rcx,%rsi
  jne    L873
  add    %rbx,%r9
  lea    (%r12,%rbx,1),%rdx
L378:
  test   %r11d,%r11d
  jne    L761
L286:
  lea    -0x1(%r8),%r9
  movzbl -0x2(%r8),%r8d
  cmp    %r9,%r10
  jbe    L221
L522:
  cmp    (%r9),%r8b
  jne    L318
  add    $0x1,%r9
  cmp    %r9,%r10
  ja     L522
L221:
  mov    %r9,%rax
  sub    %rbp,%rax
  mov    %eax,%ecx
  test   %eax,%eax
  je     L577
L532:
  mov    $0x7e,%eax
  cmp    %eax,%ecx
  cmovle %ecx,%eax
  movswl %ax,%esi
  mov    %al,(%rdx)
  add    $0x2,%rdx
  mov    %r8b,-0x1(%rdx)
  sub    %esi,%ecx
  jne    L532
L401:
  cmp    %r10,%r9
  jae    L577
L584:
  lea    0x2(%r9),%r8
  cmp    %r8,%r10
  ja     L324
  jmp    L715
L426:
  mov    %r12,%rdx
  jmp    L378
L318:
  mov    %r9,%rax
  sub    %rbp,%rax
  mov    %eax,%ecx
  test   %eax,%eax
  jne    L532
  jmp    L401
L297:
  mov    %rdi,%rdx
L577:
  movb   $0x0,(%rdx)
  lea    0x1(%rdx),%rax
  sub    %edi,%eax
L242:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L489:
  cmp    $0x2,%edx
  sete   %r10b
  test   %al,%al
  je     L695
  test   %r10b,%r10b
  je     L695
  movslq %r8d,%r8
  lea    (%r9,%r8,1),%r10
  cmp    %r10,%r9
  jae    L506
  mov    %rdi,%rdx
  jmp    L206
L519:
  add    $0x1,%r8
  cmp    %r8,%r10
  je     L10
L723:
  movzbl -0x1(%r8),%eax
  cmp    %al,-0x2(%r8)
  jne    L519
  cmp    (%r8),%al
  jne    L519
  jmp    L84
L10:
  mov    %r10,%r8
L84:
  lea    -0x2(%r8),%rbp
  mov    %rbp,%rax
  sub    %r9,%rax
  mov    %eax,%r11d
  test   %eax,%eax
  je     L329
L383:
  mov    $0x7e,%eax
  cmp    %eax,%r11d
  cmovle %r11d,%eax
  movswl %ax,%ecx
  sub    %ecx,%r11d
  lea    0x2(%rdx),%r12
  mov    %eax,%ecx
  or     $0x80,%cl
  mov    %cx,(%rdx)
  lea    -0x1(%rax),%esi
  test   %ax,%ax
  je     L394
  movzwl %si,%esi
  lea    0x1(%rsi),%rbx
  mov    $0x0,%eax
L9:
  movzbl (%r9,%rax,1),%ecx
  mov    %cx,0x2(%rdx,%rax,2)
  mov    %rax,%rcx
  add    $0x1,%rax
  cmp    %rcx,%rsi
  jne    L9
  add    %rbx,%r9
  lea    (%r12,%rbx,2),%rdx
L291:
  test   %r11d,%r11d
  jne    L383
L329:
  lea    -0x1(%r8),%r9
  movzbl -0x2(%r8),%eax
  cmp    %r9,%r10
  jbe    L467
L253:
  cmp    (%r9),%al
  jne    L467
  add    $0x1,%r9
  cmp    %r9,%r10
  ja     L253
L467:
  mov    %r9,%rsi
  sub    %rbp,%rsi
  mov    %esi,%ecx
  test   %esi,%esi
  je     L26
  movzbl %al,%r8d
L289:
  mov    $0x7e,%eax
  cmp    %eax,%ecx
  cmovle %ecx,%eax
  movswl %ax,%esi
  mov    %ax,(%rdx)
  add    $0x4,%rdx
  mov    %r8w,-0x2(%rdx)
  sub    %esi,%ecx
  jne    L289
L26:
  cmp    %r9,%r10
  jbe    L560
L206:
  lea    0x2(%r9),%r8
  cmp    %r8,%r10
  ja     L723
  jmp    L84
L394:
  mov    %r12,%rdx
  jmp    L291
L506:
  mov    %rdi,%rdx
L560:
  movw   $0x0,(%rdx)
  lea    0x2(%rdx),%rax
  sub    %rdi,%rax
  sar    %rax
  jmp    L242
L695:
  cmp    $0x2,%esi
  sete   %al
  test   %cl,%cl
  je     L337
  test   %al,%al
  je     L337
  movslq %r8d,%r8
  lea    (%r9,%r8,2),%r10
  cmp    %r10,%r9
  jae    L610
  mov    %rdi,%rax
  jmp    L311
L99:
  add    $0x2,%r8
  cmp    %r8,%r10
  jbe    L415
L459:
  movzwl -0x2(%r8),%edx
  cmp    %dx,-0x4(%r8)
  jne    L99
  cmp    (%r8),%dx
  jne    L99
L415:
  lea    -0x4(%r8),%rbp
  mov    %rbp,%rdx
  sub    %r9,%rdx
  sar    %rdx
  mov    %edx,%r11d
  test   %edx,%edx
  jne    L661
L66:
  lea    -0x2(%r8),%r9
  movzwl -0x4(%r8),%r8d
  movswl %r8w,%ecx
  cmp    %r9,%r10
  jbe    L327
L803:
  movzwl (%r9),%edx
  cmp    %ecx,%edx
  jne    L327
  add    $0x2,%r9
  cmp    %r9,%r10
  ja     L803
L327:
  mov    %r9,%rdx
  sub    %rbp,%rdx
  sar    %rdx
  mov    %edx,%ecx
  test   %edx,%edx
  je     L397
L753:
  mov    $0x7e,%edx
  cmp    %edx,%ecx
  cmovle %ecx,%edx
  movswl %dx,%esi
  mov    %dl,(%rax)
  add    $0x2,%rax
  mov    %r8b,-0x1(%rax)
  sub    %esi,%ecx
  jne    L753
L397:
  cmp    %r9,%r10
  jbe    L347
L311:
  lea    0x4(%r9),%r8
  cmp    %r8,%r10
  ja     L459
  jmp    L415
L554:
  mov    %r12,%rax
L633:
  test   %r11d,%r11d
  je     L66
L661:
  mov    $0x7e,%edx
  cmp    %edx,%r11d
  cmovle %r11d,%edx
  movswl %dx,%ecx
  sub    %ecx,%r11d
  lea    0x1(%rax),%r12
  mov    %edx,%ecx
  or     $0xffffff80,%ecx
  mov    %cl,(%rax)
  lea    -0x1(%rdx),%esi
  test   %dx,%dx
  je     L554
  movzwl %si,%esi
  lea    0x1(%rsi),%rbx
  mov    $0x0,%edx
L283:
  movzwl (%r9,%rdx,2),%ecx
  mov    %cl,0x1(%rax,%rdx,1)
  mov    %rdx,%rcx
  add    $0x1,%rdx
  cmp    %rcx,%rsi
  jne    L283
  lea    (%r9,%rbx,2),%r9
  lea    (%r12,%rbx,1),%rax
  jmp    L633
L610:
  mov    %rdi,%rax
L347:
  movb   $0x0,(%rax)
  add    $0x1,%rax
  sub    %edi,%eax
  jmp    L242
L337:
  test   %r10b,%r10b
  je     L45
  test   %al,%al
  je     L45
  movslq %r8d,%r8
  lea    (%r9,%r8,2),%r11
  cmp    %r11,%r9
  jae    L119
  mov    %rdi,%rax
  jmp    L466
L787:
  add    $0x2,%r8
  cmp    %r8,%r11
  jbe    L209
L698:
  movzwl -0x2(%r8),%edx
  cmp    %dx,-0x4(%r8)
  jne    L787
  cmp    (%r8),%dx
  jne    L787
L209:
  lea    -0x4(%r8),%rbx
  mov    %rbx,%rdx
  sub    %r9,%rdx
  sar    %rdx
  mov    %edx,%r10d
  test   %edx,%edx
  je     L167
L672:
  mov    $0x7e,%edx
  cmp    %edx,%r10d
  cmovle %r10d,%edx
  movswl %dx,%ecx
  sub    %ecx,%r10d
  lea    0x2(%rax),%rbp
  mov    %edx,%ecx
  or     $0x80,%cl
  mov    %cx,(%rax)
  lea    -0x1(%rdx),%ecx
  test   %dx,%dx
  je     L594
  movzwl %cx,%ecx
  lea    0x2(%rcx,%rcx,1),%rsi
  mov    $0x0,%edx
L287:
  movzwl (%r9,%rdx,1),%ecx
  mov    %cx,0x2(%rax,%rdx,1)
  add    $0x2,%rdx
  cmp    %rdx,%rsi
  jne    L287
  add    %rsi,%r9
  lea    0x0(%rbp,%rsi,1),%rax
L662:
  test   %r10d,%r10d
  jne    L672
L167:
  lea    -0x2(%r8),%r9
  movzwl -0x4(%r8),%r8d
  movswl %r8w,%ecx
  cmp    %r9,%r11
  jbe    L435
L239:
  movzwl (%r9),%edx
  cmp    %ecx,%edx
  jne    L435
  add    $0x2,%r9
  cmp    %r9,%r11
  ja     L239
L435:
  mov    %r9,%rdx
  sub    %rbx,%rdx
  sar    %rdx
  mov    %edx,%ecx
  test   %edx,%edx
  je     L344
L210:
  mov    $0x7e,%edx
  cmp    %edx,%ecx
  cmovle %ecx,%edx
  movswl %dx,%esi
  mov    %dx,(%rax)
  add    $0x4,%rax
  mov    %r8w,-0x2(%rax)
  sub    %esi,%ecx
  jne    L210
L344:
  cmp    %r9,%r11
  jbe    L80
L466:
  lea    0x4(%r9),%r8
  cmp    %r8,%r11
  ja     L698
  jmp    L209
L594:
  mov    %rbp,%rax
  jmp    L662
L119:
  mov    %rdi,%rax
L80:
  movw   $0x0,(%rax)
  add    $0x2,%rax
  sub    %rdi,%rax
  sar    %rax
  jmp    L242
L45:
  lea    D1(%rip),%rdi
  call   <i_errhdlr@plt>
  mov    $0x0,%eax
  jmp    L242
```

tool_calls: name: parse_data
arguments: tag: D1
type: string

tool: D1: rle_compact: bad bpp: %d %d


assistant: ```c
int img_rle_compact(unsigned short *expbuf, int ibpp, unsigned short *rlebuf, int obpp, int cnt) {
  if (ibpp == 1 && obpp == 1) {
    register unsigned char *iptr = (unsigned char *)expbuf;
    register unsigned char *ibufend = iptr + cnt;
    register unsigned char *sptr;
    register unsigned char *optr = (unsigned char *)rlebuf;
    register short todo, cc;
    register int count;
    while (iptr < ibufend) {
      sptr = iptr;
      iptr += 2;
      while ((iptr < ibufend) && ((iptr[-2] != iptr[-1]) || (iptr[-1] != iptr[0])))
        iptr++;
      iptr -= 2;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = 0x80 | todo;
        while (todo--)
          *optr++ = *sptr++;
      }
      sptr = iptr;
      cc = *iptr++;
      while ((iptr < ibufend) && (*iptr == cc))
        iptr++;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = todo;
        *optr++ = cc;
      }
    }
    *optr++ = 0;
    ;
    return optr - (unsigned char *)rlebuf;
  } else if (ibpp == 1 && obpp == 2) {
    register unsigned char *iptr = (unsigned char *)expbuf;
    register unsigned char *ibufend = iptr + cnt;
    register unsigned char *sptr;
    register unsigned short *optr = rlebuf;
    register short todo, cc;
    register int count;
    while (iptr < ibufend) {
      sptr = iptr;
      iptr += 2;
      while ((iptr < ibufend) && ((iptr[-2] != iptr[-1]) || (iptr[-1] != iptr[0])))
        iptr++;
      iptr -= 2;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = 0x80 | todo;
        while (todo--)
          *optr++ = *sptr++;
      }
      sptr = iptr;
      cc = *iptr++;
      while ((iptr < ibufend) && (*iptr == cc))
        iptr++;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = todo;
        *optr++ = cc;
      }
    }
    *optr++ = 0;
    ;
    return optr - rlebuf;
  } else if (ibpp == 2 && obpp == 1) {
    register unsigned short *iptr = expbuf;
    register unsigned short *ibufend = iptr + cnt;
    register unsigned short *sptr;
    register unsigned char *optr = (unsigned char *)rlebuf;
    register short todo, cc;
    register int count;
    while (iptr < ibufend) {
      sptr = iptr;
      iptr += 2;
      while ((iptr < ibufend) && ((iptr[-2] != iptr[-1]) || (iptr[-1] != iptr[0])))
        iptr++;
      iptr -= 2;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = 0x80 | todo;
        while (todo--)
          *optr++ = *sptr++;
      }
      sptr = iptr;
      cc = *iptr++;
      while ((iptr < ibufend) && (*iptr == cc))
        iptr++;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = todo;
        *optr++ = cc;
      }
    }
    *optr++ = 0;
    ;
    return optr - (unsigned char *)rlebuf;
  } else if (ibpp == 2 && obpp == 2) {
    register unsigned short *iptr = expbuf;
    register unsigned short *ibufend = iptr + cnt;
    register unsigned short *sptr;
    register unsigned short *optr = rlebuf;
    register short todo, cc;
    register int count;
    while (iptr < ibufend) {
      sptr = iptr;
      iptr += 2;
      while ((iptr < ibufend) && ((iptr[-2] != iptr[-1]) || (iptr[-1] != iptr[0])))
        iptr++;
      iptr -= 2;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = 0x80 | todo;
        while (todo--)
          *optr++ = *sptr++;
      }
      sptr = iptr;
      cc = *iptr++;
      while ((iptr < ibufend) && (*iptr == cc))
        iptr++;
      count = iptr - sptr;
      while (count) {
        todo = count > 126 ? 126 : count;
        count -= todo;
        *optr++ = todo;
        *optr++ = cc;
      }
    }
    *optr++ = 0;
    ;
    return optr - rlebuf;
  } else {
    i_errhdlr("rle_compact: bad bpp: %d %d\n", ibpp, obpp);
    return 0;
  }
}
```