user: Please show me the C implementation that matches the assembly code listed below:

```asm
<main>:
  endbr64
  push   %r14
  mov    $0x9,%edx
  lea    D97(%rip),%rsi
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x110,%rsp
  movdqa D2(%rip),%xmm0
  mov    %fs:0x28,%rax
  mov    %rax,0x108(%rsp)
  movabs $0x1222708819f90846,%rax
  lea    0x30(%rsp),%r12
  lea    0x90(%rsp),%rbp
  movaps %xmm0,0x20(%rsp)
  mov    %rbp,%rdi
  movdqa D37(%rip),%xmm0
  lea    0x40(%rsp),%rbx
  lea    0xe0(%rsp),%r14
  lea    0x8(%rsp),%r13
  movaps %xmm0,0xb0(%rsp)
  movdqa D7(%rip),%xmm0
  movaps %xmm0,0xc0(%rsp)
  mov    %rax,0x8(%rsp)
  movabs $0x26c2060c86231778,%rax
  mov    %rax,0x10(%rsp)
  movabs $0x49744d075d232d2f,%rax
  mov    %rax,0xd0(%rsp)
  call   <strncpy@plt>
  lea    0x99(%rsp),%rdi
  mov    $0x1,%edx
  lea    D137(%rip),%rsi
  call   <strncpy@plt>
  lea    0x9a(%rsp),%rdi
  mov    $0x6,%edx
  lea    D50(%rip),%rsi
  call   <strncpy@plt>
  lea    0xa0(%rsp),%rdi
  mov    $0x1,%edx
  lea    D167(%rip),%rsi
  call   <strncpy@plt>
  lea    0xa1(%rsp),%rdi
  mov    $0x6,%edx
  lea    D31(%rip),%rsi
  call   <strncpy@plt>
  lea    0xa7(%rsp),%rdi
  mov    $0x1,%edx
  lea    D43(%rip),%rsi
  call   <strncpy@plt>
  mov    %rbp,%rdi
  mov    %rbx,%rdx
  mov    %r12,%rsi
  call   <mrtd_bac_kmrz_to_kenc_kmac@plt>
  mov    $0x10,%edx
  mov    %r12,%rsi
  lea    D112(%rip),%rdi
  call   <printhex@plt>
  lea    0x10(%rsp),%rbp
  mov    %rbx,%rsi
  mov    $0x10,%edx
  lea    D19(%rip),%rdi
  call   <printhex@plt>
  mov    %r14,%r9
  mov    %rbx,%r8
  mov    %r12,%rcx
  lea    0x20(%rsp),%rsi
  mov    %r13,%rdx
  mov    %rbp,%rdi
  call   <mrtd_bac_cmd_data@plt>
  mov    %r14,%rsi
  mov    $0x28,%edx
  lea    D78(%rip),%rdi
  call   <printhex@plt>
  lea    0x50(%rsp),%r14
  mov    %rbp,%rdx
  mov    %r12,%rsi
  lea    0x18(%rsp),%rcx
  lea    0xb0(%rsp),%rdi
  mov    %r14,%r8
  call   <mrtd_bac_challenge_ok@plt>
  test   %rax,%rax
  je     L28
  lea    D114(%rip),%rdi
  call   <puts@plt>
L1:
  mov    $0x8,%edx
  mov    %rbp,%rsi
  lea    D103(%rip),%rdi
  call   <printhex@plt>
  mov    %r14,%rsi
  mov    $0x10,%edx
  lea    D152(%rip),%rdi
  call   <printhex@plt>
  lea    0x70(%rsp),%r14
  movdqa 0x20(%rsp),%xmm0
  lea    0x80(%rsp),%r12
  pxor   0x50(%rsp),%xmm0
  lea    0x60(%rsp),%rdi
  mov    %r12,%rdx
  mov    %r14,%rsi
  movaps %xmm0,0x60(%rsp)
  call   <mrtd_bac_kenc_kmac@plt>
  mov    $0x10,%edx
  mov    %r14,%rsi
  lea    D121(%rip),%rdi
  call   <printhex@plt>
  mov    $0x10,%edx
  mov    %r12,%rsi
  lea    D125(%rip),%rdi
  call   <printhex@plt>
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <mrtd_bac_get_ssc@plt>
  lea    D56(%rip),%rdi
  mov    %eax,%esi
  xor    %eax,%eax
  call   <printf@plt>
  mov    0x108(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L3
  add    $0x110,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L28:
  lea    D188(%rip),%rdi
  call   <puts@plt>
  jmp    L1
L3:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D97
type: string
name: retrieve_data
arguments: data_tag: D2
type: byte[16]
name: retrieve_data
arguments: data_tag: D37
type: byte[16]
name: retrieve_data
arguments: data_tag: D7
type: byte[16]
name: retrieve_data
arguments: data_tag: D137
type: string
name: retrieve_data
arguments: data_tag: D50
type: string
name: retrieve_data
arguments: data_tag: D167
type: string
name: retrieve_data
arguments: data_tag: D31
type: string
name: retrieve_data
arguments: data_tag: D43
type: string
name: retrieve_data
arguments: data_tag: D112
type: string
name: retrieve_data
arguments: data_tag: D19
type: string
name: retrieve_data
arguments: data_tag: D78
type: string
name: retrieve_data
arguments: data_tag: D114
type: string
name: retrieve_data
arguments: data_tag: D103
type: string
name: retrieve_data
arguments: data_tag: D152
type: string
name: retrieve_data
arguments: data_tag: D121
type: string
name: retrieve_data
arguments: data_tag: D125
type: string
name: retrieve_data
arguments: data_tag: D56
type: string
name: retrieve_data
arguments: data_tag: D188
type: string

tool: D97: L898902C<

tool: {"D2": [0x0b,0x79,0x52,0x40,0xcb,0x70,0x49,0xb0,0x1c,0x19,0xb3,0x3e,0x32,0x80,0x4f,0x0b]}

tool: {"D37": [0x46,0xb9,0x34,0x2a,0x41,0x39,0x6c,0xd7,0x38,0x6b,0xf5,0x80,0x31,0x04,0xd7,0xce]}

tool: {"D7": [0xdc,0x12,0x2b,0x91,0x32,0x13,0x9b,0xaf,0x2e,0xed,0xc9,0x4e,0xe1,0x78,0x53,0x4f]}

tool: D137: 3

tool: D50: 690806

tool: D167: 1

tool: D31: 940623

tool: D43: 6

tool: D112: kenc

tool: D19: kmac

tool: D78: cmd_data

tool: D114: ======================
Challenge successful!
======================

tool: D103: rnd_ifd

tool: D152: kicc

tool: D121: ksenc

tool: D125: ksmac

tool: D56: ssc: %lx


tool: D188: ======================
Challenge failed...
======================

assistant: ```c
int main() {
  int i;
  char *mrp_number = "L898902C<";
  char *mrp_numbercd = "3";
  char *mrp_dob = "690806";
  char *mrp_dobcd = "1";
  char *mrp_expiry = "940623";
  char *mrp_expirycd = "6";
  char remotechallenge[8] = {0x46, 0x08, 0xf9, 0x19, 0x88, 0x70, 0x22, 0x12};
  char rnd_ifd[8] = {0x78, 0x17, 0x23, 0x86, 0x0c, 0x06, 0xc2, 0x26};
  char kifd[16] = {0x0b, 0x79, 0x52, 0x40, 0xcb, 0x70, 0x49, 0xb0, 0x1c, 0x19, 0xb3, 0x3e, 0x32, 0x80, 0x4f, 0x0b};
  char rx_data[40] = {0x46, 0xB9, 0x34, 0x2A, 0x41, 0x39, 0x6C, 0xD7, 0x38, 0x6B, 0xF5, 0x80, 0x31, 0x04, 0xD7, 0xCE, 0xDC, 0x12, 0x2B, 0x91, 0x32, 0x13, 0x9B, 0xAF, 0x2E, 0xED, 0xC9, 0x4E, 0xE1, 0x78, 0x53, 0x4F, 0x2f, 0x2D, 0x23, 0x5D, 0x07, 0x4D, 0x74, 0x49};
  char kmrz[25];
  char kenc[16];
  char kmac[16];
  char cmd_data[40];
  char rnd_icc[8];
  char kicc[16];
  char xored[16];
  char ksenc[16];
  char ksmac[16];
  uint64_t ssc_long;
  strncpy(kmrz, mrp_number, 9);
  strncpy(kmrz + 9, mrp_numbercd, 1);
  strncpy(kmrz + 10, mrp_dob, 6);
  strncpy(kmrz + 16, mrp_dobcd, 1);
  strncpy(kmrz + 17, mrp_expiry, 6);
  strncpy(kmrz + 23, mrp_expirycd, 1);
  mrtd_bac_kmrz_to_kenc_kmac(kmrz, kenc, kmac);
  printhex("kenc", kenc, 16);
  printhex("kmac", kmac, 16);
  mrtd_bac_cmd_data(rnd_ifd, kifd, remotechallenge, kenc, kmac, cmd_data);
  printhex("cmd_data", cmd_data, 40);
  if (mrtd_bac_challenge_ok(rx_data, kenc, rnd_ifd, rnd_icc, kicc)) {
    printf("======================\nChallenge successful!\n======================\n");
  } else {
    printf("======================\nChallenge failed...\n======================\n");
  }
  printhex("rnd_ifd", rnd_ifd, 8);
  printhex("kicc", kicc, 16);
  for (i = 0; i < 16; i++) {
    xored[i] = kifd[i] ^ kicc[i];
  }
  mrtd_bac_kenc_kmac(xored, ksenc, ksmac);
  printhex("ksenc", ksenc, 16);
  printhex("ksmac", ksmac, 16);
  ssc_long = mrtd_bac_get_ssc(remotechallenge, rnd_ifd);
  printf("ssc: %lx\n", ssc_long);
  return 0;
}
```