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

```asm
<AddAttributesToDisplayOfCurrentMetaMode>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x328,%rsp
  mov    %rdi,%r13
  mov    %esi,%r14d
  mov    %edx,%ebx
  mov    %rcx,%r15
  mov    %fs:0x28,%rax
  mov    %rax,0x318(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x8(%rsp)
  lea    0x8(%rsp),%r8
  mov    $0x2d,%ecx
  mov    $0x0,%edx
  call   <XNVCTRLQueryStringAttribute@plt>
  lea    D31(%rip),%rsi
  mov    0x8(%rsp),%rdi
  call   <strstr@plt>
  lea    0x2(%rax),%r12
  lea    0x110(%rsp),%rbp
  mov    %ebx,%edx
  lea    D34(%rip),%rsi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <strstr@plt>
  mov    $0x0,%ebp
  mov    $0x1,%ecx
  mov    $0x1,%ebx
  test   %rax,%rax
  jne    L75
  jmp    L71
L116:
  mov    %ecx,%ebp
L24:
  mov    %rbx,%rax
L75:
  lea    0x1(%rax),%rbx
  movzbl 0x1(%rax),%edx
  test   %dl,%dl
  je     L121
  cmp    $0x7b,%dl
  je     L116
  cmp    $0x7d,%dl
  je     L1
  cmp    $0x2c,%dl
  jne    L24
  test   %ebp,%ebp
  jne    L24
  mov    $0x0,%ebp
L1:
  movb   $0x0,(%rbx)
  lea    0x2(%rax),%rbx
L57:
  test   %ebp,%ebp
  je     L108
  lea    0x10(%rsp),%rdi
  mov    %r15,%rdx
  lea    D40(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
L87:
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  lea    0x10(%rsp),%rdi
  call   <strlen@plt>
  add    %eax,%ebp
  mov    %rbx,%rdi
  call   <strlen@plt>
  lea    0x3(%rbp,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L9
  lea    0x10(%rsp),%rcx
  mov    %rbx,%r8
  mov    %r12,%rdx
  lea    D21(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %rbp,%r8
  mov    $0x2d,%ecx
  mov    $0x0,%edx
  mov    %r14d,%esi
  mov    %r13,%rdi
  call   <XNVCTRLSetStringAttribute@plt>
  mov    $0x0,%esi
  mov    %r13,%rdi
  call   <XSync@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    $0x0,%ebx
L71:
  mov    0x8(%rsp),%rdi
  test   %rdi,%rdi
  je     L112
  call   <free@plt>
L112:
  mov    0x318(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L115
  mov    %ebx,%eax
  add    $0x328,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L108:
  lea    0x10(%rsp),%rdi
  mov    %r15,%rdx
  lea    D8(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
  jmp    L87
L9:
  mov    $0x1,%ebx
  jmp    L71
L121:
  lea    0x10(%rsp),%rdi
  mov    %r15,%rdx
  lea    D26(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
  jmp    L57
L115:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D31
datatype: string
name: unpack_data
arguments: label: D34
datatype: string
name: unpack_data
arguments: label: D40
datatype: string
name: unpack_data
arguments: label: D21
datatype: string
name: unpack_data
arguments: label: D8
datatype: string
name: unpack_data
arguments: label: D26
datatype: string

tool: D31: ::

tool: D34: DPY-%i

tool: D40: , %s}

tool: D21: %s%s%s

tool: D8:  {%s},

tool: D26:  {%s}

assistant: ```c
int AddAttributesToDisplayOfCurrentMetaMode(Display *xDpy, int screenId, int nvDpyId, const char *attributes) {
  char *pOldCurrentMetaMode = NULL;
  char *pCurrentMetaMode = NULL;
  char displayName[512];
  char *pDisplay;
  char *newMetaMode = NULL;
  int error = 1;
  XNVCTRLQueryStringAttribute(xDpy, screenId, 0, 45, &pOldCurrentMetaMode);
  pCurrentMetaMode = strstr(pOldCurrentMetaMode, "::");
  pCurrentMetaMode += 2;
  sprintf(displayName, "DPY-%i", nvDpyId);
  pDisplay = strstr(pCurrentMetaMode, displayName);
  if (pDisplay) {
    int foundBeginAttr = 0;
    char newAttribute[256];
    int endOfString = 1;
    int neededLength;
    while (*(++pDisplay)) {
      if (*pDisplay == '{') {
        foundBeginAttr = 1;
      }
      if (*pDisplay == '}') {
        endOfString = 0;
        break;
      }
      if (*pDisplay == ',' && !foundBeginAttr) {
        endOfString = 0;
        break;
      }
    }
    if (!endOfString) {
      *pDisplay = 0;
      pDisplay++;
    }
    if (endOfString) {
      sprintf(newAttribute, " {%s}", attributes);
    }
    if (foundBeginAttr) {
      sprintf(newAttribute, ", %s}", attributes);
    } else {
      sprintf(newAttribute, " {%s},", attributes);
    }
    neededLength = strlen(pCurrentMetaMode) + strlen(newAttribute) + strlen(pDisplay);
    newMetaMode = malloc(neededLength + 3);
    if (!newMetaMode) {
      goto cleanup;
    }
    sprintf(newMetaMode, "%s%s%s", pCurrentMetaMode, newAttribute, pDisplay);
  } else {
    goto cleanup;
  }
  XNVCTRLSetStringAttribute(xDpy, screenId, 0, 45, newMetaMode);
  XSync(xDpy, 0);
  error = 0;
cleanup:
  if (newMetaMode) {
    free(newMetaMode);
  }
  if (pOldCurrentMetaMode) {
    free(pOldCurrentMetaMode);
  }
  return error;
}
```