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

```asm
<sqlite_swap>:
  endbr64
  push   %r15
  mov    %rdx,%rcx
  xor    %eax,%eax
  mov    %rdx,%r15
  push   %r14
  mov    %rsi,%rdx
  push   %r13
  mov    %rsi,%r13
  lea    D20(%rip),%rsi
  push   %r12
  mov    %rdi,%r12
  mov    $0x3,%edi
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  call   <logprintf@plt>
  lea    D72(%rip),%rsi
  mov    %r12,%rdi
  call   <database_prepare@plt>
  lea    D4(%rip),%rsi
  mov    %r12,%rdi
  mov    %rax,%rbp
  call   <database_prepare@plt>
  test   %rbp,%rbp
  je     L254
  mov    %rax,%r14
  test   %rax,%rax
  je     L254
  mov    %r13,%rdx
  mov    $0x1,%esi
  mov    %rbp,%rdi
  call   <sqlite3_bind_int@plt>
  test   %rax,%rax
  jne    L254
  mov    %rbp,%rdi
  call   <sqlite3_step@plt>
  cmp    $0x80,%eax
  je     L166
  cmp    $0x82,%eax
  je     L155
  mov    %r12,%rdi
  xor    %ebx,%ebx
  call   <sqlite3_errmsg@plt>
  lea    D32(%rip),%rsi
  xor    %edi,%edi
  mov    %rax,%rdx
  xor    %eax,%eax
  call   <logprintf@plt>
  mov    %rbp,%rdi
  call   <sqlite3_finalize@plt>
  movq   $0x0,(%rsp)
  movq   $0x0,0x8(%rsp)
L187:
  xor    %r8d,%r8d
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    %r12,%rdi
  lea    D22(%rip),%rsi
  call   <sqlite3_exec@plt>
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <sqlite_delete_address@plt>
  test   %rax,%rax
  je     L63
  mov    %r14,%rdi
  mov    $0x15,%r13d
  call   <sqlite3_step@plt>
  sub    $0x81,%eax
  cmp    $0x1,%eax
  ja     L163
L221:
  xor    %r8d,%r8d
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    %r12,%rdi
  lea    D57(%rip),%rsi
  call   <sqlite3_exec@plt>
L230:
  mov    %r14,%rdi
  call   <sqlite3_finalize@plt>
  test   %rbx,%rbx
  je     L9
  mov    %rbx,%rdi
  call   <free@plt>
L9:
  mov    (%rsp),%rax
  test   %rax,%rax
  je     L197
  mov    %rax,%rdi
  call   <free@plt>
L197:
  mov    0x8(%rsp),%rax
  test   %rax,%rax
  je     L252
  mov    %rax,%rdi
  call   <free@plt>
  jmp    L252
  nopl   (%rax)
L155:
  mov    %r13,%rdx
  lea    D13(%rip),%rsi
  xor    %edi,%edi
  xor    %eax,%eax
  call   <logprintf@plt>
  mov    %rbp,%rdi
  mov    $0x14,%r13d
  call   <sqlite3_finalize@plt>
  mov    %r14,%rdi
  call   <sqlite3_finalize@plt>
L252:
  add    $0x18,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L166:
  xor    %esi,%esi
  mov    %rbp,%rdi
  call   <sqlite3_column_text@plt>
  mov    %rax,%rdi
  call   <common_strdup@plt>
  mov    $0x1,%esi
  mov    %rbp,%rdi
  mov    %rax,%rbx
  call   <sqlite3_column_text@plt>
  mov    %rax,%rdi
  call   <common_strdup@plt>
  mov    $0x2,%esi
  mov    %rbp,%rdi
  mov    %rax,(%rsp)
  call   <sqlite3_column_text@plt>
  movq   $0x0,0x8(%rsp)
  test   %rax,%rax
  jne    L113
L44:
  mov    %rbp,%rdi
  test   %rbx,%rbx
  je     L182
  cmpq   $0x0,(%rsp)
  je     L182
  call   <sqlite3_finalize@plt>
  jmp    L187
  cs nopw 0x0(%rax,%rax,1)
L63:
  mov    %r13,%rdx
  mov    $0x1,%esi
  mov    %r14,%rdi
  call   <sqlite3_bind_int@plt>
  cmp    $0x81,%rax
  je     L222
L7:
  mov    %r14,%rdi
  mov    $0x16,%r13d
  call   <sqlite3_step@plt>
  sub    $0x81,%eax
  cmp    $0x1,%eax
  jbe    L221
L163:
  mov    %r12,%rdi
  mov    $0x17,%r13d
  call   <sqlite3_errmsg@plt>
  lea    D44(%rip),%rsi
  xor    %edi,%edi
  mov    %rax,%rdx
  xor    %eax,%eax
  call   <logprintf@plt>
  jmp    L221
  xchg   %ax,%ax
L182:
  call   <sqlite3_finalize@plt>
  mov    $0x13,%r13d
  jmp    L230
L113:
  mov    $0x2,%esi
  mov    %rbp,%rdi
  call   <sqlite3_column_text@plt>
  mov    %rax,%rdi
  call   <common_strdup@plt>
  mov    %rax,0x8(%rsp)
  jmp    L44
  nop
L254:
  lea    D10(%rip),%rsi
  xor    %edi,%edi
  xor    %eax,%eax
  mov    $0xffffffff,%r13d
  call   <logprintf@plt>
  jmp    L252
  nopl   0x0(%rax,%rax,1)
L222:
  mov    %r15,%rdx
  mov    $0x2,%esi
  mov    %r14,%rdi
  call   <sqlite3_bind_int@plt>
  cmp    $0x81,%rax
  jne    L7
  mov    %r14,%rdi
  call   <sqlite3_step@plt>
  sub    $0x81,%eax
  cmp    $0x1,%eax
  ja     L163
  mov    0x8(%rsp),%r8
  mov    (%rsp),%rcx
  mov    %r15,%rdx
  mov    %rbx,%rsi
  mov    %r12,%rdi
  call   <sqlite_add_address_order@plt>
  test   %rax,%rax
  je     L176
  mov    $0x18,%r13d
  jmp    L221
  nopl   0x0(%rax)
L176:
  xor    %r8d,%r8d
  xor    %ecx,%ecx
  xor    %edx,%edx
  mov    %r12,%rdi
  lea    D87(%rip),%rsi
  xor    %r13d,%r13d
  call   <sqlite3_exec@plt>
  jmp    L230
```

