user: Translate the below assembly code into C programming language:

```asm
<write_texture>:
  endbr64
  push   %r12
  mov    %rsi,%r12
  lea    D34(%rip),%rsi
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L97
L50:
  lea    0x14(%rsp),%rcx
  lea    0x10(%rsp),%rdx
  mov    %r12,%rdi
  lea    0xc(%rsp),%rsi
  call   <jpeg_load@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L21
L156:
  mov    0x10(%rsp),%eax
  imul   0xc(%rsp),%eax
  lea    (%rax,%rax,2),%edi
  shl    $0x2,%edi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L33
L154:
  mov    0xc(%rsp),%r8d
  mov    0x10(%rsp),%r9d
  mov    %r8d,%edi
  imul   %r9d,%edi
  test   %edi,%edi
  jle    L157
  lea    (%rdi,%rdi,2),%rdi
  mov    0x14(%rsp),%edx
  mov    %r12,%rax
  lea    0x8(%r12),%rcx
  movss  D11(%rip),%xmm0
  lea    0x4(%r12),%rsi
  lea    (%r12,%rdi,4),%rdi
  jmp    L128
  cs nopw 0x0(%rax,%rax,1)
L47:
  cmp    $0x1,%edx
  je     L74
L10:
  add    $0xc,%rax
  add    $0xc,%rcx
  add    $0xc,%rsi
  cmp    %rax,%rdi
  je     L157
L128:
  cmp    $0x2,%edx
  je     L96
  cmp    $0x3,%edx
  jne    L47
  movzbl (%rbx),%r10d
  pxor   %xmm1,%xmm1
  add    $0x3,%rbx
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movss  %xmm1,(%rax)
  movzbl -0x2(%rbx),%r10d
  pxor   %xmm1,%xmm1
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movss  %xmm1,(%rsi)
  movzbl -0x1(%rbx),%r10d
  pxor   %xmm1,%xmm1
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movss  %xmm1,(%rcx)
  jmp    L10
  nop
L96:
  movzbl (%rbx),%r10d
  pxor   %xmm1,%xmm1
  add    $0x2,%rbx
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movss  %xmm1,(%rax)
  movzbl -0x1(%rbx),%r10d
  pxor   %xmm1,%xmm1
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movss  %xmm1,(%rsi)
  movss  %xmm1,(%rcx)
  jmp    L10
  nopl   0x0(%rax,%rax,1)
L74:
  movzbl (%rbx),%r10d
  pxor   %xmm1,%xmm1
  add    $0x1,%rbx
  cvtsi2ss %r10d,%xmm1
  mulss  %xmm0,%xmm1
  movaps %xmm1,%xmm2
  shufps $0xe0,%xmm2,%xmm2
  movlps %xmm2,(%rax)
  movss  %xmm1,(%rcx)
  jmp    L10
  nopl   0x0(%rax,%rax,1)
L157:
  xor    %ecx,%ecx
  mov    %r9d,%edx
  mov    %r8d,%esi
  mov    %rbp,%rdi
  call   <RGBE_WriteHeader@plt>
  mov    0x10(%rsp),%ecx
  mov    0xc(%rsp),%edx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <RGBE_WritePixels_RLE@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x20,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax)
L33:
  lea    D36(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L154
  nopl   0x0(%rax,%rax,1)
L21:
  lea    D4(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L156
  nopl   0x0(%rax,%rax,1)
L97:
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L50
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: tag: D34
type_infered: string
name: extract_symbolic_data
arguments: tag: D11
type_infered: byte[4]
name: extract_symbolic_data
arguments: tag: D36
type_infered: string
name: extract_symbolic_data
arguments: tag: D4
type_infered: string

tool: D34: wb

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

tool: D36: muda muda muda!


tool: D4: can't load jpeg file.


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