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

```asm
<write_texture>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x48(%rbp),%rax
  lea    D8(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L107
  mov    $0xffffffff,%edi
  call   <exit@plt>
L107:
  lea    -0x2c(%rbp),%rcx
  lea    -0x30(%rbp),%rdx
  lea    -0x34(%rbp),%rsi
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <jpeg_load@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L96
  lea    D51(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
L96:
  mov    -0x34(%rbp),%eax
  cltq
  mov    %eax,%edx
  mov    -0x30(%rbp),%eax
  cltq
  imul   %eax,%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L14
  lea    D55(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
L14:
  movl   $0x0,-0x28(%rbp)
  jmp    L83
L24:
  mov    -0x28(%rbp),%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  mov    %eax,-0x24(%rbp)
  mov    -0x2c(%rbp),%eax
  cmp    $0x3,%eax
  je     L91
  cmp    $0x3,%eax
  jg     L115
  cmp    $0x1,%eax
  je     L29
  cmp    $0x2,%eax
  je     L100
  jmp    L115
L29:
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rcx
  mov    -0x10(%rbp),%rax
  add    %rcx,%rax
  movss  (%rdx),%xmm0
  movss  %xmm0,(%rax)
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x2,%rax
  lea    0x0(,%rax,4),%rcx
  mov    -0x10(%rbp),%rax
  add    %rcx,%rax
  movss  (%rdx),%xmm0
  movss  %xmm0,(%rax)
  jmp    L115
L100:
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x2,%rax
  lea    0x0(,%rax,4),%rcx
  mov    -0x10(%rbp),%rax
  add    %rcx,%rax
  movss  (%rdx),%xmm0
  movss  %xmm0,(%rax)
  jmp    L115
L91:
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x2,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movss  D48(%rip),%xmm1
  divss  %xmm1,%xmm0
  movss  %xmm0,(%rax)
  nop
L115:
  addl   $0x1,-0x28(%rbp)
L83:
  mov    -0x34(%rbp),%edx
  mov    -0x30(%rbp),%eax
  imul   %edx,%eax
  cmp    %eax,-0x28(%rbp)
  jl     L24
  mov    -0x30(%rbp),%edx
  mov    -0x34(%rbp),%esi
  mov    -0x18(%rbp),%rax
  mov    $0x0,%ecx
  mov    %rax,%rdi
  call   <RGBE_WriteHeader@plt>
  mov    -0x30(%rbp),%ecx
  mov    -0x34(%rbp),%edx
  mov    -0x10(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <RGBE_WritePixels_RLE@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L21
  call   <__stack_chk_fail@plt>
L21:
  leave
  ret
```

tool_calls: name: read_data
arguments: label: D8
type: string
name: read_data
arguments: label: D51
type: string
name: read_data
arguments: label: D55
type: string
name: read_data
arguments: label: D48
type: byte[4]

tool: D8: wb

tool: D51: can't load jpeg file.


tool: D55: muda muda muda!


tool: {"D48": [0x00,0x00,0x80,0x43]}

assistant: ```c
void write_texture(const char *filename, const char *jpegfile) {
  FILE *fp;
  unsigned char *img;
  int width;
  int height;
  int compos;
  int i;
  int ival;
  int idx;
  float *data;
  float fval;
  fp = fopen(filename, "wb");
  if (!fp)
    exit(-1);
  img = jpeg_load(jpegfile, &width, &height, &compos);
  if (img == NULL) {
    printf("can't load jpeg file.\n");
    exit(-1);
  }
  data = (float *)malloc(sizeof(float) * width * height * 3);
  if (!data) {
    printf("muda muda muda!\n");
    exit(-1);
  }
  for (i = 0; i < width * height; i++) {
    idx = 3 * i;
    switch (compos) {
    case 1:
      data[idx + 0] = (float)(*img++) / (256.0f);
      data[idx + 1] = data[idx + 0];
      data[idx + 2] = data[idx + 1];
      break;
    case 2:
      data[idx + 0] = (float)(*img++) / (256.0f);
      data[idx + 1] = (float)(*img++) / (256.0f);
      data[idx + 2] = data[idx + 1];
      break;
    case 3:
      data[idx + 0] = (float)(*img++) / (256.0f);
      data[idx + 1] = (float)(*img++) / (256.0f);
      data[idx + 2] = (float)(*img++) / (256.0f);
      break;
    }
  }
  RGBE_WriteHeader(fp, width, height, NULL);
  RGBE_WritePixels_RLE(fp, data, width, height);
}
```