user: 请将以下的汇编代码转换成C语言代码:

```asm
<rdmad>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x5000(%rsp),%r11
L449:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L449
  sub    $0x118,%rsp
  mov    %rdi,%r12
  mov    %rsi,%rbp
  mov    %rdx,0x10(%rsp)
  mov    %ecx,0xc(%rsp)
  mov    %r9,%r13
  mov    0x5150(%rsp),%r15
  mov    %fs:0x28,%rax
  mov    %rax,0x5108(%rsp)
  xor    %eax,%eax
  movl   $0x1,0x54(%rsp)
  call   <filec_getdebug@plt>
  mov    %eax,%ebx
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,0x44(%rsp)
  test   %ebx,%ebx
  jne    L363
L698:
  lea    0x48(%rsp),%rcx
  lea    0x44(%rsp),%rdx
  lea    0x54(%rsp),%rdi
  mov    %r12,%rsi
  call   <dskbor_@plt>
  mov    0x48(%rsp),%r12d
  test   %r12d,%r12d
  jne    L841
  movl   $0x1,0x58(%rsp)
  test   %ebx,%ebx
  jne    L399
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%r14
  mov    %r14,%rdi
  call   <dskbwr_@plt>
  movl   $0x200,0x3c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  je     L865
L172:
  lea    0x40(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbcr_@plt>
L609:
  test   %ebx,%ebx
  jne    L713
L746:
  mov    0x48(%rsp),%r12d
L841:
  mov    0x5108(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L45
  mov    %r12d,%eax
  add    $0x5118,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L363:
  mov    %r12,%rsi
  lea    D325(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L698
L399:
  lea    D118(%rip),%rdi
  call   <puts@plt>
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%r14
  mov    %r14,%rdi
  call   <dskbwr_@plt>
  movl   $0x200,0x3c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <dskbr_@plt>
  mov    0x48(%rsp),%esi
  lea    D341(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  cmpl   $0x0,0x48(%rsp)
  je     L865
L981:
  mov    0x48(%rsp),%ecx
  mov    (%r15),%edx
  mov    0x0(%r13),%esi
  lea    D178(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L324:
  cmpl   $0x0,0x48(%rsp)
  jne    L172
  lea    0x48(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbcr_@plt>
  jmp    L609
L865:
  lea    0x4c(%rsp),%rdi
  mov    %rbp,%rsi
  call   <gethdl@plt>
  test   %ebx,%ebx
  jne    L82
  mov    0x4c(%rsp),%eax
  sub    $0x200,%eax
  mov    %eax,0x3c(%rsp)
  test   %eax,%eax
  jle    L35
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  lea    0x200(%rbp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  jne    L172
L312:
  movl   $0x0,0x58(%rsp)
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbwr_@plt>
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D149(%rip),%rdi
  call   <gethd@plt>
  test   %ebx,%ebx
  je     L29
  jmp    L774
L82:
  mov    0x4c(%rsp),%esi
  lea    D88(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    0x4c(%rsp),%eax
  sub    $0x200,%eax
  mov    %eax,0x3c(%rsp)
  test   %eax,%eax
  jle    L692
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  lea    0x200(%rbp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  je     L312
  jmp    L981
L177:
  lea    0x60(%rsp),%rdi
  mov    %r13,%rdx
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L820
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D152(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  je     L820
  lea    0x60(%rsp),%rdi
  mov    %r15,%rdx
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L820
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D85(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  je     L820
  lea    0x50(%rsp),%rdx
  lea    0x60(%rsp),%rdi
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  mov    %eax,%ebp
  cmp    $0x1,%eax
  jne    L820
  test   %ebx,%ebx
  jne    L156
  mov    0xc(%rsp),%eax
  cmp    %eax,0x0(%r13)
  je     L732
L650:
  mov    0x0(%r13),%eax
  add    %eax,%eax
  mov    %eax,0x3c(%rsp)
  movl   $0x0,0x44(%rsp)
  cmpl   $0x0,(%r15)
  jle    L147
  mov    %r12d,%eax
  lea    0x48(%rsp),%r14
  mov    %ebp,0x18(%rsp)
  mov    %ebx,0x28(%rsp)
  mov    0x10(%rsp),%rbp
  mov    0xc(%rsp),%ebx
L171:
  lea    0x3c(%rsp),%rdx
  imul   %ebx,%eax
  cltq
  lea    0x0(%rbp,%rax,2),%rsi
  lea    0x54(%rsp),%rdi
  mov    %r14,%rcx
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  jne    L792
  mov    0x44(%rsp),%eax
  add    $0x1,%eax
  mov    %eax,0x44(%rsp)
  cmp    (%r15),%eax
  jl     L171
  mov    0x18(%rsp),%ebp
  mov    0x28(%rsp),%ebx
L147:
  movl   $0x1,0x58(%rsp)
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbwr_@plt>
  cmpb   $0x0,0xb0(%rsp)
  je     L496
  lea    0xb0(%rsp),%rdi
  lea    D62(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L949
  mov    %r12d,%ebp
L496:
  mov    $0x0,%eax
  call   <getbo@plt>
  cmp    %ebp,%eax
  je     L820
  test   %ebx,%ebx
  jne    L137
L561:
  movl   $0x0,0x44(%rsp)
  cmpl   $0x0,(%r15)
  jle    L820
  mov    0x10(%rsp),%rbp
  mov    0xc(%rsp),%r14d
L581:
  imul   %r14d,%r12d
  movslq %r12d,%rax
  lea    0x0(%rbp,%rax,2),%rdx
  mov    0x0(%r13),%eax
  lea    (%rax,%rax,1),%esi
  mov    $0x0,%edi
  call   <swpbyt@plt>
  mov    0x44(%rsp),%eax
  lea    0x1(%rax),%r12d
  mov    %r12d,0x44(%rsp)
  cmp    (%r15),%r12d
  jl     L581
  jmp    L820
L156:
  mov    0x50(%rsp),%ecx
  mov    (%r15),%edx
  mov    0x0(%r13),%esi
  lea    D296(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    0xc(%rsp),%eax
  cmp    0x0(%r13),%eax
  je     L741
  lea    D164(%rip),%rdi
  call   <puts@plt>
  jmp    L650
L741:
  lea    D254(%rip),%rdi
  call   <puts@plt>
  mov    0x0(%r13),%eax
  imul   (%r15),%eax
  add    %eax,%eax
  mov    %eax,0x3c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  lea    0x54(%rsp),%rdi
  mov    0x10(%rsp),%rsi
  call   <dskbr_@plt>
  mov    0x48(%rsp),%esi
  lea    D341(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  cmpl   $0x0,0x48(%rsp)
  je     L147
  jmp    L113
L949:
  lea    0xb0(%rsp),%rdi
  lea    D21(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L496
  movl   $0xfffffffe,0x48(%rsp)
  jmp    L113
L137:
  lea    D277(%rip),%rdi
  call   <puts@plt>
  jmp    L561
L371:
  lea    0x60(%rsp),%rdi
  lea    D40(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L425
  test   %ebx,%ebx
  jne    L412
L256:
  movl   $0xfffffffe,0x48(%rsp)
L113:
  test   %ebx,%ebx
  je     L172
  jmp    L981
L425:
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D200(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  je     L820
  lea    0x60(%rsp),%rdi
  mov    %r13,%rdx
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L820
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D152(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  je     L820
  lea    0x60(%rsp),%rdi
  mov    %r15,%rdx
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L820
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D85(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  je     L820
  lea    0x50(%rsp),%rdx
  lea    0x60(%rsp),%rdi
  lea    D131(%rip),%rsi
  call   <sscanf@plt>
  mov    %eax,%r14d
  cmp    $0x1,%eax
  jne    L820
  mov    $0x0,%eax
  call   <getbo@plt>
  mov    %eax,0x28(%rsp)
  test   %eax,%eax
  je     L802
  cmp    $0x1,%eax
  cmove  %r12d,%r14d
L802:
  movl   $0x2,0x5c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x5c(%rsp),%rdx
  lea    0x100(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  mov    0x48(%rsp),%r12d
  test   %r12d,%r12d
  jne    L113
  mov    0x5c(%rsp),%eax
  lea    -0x2(%rax),%edx
  movslq %edx,%rdx
  movzbl 0x100(%rsp,%rdx,1),%edx
  shl    $0x8,%edx
  sub    $0x1,%eax
  cltq
  movzbl 0x100(%rsp,%rax,1),%eax
  add    %edx,%eax
  mov    %eax,0x5c(%rsp)
  mov    %r12d,%eax
  movslq 0x28(%rsp),%rcx
  mov    %rcx,0x18(%rsp)
  movslq %r14d,%rcx
  mov    %rcx,0x20(%rsp)
  jmp    L259
L956:
  mov    0x5c(%rsp),%esi
  lea    D94(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    0x48(%rsp),%rcx
  lea    0x5c(%rsp),%rdx
  lea    0x100(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  jne    L113
  test   %ebx,%ebx
  je     L705
  mov    0x5c(%rsp),%esi
  sub    0x0(%r13),%esi
  sub    $0x2,%esi
  lea    D112(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L705
L539:
  mov    %r12d,%edi
L737:
  cmp    %rsi,%r8
  jbe    L64
L854:
  movzbl (%rsi),%edx
  movzbl %dl,%edi
  add    $0x2,%rsi
  movzbl -0x1(%rsi),%ecx
  test   %edi,%edi
  jle    L539
  movzbl %dl,%edx
  add    %rax,%rdx
L230:
  add    $0x1,%rax
  mov    %cl,-0x1(%rax)
  cmp    %rax,%rdx
  jne    L230
  mov    %rdx,%rax
  jmp    L737
L64:
  mov    %edi,0x40(%rsp)
L673:
  test   %ebx,%ebx
  jne    L875
L822:
  mov    0x44(%rsp),%edi
  mov    0xc(%rsp),%eax
  imul   %edi,%eax
  add    %eax,%eax
  cltq
  mov    0x18(%rsp),%rcx
  lea    (%rcx,%rax,1),%r8
  mov    0x10(%rsp),%rcx
  add    %rcx,%r8
  add    0x20(%rsp),%rax
  add    %rax,%rcx
  lea    0x100(%rsp),%rdx
  movslq 0x0(%r13),%rax
  add    %rdx,%rax
  cmp    %rax,%rdx
  jae    L277
  mov    $0x0,%eax
  mov    %rdx,%r9
L573:
  add    $0x1,%rdx
  movzbl -0x1(%rdx),%esi
  mov    %sil,(%r8,%rax,2)
  movzbl 0x2900(%rsp,%rax,1),%esi
  mov    %sil,(%rcx,%rax,2)
  add    $0x1,%rax
  movslq 0x0(%r13),%rsi
  add    %r9,%rsi
  cmp    %rsi,%rdx
  jb     L573
L277:
  test   %ebx,%ebx
  jne    L733
L885:
  mov    0x5c(%rsp),%eax
  lea    -0x2(%rax),%edx
  movslq %edx,%rdx
  movzbl 0x100(%rsp,%rdx,1),%edx
  shl    $0x8,%edx
  sub    $0x1,%eax
  cltq
  movzbl 0x100(%rsp,%rax,1),%eax
  add    %edx,%eax
  mov    %eax,0x5c(%rsp)
  mov    0x44(%rsp),%eax
  add    $0x1,%eax
L259:
  mov    %eax,0x44(%rsp)
  mov    (%r15),%ecx
  lea    -0x1(%rcx),%edx
  cmp    %eax,%edx
  jle    L706
  test   %ebx,%ebx
  jne    L956
  lea    0x48(%rsp),%rcx
  lea    0x5c(%rsp),%rdx
  lea    0x100(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  jne    L113
L705:
  lea    0x100(%rsp),%rax
  movslq 0x0(%r13),%rsi
  add    %rax,%rsi
  movslq 0x5c(%rsp),%rdx
  lea    -0x2(%rax,%rdx,1),%r8
  cmp    %r8,%rsi
  jae    L428
  lea    0x2900(%rsp),%rax
  jmp    L854
L428:
  lea    0x2900(%rsp),%rax
  jmp    L673
L875:
  lea    0x2900(%rsp),%rdx
  sub    %rdx,%rax
  mov    %rax,%rsi
  lea    D217(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L822
L733:
  mov    %edi,%esi
  lea    D295(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D314(%rip),%rdi
  call   <puts@plt>
  jmp    L885
L706:
  subl   $0x2,0x5c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x5c(%rsp),%rdx
  lea    0x100(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbr_@plt>
  mov    0x48(%rsp),%edi
  test   %edi,%edi
  jne    L113
  lea    0x100(%rsp),%rax
  movslq 0x0(%r13),%rcx
  add    %rax,%rcx
  movslq 0x5c(%rsp),%rdx
  lea    (%rax,%rdx,1),%rsi
  mov    $0x0,%edx
  lea    0x2900(%rsp),%rax
  mov    $0x1,%r8d
  mov    0x2c(%rsp),%r9d
  jmp    L74
L793:
  mov    %edi,%r9d
  mov    %rax,%rdx
L294:
  mov    %rdx,%rax
  mov    %r8d,%edx
L74:
  cmp    %rcx,%rsi
  jbe    L828
  movzbl (%rcx),%edx
  movzbl %dl,%r9d
  add    $0x2,%rcx
  movzbl -0x1(%rcx),%r10d
  test   %r9d,%r9d
  jle    L793
  movzbl %dl,%edx
  add    %rax,%rdx
L704:
  add    $0x1,%rax
  mov    %r10b,-0x1(%rax)
  cmp    %rdx,%rax
  jne    L704
  jmp    L294
L828:
  test   %dl,%dl
  je     L892
  mov    %r9d,0x40(%rsp)
L892:
  test   %ebx,%ebx
  jne    L15
L182:
  mov    0xc(%rsp),%ecx
  imul   0x44(%rsp),%ecx
  add    %ecx,%ecx
  movslq %ecx,%rcx
  movslq 0x28(%rsp),%rdx
  add    %rcx,%rdx
  mov    0x10(%rsp),%rsi
  add    %rsi,%rdx
  movslq %r14d,%rax
  add    %rcx,%rax
  add    %rsi,%rax
  mov    $0x0,%ecx
  lea    0x100(%rsp),%rsi
  mov    %rsi,%r8
  jmp    L608
L15:
  lea    0x2900(%rsp),%rdx
  sub    %rdx,%rax
  mov    %rax,%rsi
  lea    D217(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L182
L651:
  add    $0x1,%rsi
  movzbl -0x1(%rsi),%edi
  mov    %dil,(%rdx,%rcx,2)
  movzbl 0x2900(%rsp,%rcx,1),%edi
  mov    %dil,(%rax,%rcx,2)
  add    $0x1,%rcx
L608:
  movslq 0x0(%r13),%rdi
  add    %r8,%rdi
  cmp    %rdi,%rsi
  jb     L651
  test   %ebx,%ebx
  jne    L620
L586:
  mov    %rbp,%rdx
  lea    D256(%rip),%rsi
  lea    D149(%rip),%rdi
  call   <puthd@plt>
  jmp    L820
L620:
  lea    D123(%rip),%rdi
  call   <puts@plt>
  jmp    L586
L412:
  lea    D34(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L256
L713:
  mov    0x48(%rsp),%esi
  lea    D338(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L746
L792:
  mov    0x28(%rsp),%ebx
  jmp    L113
L732:
  mov    0xc(%rsp),%eax
  imul   (%r15),%eax
  add    %eax,%eax
  mov    %eax,0x3c(%rsp)
  lea    0x48(%rsp),%rcx
  lea    0x3c(%rsp),%rdx
  lea    0x54(%rsp),%rdi
  mov    0x10(%rsp),%rsi
  call   <dskbr_@plt>
  cmpl   $0x0,0x48(%rsp)
  je     L147
  jmp    L172
L692:
  movl   $0x0,0x58(%rsp)
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbwr_@plt>
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D149(%rip),%rdi
  call   <gethd@plt>
L774:
  lea    0x60(%rsp),%rsi
  lea    D351(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L29
L35:
  movl   $0x0,0x58(%rsp)
  lea    0x58(%rsp),%rsi
  lea    0x54(%rsp),%rdi
  call   <dskbwr_@plt>
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D149(%rip),%rdi
  call   <gethd@plt>
L29:
  lea    0x60(%rsp),%rdi
  lea    D122(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L407
  lea    0x60(%rsp),%rdi
  lea    D256(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L371
L407:
  lea    0xb0(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D57(%rip),%rdi
  call   <gethd@plt>
  lea    0x60(%rsp),%rsi
  mov    %rbp,%rdx
  lea    D200(%rip),%rdi
  call   <gethd@plt>
  cmpb   $0x0,0x60(%rsp)
  jne    L177
L820:
  test   %ebx,%ebx
  je     L324
  jmp    L981
L45:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D325
datatype: string
name: retrieve_data
arguments: label: D118
datatype: string
name: retrieve_data
arguments: label: D341
datatype: string
name: retrieve_data
arguments: label: D178
datatype: string
name: retrieve_data
arguments: label: D149
datatype: string
name: retrieve_data
arguments: label: D88
datatype: string
name: retrieve_data
arguments: label: D131
datatype: string
name: retrieve_data
arguments: label: D152
datatype: string
name: retrieve_data
arguments: label: D85
datatype: string
name: retrieve_data
arguments: label: D62
datatype: string
name: retrieve_data
arguments: label: D296
datatype: string
name: retrieve_data
arguments: label: D164
datatype: string
name: retrieve_data
arguments: label: D254
datatype: string
name: retrieve_data
arguments: label: D21
datatype: string
name: retrieve_data
arguments: label: D277
datatype: string
name: retrieve_data
arguments: label: D40
datatype: string
name: retrieve_data
arguments: label: D200
datatype: string
name: retrieve_data
arguments: label: D94
datatype: string
name: retrieve_data
arguments: label: D112
datatype: string
name: retrieve_data
arguments: label: D217
datatype: string
name: retrieve_data
arguments: label: D295
datatype: string
name: retrieve_data
arguments: label: D314
datatype: string
name: retrieve_data
arguments: label: D256
datatype: string
name: retrieve_data
arguments: label: D123
datatype: string
name: retrieve_data
arguments: label: D34
datatype: string
name: retrieve_data
arguments: label: D338
datatype: string
name: retrieve_data
arguments: label: D351
datatype: string
name: retrieve_data
arguments: label: D122
datatype: string
name: retrieve_data
arguments: label: D57
datatype: string

tool: D325: Opening file: %s


tool: D118: Reading header

tool: D341: Read Completion status : %d


tool: D178: Done reading Image size %d %d (%d)


tool: D149: TYPE

tool: D88: Header length : %d


tool: D131: %d

tool: D152: SIZE2

tool: D85: DIM

tool: D62: little_endian

tool: D296: Image size %d %d %d


tool: D164: Reading one line at a time

tool: D254: Reading in single chunk

tool: D21: big_endian

tool: D277: Swapping bytes

tool: D40: swap_rlmsb

tool: D200: SIZE1

tool: D94: Reading %d bytes


tool: D112: Uncompressing %d bytes


tool: D217: Restored %d bytes in MSB


tool: D295: Done line %d


tool: D314: =================================

tool: D256: unsigned_short

tool: D123: ===================================

tool: D34: Unsupported Filetype (%s)


tool: D338: RDFILE completion status %d


tool: D351: Type >%s<


tool: D122: mad

tool: D57: BYTE_ORDER

assistant: ```c
int rdmad(char *filename, char *head, short *array, int as1, int as2, int *is1, int *is2) {
  int readl, remain;
  int i, j, k;
  int istat, lhead, bo, dim;
  char s[80], byteo[80];
  int lun = 1;
  int lflag;
  unsigned char lsb[10 * 1024], msb[10 * 1024];
  unsigned char *lp, *mp, *alp, *amp;
  int lstart, mstart;
  int llen, n, val;
  int filec_debug = filec_getdebug();
  j = strlen(filename);
  if (filec_debug)
    printf("Opening file: %s\n", filename);
  dskbor_(&lun, filename, &j, &istat);
  if (istat != 0)
    return (istat);
  lflag = (1 == 1);
  if (filec_debug)
    printf("Reading header\n");
  dskbwr_(&lun, &lflag);
  readl = 512;
  dskbr_(&lun, head, &readl, &istat);
  if (filec_debug)
    printf("Read Completion status : %d\n", istat);
  if (istat != 0)
    goto close;
  gethdl(&lhead, head);
  if (filec_debug)
    printf("Header length : %d\n", lhead);
  readl = lhead - 512;
  if (readl > 0) {
    dskbr_(&lun, head + 512, &readl, &istat);
    if (istat != 0)
      goto close;
  }
  lflag = (1 == 0);
  dskbwr_(&lun, &lflag);
  gethd("TYPE", s, head);
  if (filec_debug)
    printf("Type >%s<\n", s);
  if (strcmp(s, "mad") == 0 || strcmp(s, "unsigned_short") == 0) {
    gethd("BYTE_ORDER", byteo, head);
    gethd("SIZE1", s, head);
    if (*s == 0 || sscanf(s, "%d", is1) != 1)
      goto close;
    gethd("SIZE2", s, head);
    if (*s == 0 || sscanf(s, "%d", is2) != 1)
      goto close;
    gethd("DIM", s, head);
    if (*s == 0 || sscanf(s, "%d", &dim) != 1)
      goto close;
    if (filec_debug)
      printf("Image size %d %d %d\n", *is1, *is2, dim);
    if (*is1 == as1) {
      if (filec_debug)
        printf("Reading in single chunk\n");
      readl = (*is1) * (*is2) * 2;
      dskbr_(&lun, (char *)array, &readl, &istat);
      if (filec_debug)
        printf("Read Completion status : %d\n", istat);
      if (istat != 0)
        goto close;
    } else {
      if (filec_debug)
        printf("Reading one line at a time\n");
      readl = *is1 * 2;
      for (j = 0; j < *is2; j++) {
        dskbr_(&lun, (char *)(array + j * as1), &readl, &istat);
        if (istat != 0)
          goto close;
      }
    }
    lflag = (1 == 1);
    dskbwr_(&lun, &lflag);
    if (*byteo) {
      if (strcmp(byteo, "little_endian") == 0)
        bo = 0;
      else if (strcmp(byteo, "big_endian") == 0)
        bo = 1;
      else {
        istat = -2;
        goto close;
      }
    }
    if (bo != getbo()) {
      if (filec_debug)
        printf("Swapping bytes\n");
      for (j = 0; j < *is2; j++)
        swpbyt(0, 2 * *is1, (char *)(array + j * as1));
    }
  } else if (strcmp(s, "swap_rlmsb") == 0) {
    gethd("SIZE1", s, head);
    if (*s == 0 || sscanf(s, "%d", is1) != 1)
      goto close;
    gethd("SIZE2", s, head);
    if (*s == 0 || sscanf(s, "%d", is2) != 1)
      goto close;
    gethd("DIM", s, head);
    if (*s == 0 || sscanf(s, "%d", &dim) != 1)
      goto close;
    bo = getbo();
    if (bo == 0) {
      lstart = 0;
      mstart = 1;
    } else if (bo == 1) {
      lstart = 1;
      mstart = 0;
    }
    llen = 2;
    dskbr_(&lun, (char *)lsb, &llen, &istat);
    if (istat != 0)
      goto close;
    llen = (int)lsb[llen - 2] * 256 + lsb[llen - 1];
    for (j = 0; j < (*is2 - 1); j++) {
      if (filec_debug)
        printf("Reading %d bytes\n", llen);
      dskbr_(&lun, (char *)lsb, &llen, &istat);
      if (istat != 0)
        goto close;
      if (filec_debug)
        printf("Uncompressing %d bytes\n", llen - (*is1) - 2);
      for (lp = lsb + (*is1), mp = msb; lp < lsb + llen - 2;) {
        n = *lp++;
        val = *lp++;
        for (i = 0; i < n; i++)
          *mp++ = val;
      }
      if (filec_debug)
        printf("Restored %d bytes in MSB\n", mp - msb);
      alp = (unsigned char *)array + 2 * j * as1 + lstart;
      amp = (unsigned char *)array + 2 * j * as1 + mstart;
      for (lp = lsb, mp = msb; lp < lsb + (*is1); alp += 2, amp += 2) {
        *alp = *lp++;
        *amp = *mp++;
      }
      if (filec_debug) {
        printf("Done line %d\n", j);
        printf("=================================\n");
      }
      llen = (int)lsb[llen - 2] * 256 + lsb[llen - 1];
    }
    llen -= 2;
    dskbr_(&lun, (char *)lsb, &llen, &istat);
    if (istat != 0)
      goto close;
    for (lp = lsb + (*is1), mp = msb; lp < lsb + llen;) {
      n = *lp++;
      val = *lp++;
      for (i = 0; i < n; i++)
        *mp++ = val;
    }
    if (filec_debug)
      printf("Restored %d bytes in MSB\n", mp - msb);
    alp = (unsigned char *)array + 2 * j * as1 + lstart;
    amp = (unsigned char *)array + 2 * j * as1 + mstart;
    for (lp = lsb, mp = msb; lp < lsb + (*is1); alp += 2, amp += 2) {
      *alp = *lp++;
      *amp = *mp++;
    }
    if (filec_debug)
      printf("===================================\n");
    puthd("TYPE", "unsigned_short", head);
  } else {
    if (filec_debug)
      printf("Unsupported Filetype (%s)\n");
    istat = -2;
    goto close;
  }
close:
  if (filec_debug)
    printf("Done reading Image size %d %d (%d)\n", *is1, *is2, istat);
  if (istat != 0)
    dskbcr_(&lun, &i);
  else
    dskbcr_(&lun, &istat);
  if (filec_debug)
    printf("RDFILE completion status %d\n", istat);
  return (istat);
}
```