user: Converte this assembly snippet into its equivalent C code:

```asm
<write_texture>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  mov    %rsi,%rbx
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    D25(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L20
L2:
  lea    0x14(%rsp),%rcx
  lea    0x10(%rsp),%rdx
  lea    0xc(%rsp),%rsi
  mov    %rbx,%rdi
  call   <jpeg_load@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L142
L67:
  mov    0x10(%rsp),%eax
  imul   0xc(%rsp),%eax
  lea    (%rax,%rax,2),%edi
  shl    $0x2,%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L65
L124:
  mov    0xc(%rsp),%eax
  mov    0x10(%rsp),%r8d
  mov    %eax,%edx
  imul   %r8d,%edx
  test   %edx,%edx
  jle    L105
  mov    %rbp,%rdi
  lea    0x4(%rbp),%rsi
  lea    0x8(%rbp),%rcx
  mov    $0x0,%edx
  movss  D11(%rip),%xmm2
  movaps %xmm2,%xmm1
  movaps %xmm2,%xmm3
  jmp    L11
L20:
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L2
L142:
  lea    D0(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L67
L65:
  lea    D2(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L124
L108:
  movzbl (%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm2,%xmm0
  movss  %xmm0,(%rdi)
  movzbl 0x1(%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm2,%xmm0
  movss  %xmm0,(%rsi)
  movss  %xmm0,(%rcx)
  lea    0x2(%rbx),%rbx
L88:
  add    $0x1,%edx
  mov    0xc(%rsp),%eax
  mov    0x10(%rsp),%r8d
  add    $0xc,%rdi
  add    $0xc,%rsi
  add    $0xc,%rcx
  mov    %eax,%r9d
  imul   %r8d,%r9d
  cmp    %edx,%r9d
  jle    L105
L11:
  mov    0x14(%rsp),%eax
  cmp    $0x2,%eax
  je     L108
  cmp    $0x3,%eax
  je     L22
  cmp    $0x1,%eax
  jne    L88
  movzbl (%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm3,%xmm0
  movss  %xmm0,(%rdi)
  movss  %xmm0,(%rsi)
  movss  %xmm0,(%rcx)
  lea    0x1(%rbx),%rbx
  jmp    L88
L22:
  movzbl (%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm1,%xmm0
  movss  %xmm0,(%rdi)
  movzbl 0x1(%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm1,%xmm0
  movss  %xmm0,(%rsi)
  movzbl 0x2(%rbx),%eax
  pxor   %xmm0,%xmm0
  cvtsi2ss %eax,%xmm0
  mulss  %xmm1,%xmm0
  movss  %xmm0,(%rcx)
  lea    0x3(%rbx),%rbx
  jmp    L88
L105:
  mov    $0x0,%ecx
  mov    %r8d,%edx
  mov    %eax,%esi
  mov    %r12,%rdi
  call   <RGBE_WriteHeader@plt>
  mov    0x10(%rsp),%ecx
  mov    0xc(%rsp),%edx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <RGBE_WritePixels_RLE@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  add    $0x20,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L19:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D25
type_guessed: string
name: unpack_data
arguments: tag: D11
type_guessed: byte[4]
name: unpack_data
arguments: tag: D0
type_guessed: string
name: unpack_data
arguments: tag: D2
type_guessed: string

tool: D25: wb

tool: {"D11": [0x00,0x00,0x80,0x3b]}

tool: D0: can't load jpeg file.


tool: D2: muda muda muda!


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);
}
```