user: Please show me the C implementation that matches the assembly code listed below:

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x20000(%rsp),%r11
L85:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L85
  sub    $0x438,%rsp
  mov    %fs:0x28,%rdx
  mov    %rdx,0x20428(%rsp)
  xor    %edx,%edx
  cmp    $0x1,%edi
  jle    L88
  cmp    $0x2,%edi
  je     L145
  lea    D80(%rip),%rdi
  call   <printf@plt>
L51:
  mov    0x20428(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L101
  add    $0x20438,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L145:
  mov    0x8(%rsi),%rdi
  mov    %rsi,%rbx
  lea    D60(%rip),%rsi
  lea    0x420(%rsp),%r12
  call   <fopen@plt>
  mov    $0x10000,%edx
  mov    $0x1,%esi
  mov    %r12,%rdi
  mov    %rax,%rcx
  mov    %rax,%rbp
  call   <fread@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    0x8(%rbx),%rdi
  lea    D66(%rip),%rsi
  call   <strtok@plt>
  lea    D15(%rip),%rdi
  mov    %rax,(%rsp)
  call   <printf@plt>
  lea    0x1c(%rsp),%rsi
  lea    D34(%rip),%rdi
  call   <scanf@plt>
  mov    0x1c(%rsp),%edi
  mov    0x20(%rsp),%edx
  xor    %r8d,%r8d
  mov    0x41c(%rsp),%ecx
  xor    %esi,%esi
  xor    %eax,%eax
  jmp    L0
  nopw   0x0(%rax,%rax,1)
L56:
  add    $0x1,%eax
  add    $0x1,%edx
  mov    $0x1,%esi
  cmp    $0x100,%eax
  je     L169
L0:
  cmp    %eax,%edi
  jg     L56
  add    $0x1,%eax
  add    $0x1,%ecx
  mov    $0x1,%r8d
  cmp    $0x100,%eax
  jne    L0
L169:
  test   %r8b,%r8b
  je     L30
  mov    %ecx,0x41c(%rsp)
L30:
  test   %sil,%sil
  je     L158
  mov    %edx,0x20(%rsp)
L158:
  lea    0x10420(%rsp),%rsi
  mov    %r12,%rcx
  mov    %rsi,0x8(%rsp)
  mov    %rsi,%r8
L10:
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L54:
  movzbl (%rcx,%rax,1),%edx
  cmp    %edx,%edi
  setl   %dl
  neg    %edx
  mov    %dl,(%rsi,%rax,1)
  add    $0x1,%rax
  cmp    $0x100,%rax
  jne    L54
  add    $0x100,%rcx
  add    $0x100,%rsi
  cmp    %r8,%rcx
  jne    L10
  mov    (%rsp),%rdi
  lea    D53(%rip),%r15
  lea    D77(%rip),%r14
  mov    %r15,%rsi
  call   <strcmp@plt>
  mov    %r14,%rsi
  test   %rax,%rax
  jne    L13
  lea    D23(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r12
L178:
  xor    %ebx,%ebx
  lea    0x20(%rsp),%rbp
  lea    D96(%rip),%r13
L62:
  mov    0x0(%rbp,%rbx,4),%ecx
  mov    %ebx,%edx
  mov    %r13,%rsi
  mov    %r12,%rdi
  add    $0x1,%rbx
  call   <fprintf@plt>
  cmp    $0x100,%rbx
  jne    L62
  mov    %r12,%rdi
  call   <fclose@plt>
  mov    (%rsp),%rdi
  mov    %r15,%rsi
  call   <strcmp@plt>
  mov    %r14,%rsi
  test   %rax,%rax
  jne    L142
  lea    D112(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
L173:
  mov    0x8(%rsp),%rdi
  mov    $0x1,%esi
  mov    %r13,%rcx
  mov    $0x10000,%edx
  call   <fwrite@plt>
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    (%rsp),%rdi
  mov    %r15,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L94
  lea    D29(%rip),%rdi
  call   <system@plt>
  jmp    L51
L13:
  lea    D24(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r12
  jmp    L178
L94:
  lea    D116(%rip),%rdi
  call   <system@plt>
  jmp    L51
L142:
  lea    D94(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  jmp    L173
L88:
  lea    D70(%rip),%rdi
  call   <printf@plt>
  jmp    L51
L101:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_tag: D80
data_type: string
name: unpack_data
arguments: data_tag: D60
data_type: string
name: unpack_data
arguments: data_tag: D66
data_type: string
name: unpack_data
arguments: data_tag: D15
data_type: string
name: unpack_data
arguments: data_tag: D34
data_type: string
name: unpack_data
arguments: data_tag: D53
data_type: string
name: unpack_data
arguments: data_tag: D77
data_type: string
name: unpack_data
arguments: data_tag: D23
data_type: string
name: unpack_data
arguments: data_tag: D96
data_type: string
name: unpack_data
arguments: data_tag: D112
data_type: string
name: unpack_data
arguments: data_tag: D29
data_type: string
name: unpack_data
arguments: data_tag: D24
data_type: string
name: unpack_data
arguments: data_tag: D116
data_type: string
name: unpack_data
arguments: data_tag: D94
data_type: string
name: unpack_data
arguments: data_tag: D70
data_type: string

tool: D80: many arguments


tool: D60: rb

tool: D66: .

tool: D15: input theta value


tool: D34: %d

tool: D53: girl

tool: D77: wb

tool: D23: plot_ex1girl.dat

tool: D96: %3d %3d


tool: D112: girlex1_binary.dat

tool: D29: zsh mode_girl.sh

tool: D24: plot_ex1ei.dat

tool: D116: zsh mode_ei.sh

tool: D94: eiex1_binary.dat

tool: D70: don't read filename


assistant: ```c
int main(int argc, char *argv[]) {
  unsigned char image[256][256];
  unsigned char image_w[256][256];
  int histgram[256] = {0};
  int mode;
  char *fn;
  FILE *fp;
  if (argc < 2) {
    printf("don't read filename\n");
    return 0;
  } else if (argc > 2) {
    printf("many arguments\n");
    return 0;
  } else {
    fp = fopen(argv[1], "rb");
    fread(image, sizeof(unsigned char), 256 * 256, fp);
    fclose(fp);
    fn = strtok(argv[1], ".");
    printf("input theta value\n");
    scanf("%d", &mode);
    int newhist[256];
    for (int i = 0; i < 256; i++) {
      if (i < mode) {
        newhist[0]++;
      } else {
        newhist[255]++;
      }
    }
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        if (image[i][j] > mode) {
          image_w[i][j] = 255;
        } else {
          image_w[i][j] = 0;
        }
      }
    }
    if (strcmp(fn, "girl") == 0) {
      fp = fopen("plot_ex1girl.dat", "wb");
    } else {
      fp = fopen("plot_ex1ei.dat", "wb");
    }
    for (int i = 0; i < 256; i++) {
      fprintf(fp, "%3d %3d\n", i, newhist[i]);
    }
    fclose(fp);
    if (strcmp(fn, "girl") == 0) {
      fp = fopen("girlex1_binary.dat", "wb");
    } else {
      fp = fopen("eiex1_binary.dat", "wb");
    }
    fwrite(image_w, sizeof(unsigned char), 256 * 256, fp);
    fclose(fp);
    if (strcmp(fn, "girl") == 0) {
      system("zsh mode_girl.sh");
    } else {
      system("zsh mode_ei.sh");
    }
    return 0;
  }
}
```