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

```asm
<test_strfmt>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x818,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x808(%rsp)
  xor    %eax,%eax
  mov    %rsp,%rbx
  movabs $0x1b69b4bacd05f15,%r12
  mov    %r12,%rcx
  lea    D168(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  call   <strfmt@plt>
  mov    %eax,%r13d
  lea    0x400(%rsp),%rbp
  mov    %r12,%rcx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x12,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    $0x7b,%ecx
  lea    D122(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r13d
  mov    $0x7b,%ecx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x6,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    $0xffffff85,%ecx
  lea    D62(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r13d
  mov    $0xffffff85,%ecx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x4,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  lea    D129(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r13d
  mov    %r12,%rcx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x12,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    $0x7b,%ecx
  lea    D12(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r13d
  mov    $0x7b,%ecx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x6,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  lea    D3(%rip),%r14
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r13d
  mov    %r12,%rcx
  mov    %r14,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0xf,%r13d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    $0x7b,%ecx
  lea    D146(%rip),%r13
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r12d
  mov    $0x7b,%ecx
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x2,%r12d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    $0x123,%ecx
  lea    D158(%rip),%r13
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r12d
  mov    $0x123,%ecx
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x6,%r12d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  lea    D7(%rip),%r12
  mov    %r12,%rcx
  lea    D82(%rip),%r13
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r14d
  mov    %r12,%rcx
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x15,%r14d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  lea    D151(%rip),%r15
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r14d
  mov    %r12,%rcx
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x15,%r14d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  lea    D149(%rip),%r15
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r14d
  mov    %r12,%rcx
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x27,%r14d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  lea    D131(%rip),%r15
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r14d
  mov    %r12,%rcx
  mov    %r15,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0x27,%r14d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %r12,%rcx
  mov    %r13,%rdx
  mov    $0xa,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r14d
  mov    %r12,%rcx
  mov    %r13,%rdx
  mov    $0xa,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <hack_snprintf@plt>
  cmp    %eax,%r14d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  sub    $0x8,%rsp
  push   $0x2e
  lea    D55(%rip),%r9
  mov    $0x20,%r8d
  lea    D81(%rip),%r14
  mov    %r14,%rcx
  lea    D126(%rip),%r13
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <strfmt@plt>
  mov    %eax,%r12d
  movl   $0x2e,(%rsp)
  lea    D55(%rip),%r9
  mov    $0x20,%r8d
  mov    %r14,%rcx
  mov    %r13,%rdx
  mov    $0x400,%esi
  mov    %rbp,%rdi
  mov    $0x0,%eax
  call   <snprintf@plt>
  cmp    $0xc,%r12d
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  sete   %dil
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <assert@plt>
  mov    %rbx,%rsp
  mov    0x808(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L7
  add    $0x818,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L7:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D168
datatype: string
name: retrieve_data
arguments: tag: D122
datatype: string
name: retrieve_data
arguments: tag: D62
datatype: string
name: retrieve_data
arguments: tag: D129
datatype: string
name: retrieve_data
arguments: tag: D12
datatype: string
name: retrieve_data
arguments: tag: D3
datatype: string
name: retrieve_data
arguments: tag: D146
datatype: string
name: retrieve_data
arguments: tag: D158
datatype: string
name: retrieve_data
arguments: tag: D7
datatype: string
name: retrieve_data
arguments: tag: D82
datatype: string
name: retrieve_data
arguments: tag: D151
datatype: string
name: retrieve_data
arguments: tag: D149
datatype: string
name: retrieve_data
arguments: tag: D131
datatype: string
name: retrieve_data
arguments: tag: D55
datatype: string
name: retrieve_data
arguments: tag: D81
datatype: string
name: retrieve_data
arguments: tag: D126
datatype: string

tool: D168: %06ld

tool: D122: %06d

tool: D62: %d

tool: D129: %06lu

tool: D12: %06u

tool: D3: %lx

tool: D146: %x

tool: D158: %6x

tool: D7: hello world

tool: D82: test %s this

tool: D151: test %5s this

tool: D149: test %-29s this

tool: D131: test %29s this

tool: D55: world

tool: D81: hello

tool: D126: %s%c%s%c

assistant: ```c
void test_strfmt(void) {
  char str1[1024], str2[1024];
  int n1, n2;
  n1 = strfmt(str1, sizeof(str1), "%06ld", 123456789123456789ul);
  n2 = snprintf(str2, sizeof(str2), "%06ld", 123456789123456789ul);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%06d", 123);
  n2 = snprintf(str2, sizeof(str2), "%06d", 123);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%d", -123);
  n2 = snprintf(str2, sizeof(str2), "%d", -123);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%06lu", 123456789123456789ul);
  n2 = snprintf(str2, sizeof(str2), "%06lu", 123456789123456789ul);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%06u", 123);
  n2 = snprintf(str2, sizeof(str2), "%06u", 123);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%lx", 123456789123456789ul);
  n2 = snprintf(str2, sizeof(str2), "%lx", 123456789123456789ul);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%x", 123);
  n2 = snprintf(str2, sizeof(str2), "%x", 123);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%6x", 0x123);
  n2 = snprintf(str2, sizeof(str2), "%6x", 0x123);
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "test %s this", "hello world");
  n2 = snprintf(str2, sizeof(str2), "test %s this", "hello world");
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "test %5s this", "hello world");
  n2 = snprintf(str2, sizeof(str2), "test %5s this", "hello world");
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "test %-29s this", "hello world");
  n2 = snprintf(str2, sizeof(str2), "test %-29s this", "hello world");
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "test %29s this", "hello world");
  n2 = snprintf(str2, sizeof(str2), "test %29s this", "hello world");
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, 10, "test %s this", "hello world");
  n2 = hack_snprintf(str2, 10, "test %s this", "hello world");
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
  n1 = strfmt(str1, sizeof(str1), "%s%c%s%c", "hello", ' ', "world", '.');
  n2 = snprintf(str2, sizeof(str2), "%s%c%s%c", "hello", ' ', "world", '.');
  assert(n1 == n2);
  assert(strcmp(str1, str2) == 0);
}
```