tool_calls: name: unpack_data
arguments: data_tag: D20
type_guessed: string
name: unpack_data
arguments: data_tag: D72
type_guessed: string
name: unpack_data
arguments: data_tag: D4
type_guessed: string
name: unpack_data
arguments: data_tag: D32
type_guessed: string
name: unpack_data
arguments: data_tag: D22
type_guessed: string
name: unpack_data
arguments: data_tag: D57
type_guessed: string
name: unpack_data
arguments: data_tag: D13
type_guessed: string
name: unpack_data
arguments: data_tag: D44
type_guessed: string
name: unpack_data
arguments: data_tag: D10
type_guessed: string
name: unpack_data
arguments: data_tag: D87
type_guessed: string

tool: D20: order1: %d, order2: %d


tool: D72: SELECT address_expression, address_router, address_route FROM addresses WHERE address_order = ?;

tool: D4: UPDATE addresses SET address_order = ? WHERE address_order = ?;

tool: D32: Unhandled failure: %s


tool: D22: BEGIN TRANSACTION

tool: D57: ROLLBACK

tool: D13: No expression with order %d


tool: D44: Failed to update address record: %s


tool: D10: Failed to prepare or bind statement


tool: D87: COMMIT

assistant: ```c
int sqlite_swap(sqlite3 *db, long first, long second) {
  int status = 0;
  char *expression = NULL;
  char *router = NULL;
  char *route = NULL;
  logprintf(3, "order1: %d, order2: %d\n", first, second);
  sqlite3_stmt *fetch = database_prepare(db, "SELECT address_expression, address_router, address_route FROM addresses WHERE address_order = ?;");
  sqlite3_stmt *update = database_prepare(db, "UPDATE addresses SET address_order = ? WHERE address_order = ?;");
  if (!fetch || !update || sqlite3_bind_int(fetch, 1, first)) {
    logprintf(0, "Failed to prepare or bind statement\n");
    return -1;
  }
  switch (sqlite3_step(fetch)) {
  case SQLITE_ROW:
    expression = common_strdup((char *)sqlite3_column_text(fetch, 0));
    router = common_strdup((char *)sqlite3_column_text(fetch, 1));
    if (sqlite3_column_text(fetch, 2)) {
      route = common_strdup((char *)sqlite3_column_text(fetch, 2));
    }
    if (!expression || !router) {
      status = 19;
    }
    break;
  case SQLITE_DONE:
    logprintf(0, "No expression with order %d\n", first);
    status = 20;
    break;
  default:
    logprintf(0, "Unhandled failure: %s\n", sqlite3_errmsg(db));
    break;
  }
  sqlite3_finalize(fetch);
  if (!status) {
    sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL);
    if (sqlite_delete_address(db, first) != 0) {
      status = 21;
    }
    if (!status && (sqlite3_bind_int(update, 1, first) != SQLITE_OK || sqlite3_bind_int(update, 2, second) != SQLITE_OK)) {
      status = 22;
    }
    switch (sqlite3_step(update)) {
    case SQLITE_DONE:
    case SQLITE_OK:
      break;
    default:
      logprintf(0, "Failed to update address record: %s\n", sqlite3_errmsg(db));
      status = 23;
      break;
    }
    if (!status && sqlite_add_address_order(db, expression, second, router, route) != 0) {
      status = 24;
    }
    if (status) {
      sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
    } else {
      sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
    }
  }
  sqlite3_finalize(update);
  if (expression) {
    free(expression);
  }
  if (router) {
    free(router);
  }
  if (route) {
    free(route);
  }
  return status;
}
```