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

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  mov    %rsi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x288,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x278(%rsp)
  xor    %eax,%eax
  movq   $0x499602d2,0x50(%rsp)
  movq   $0x12aa0131,0x58(%rsp)
  cmp    $0x2,%edi
  je     L331
  mov    $0xa,%edi
  lea    D247(%rip),%rbx
  lea    D726(%rip),%r15
  call   <putchar@plt>
  mov    $0xa,%edi
  lea    D514(%rip),%r13
  lea    D584(%rip),%r12
  call   <putchar@plt>
  mov    (%r14),%rsi
  xor    %eax,%eax
  lea    D618(%rip),%rdi
  lea    D537(%rip),%r14
  lea    D253(%rip),%rbp
  call   <printf@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D162(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D771(%rip),%rsi
  mov    %rsi,%rdi
  call   <puts@plt>
  lea    D588(%rip),%rcx
  mov    %rcx,%rdi
  call   <puts@plt>
  lea    D18(%rip),%rdx
  mov    %rdx,%rdi
  call   <puts@plt>
  lea    D484(%rip),%r11
  mov    %r11,%rdi
  call   <puts@plt>
  lea    D527(%rip),%r10
  mov    %r10,%rdi
  call   <puts@plt>
  lea    D131(%rip),%r9
  mov    %r9,%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D194(%rip),%r8
  mov    %r8,%rdi
  call   <puts@plt>
  mov    %rbx,%rdi
  call   <puts@plt>
  mov    %r15,%rdi
  call   <puts@plt>
  lea    D201(%rip),%rdi
  call   <puts@plt>
  lea    D610(%rip),%rdi
  call   <puts@plt>
  mov    %r14,%rdi
  call   <puts@plt>
  lea    D826(%rip),%rdi
  call   <puts@plt>
  lea    D250(%rip),%rdi
  call   <puts@plt>
  lea    D538(%rip),%rdi
  call   <puts@plt>
  mov    %r13,%rdi
  call   <puts@plt>
  mov    %r12,%rdi
  call   <puts@plt>
  lea    D645(%rip),%rdi
  call   <puts@plt>
  mov    %rbp,%rdi
  call   <puts@plt>
  lea    D813(%rip),%rdi
  call   <puts@plt>
  lea    D477(%rip),%rdi
  call   <puts@plt>
  lea    D594(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D553(%rip),%rdi
  call   <puts@plt>
  lea    D268(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D771(%rip),%rsi
  mov    %rsi,%rdi
  call   <puts@plt>
  lea    D588(%rip),%rcx
  mov    %rcx,%rdi
  call   <puts@plt>
  lea    D18(%rip),%rdx
  mov    %rdx,%rdi
  call   <puts@plt>
  lea    D484(%rip),%r11
  mov    %r11,%rdi
  call   <puts@plt>
  lea    D527(%rip),%r10
  mov    %r10,%rdi
  call   <puts@plt>
  lea    D131(%rip),%r9
  mov    %r9,%rdi
  call   <puts@plt>
  lea    D717(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D194(%rip),%r8
  mov    %r8,%rdi
  call   <puts@plt>
  mov    %rbx,%rdi
  call   <puts@plt>
  mov    %r15,%rdi
  call   <puts@plt>
  lea    D830(%rip),%rdi
  call   <puts@plt>
  lea    D479(%rip),%rdi
  call   <puts@plt>
  mov    %r14,%rdi
  call   <puts@plt>
  lea    D825(%rip),%rdi
  call   <puts@plt>
  lea    D611(%rip),%rdi
  call   <puts@plt>
  lea    D687(%rip),%rdi
  call   <puts@plt>
  mov    %r13,%rdi
  call   <puts@plt>
  mov    %r12,%rdi
  call   <puts@plt>
  lea    D702(%rip),%rdi
  call   <puts@plt>
  mov    %rbp,%rdi
  call   <puts@plt>
  lea    D813(%rip),%rdi
  call   <puts@plt>
  lea    D291(%rip),%rdi
  call   <puts@plt>
  lea    D594(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D666(%rip),%rdi
  call   <puts@plt>
  lea    D262(%rip),%rdi
  call   <puts@plt>
  lea    D361(%rip),%rdi
  call   <puts@plt>
  lea    D706(%rip),%rdi
  call   <puts@plt>
  lea    D495(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  lea    D326(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    $0x1,%eax
L332:
  mov    0x278(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L290
  add    $0x288,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L331:
  mov    0x8(%rsi),%rdi
  lea    D490(%rip),%rsi
  lea    0x70(%rsp),%rbx
  lea    D473(%rip),%r12
  lea    D84(%rip),%r13
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L459
  mov    0x8(%r14),%rsi
  lea    D351(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x2,%eax
  jmp    L332
  nopl   0x0(%rax,%rax,1)
L19:
  mov    %r12,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %r15,%rsi
  test   %rax,%rax
  jne    L8
  mov    %r13,%rdi
  call   <printf@plt>
L459:
  mov    %rbp,%rdx
  mov    $0x1fe,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  mov    %rax,%r15
  test   %rax,%rax
  jne    L19
  mov    %rbp,%rsi
  lea    D468(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x3,%eax
  jmp    L332
L8:
  lea    D84(%rip),%rdi
  xor    %eax,%eax
  xor    %r14d,%r14d
  call   <printf@plt>
  nopl   0x0(%rax,%rax,1)
L515:
  movsbl (%r15,%r14,1),%edi
  mov    %r14d,%r13d
  add    $0x1,%r14
  call   <isdigit@plt>
  test   %rax,%rax
  je     L515
  mov    $0x14,%r12d
  lea    0x56(%rsp),%r14
  cmp    $0x14,%r13d
  jne    L41
  mov    %rbp,0x8(%rsp)
  mov    %r15,%rbp
  mov    %rbx,%r15
  mov    %r14,%rbx
L583:
  movsbl 0x0(%rbp,%r12,1),%edi
  mov    %r12d,%r13d
  lea    -0x14(%r12),%r14d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L485
  movzbl 0x0(%rbp,%r12,1),%eax
  mov    %al,(%rbx,%r12,1)
  add    $0x1,%r12
  cmp    $0x1a,%r12
  jne    L583
  mov    $0x6,%esi
  lea    D620(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x5,%eax
  jmp    L332
L41:
  mov    %r13d,%esi
  lea    D497(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x4,%eax
  jmp    L332
L485:
  movslq %r14d,%rax
  mov    %r15,%rbx
  movslq %r12d,%r14
  mov    %rbp,%r15
  movb   $0x0,0x6a(%rsp,%rax,1)
  lea    0x6a(%rsp),%rax
  mov    0x8(%rsp),%rbp
  mov    %rax,%rdi
  mov    %rax,0x10(%rsp)
  call   <atoi@plt>
  mov    %rbx,0x8(%rsp)
  mov    %r14,%rbx
  mov    %eax,0x1c(%rsp)
  jmp    L346
L648:
  add    $0x1,%rbx
L346:
  movsbl (%r15,%rbx,1),%edi
  mov    %ebx,%r14d
  mov    %ebx,%r12d
  sub    %r13d,%r14d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L648
  lea    -0x6(%r14),%eax
  mov    0x8(%rsp),%rbx
  mov    %r14d,%esi
  cmp    $0x1,%eax
  ja     L271
  lea    0x61(%rsp),%rax
  xor    %r13d,%r13d
  mov    %rbx,0x28(%rsp)
  movslq %r12d,%r14
  mov    %rax,0x8(%rsp)
  mov    %r13,%rcx
  mov    %r15,%r13
  mov    %rbp,0x20(%rsp)
  mov    %rcx,%r15
  mov    %rax,%rbp
L323:
  movsbl 0x0(%r13,%r14,1),%edi
  mov    %r15d,%r12d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L93
  movzbl 0x0(%r13,%r14,1),%eax
  add    $0x1,%r14
  mov    %al,0x0(%rbp,%r15,1)
  add    $0x1,%r15
  cmp    $0x3,%r15
  jne    L323
  mov    $0x3,%esi
  lea    D292(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x7,%eax
  jmp    L332
L271:
  lea    D266(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x6,%eax
  jmp    L332
L93:
  mov    0x8(%rsp),%rdi
  movslq %r12d,%rax
  mov    0x20(%rsp),%rbp
  movslq %r14d,%r14
  mov    0x28(%rsp),%rbx
  movb   $0x0,0x61(%rsp,%rax,1)
  mov    %r13,%r15
  call   <atoi@plt>
  mov    %rbp,0x20(%rsp)
  mov    %r14,%rbp
  mov    %eax,0x30(%rsp)
  mov    %r14,%rax
  mov    %rbx,%r14
  mov    %eax,%ebx
  jmp    L40
L180:
  add    $0x1,%rbp
L40:
  movsbl (%r15,%rbp,1),%edi
  mov    %ebp,%r13d
  mov    %ebp,%r12d
  sub    %ebx,%r13d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L180
  lea    -0x7(%r13),%eax
  mov    0x20(%rsp),%rbp
  mov    %r14,%rbx
  cmp    $0x1,%eax
  ja     L396
  lea    0x64(%rsp),%rax
  xor    %r13d,%r13d
  movslq %r12d,%r14
  mov    %rax,0x20(%rsp)
  mov    %rbx,%rax
  mov    %r15,%rbx
  mov    %r13,%r15
  mov    %rax,%r13
L256:
  movsbl (%rbx,%r14,1),%edi
  mov    %r14d,0x28(%rsp)
  mov    %r15d,%r12d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L641
  movzbl (%rbx,%r14,1),%eax
  mov    0x20(%rsp),%rcx
  add    $0x1,%r14
  mov    %al,(%rcx,%r15,1)
  add    $0x1,%r15
  cmp    $0x3,%r15
  jne    L256
  mov    $0x3,%esi
  lea    D126(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x9,%eax
  jmp    L332
L641:
  mov    0x20(%rsp),%rdi
  mov    %rbx,%r15
  mov    %r13,%rbx
  movslq %r12d,%r13
  movb   $0x0,0x64(%rsp,%r13,1)
  call   <atoi@plt>
  movslq 0x28(%rsp),%r14
  mov    %eax,0x34(%rsp)
  jmp    L451
L0:
  add    $0x1,%r14
L451:
  movsbl (%r15,%r14,1),%edi
  mov    %r14d,%r12d
  movslq %r14d,%r13
  sub    0x28(%rsp),%r12d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L0
  lea    -0x9(%r12),%eax
  mov    %r12d,%esi
  cmp    $0x1,%eax
  ja     L503
  lea    0x67(%rsp),%rax
  add    %r15,%r13
  xor    %r15d,%r15d
  mov    %rax,0x28(%rsp)
L657:
  movsbl 0x0(%r13),%edi
  mov    %r15d,%r12d
  call   <isdigit@plt>
  test   %rax,%rax
  je     L318
  movzbl 0x0(%r13),%eax
  mov    0x28(%rsp),%rcx
  add    $0x1,%r13
  mov    %al,(%rcx,%r15,1)
  add    $0x1,%r15
  cmp    $0x3,%r15
  jne    L657
  mov    $0x3,%esi
  lea    D79(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0xb,%eax
  jmp    L332
L396:
  mov    %r13d,%esi
  lea    D714(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x8,%eax
  jmp    L332
L290:
  call   <__stack_chk_fail@plt>
L318:
  mov    0x28(%rsp),%rdi
  movslq %r15d,%rax
  movb   $0x0,0x67(%rsp,%rax,1)
  call   <atoi@plt>
  mov    %rbp,%rdx
  mov    $0x1fe,%esi
  mov    %rbx,%rdi
  movslq %eax,%r14
  call   <fgets@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L249
  mov    %rax,%rsi
  lea    D84(%rip),%rdi
  lea    0x4c(%rsp),%r13
  xor    %eax,%eax
  call   <printf@plt>
  mov    %r13,%rdx
  lea    D225(%rip),%rsi
  mov    %r15,%rdi
  call   <strptime@plt>
  test   %eax,%eax
  je     L553
  mov    %r13,%rdi
  movl   $0xffffffff,0x4c(%rsp)
  call   <mktime@plt>
  cmp    $0xffffffff,%eax
  je     L551
  imul   $0x3c,0x34(%rsp),%edx
  cltq
  lea    0x50(%rsp),%rdi
  mov    %rbx,%r13
  add    %r14,%rax
  mov    %r12d,%ebx
  movslq %edx,%rdx
  add    %rdx,%rax
  imul   $0xe10,0x30(%rsp),%edx
  movslq %edx,%rdx
  add    %rdx,%rax
  imul   $0x15180,0x1c(%rsp),%edx
  movslq %edx,%rdx
  add    %rdx,%rax
  mov    %rax,0x50(%rsp)
  call   <gmtime@plt>
  mov    %eax,%edi
  call   <asctime@plt>
  lea    D504(%rip),%rdi
  mov    %rax,%rsi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %rbp,0x38(%rsp)
L242:
  mov    0x38(%rsp),%rdx
  mov    $0x1fe,%esi
  mov    %r13,%rdi
  call   <fgets@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L7
  lea    D614(%rip),%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  test   %rax,%rax
  jne    L59
  mov    %rbp,%rsi
  lea    D84(%rip),%rdi
  call   <printf@plt>
  jmp    L242
L503:
  lea    D171(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0xa,%eax
  jmp    L332
L59:
  mov    %rbp,%rdi
  call   <strlen@plt>
  sub    $0x1,%eax
  cltq
L482:
  mov    %eax,%edx
  cmp    $0xffffffff,%eax
  jl     L58
  je     L102
  movzbl 0x0(%rbp,%rax,1),%ecx
  sub    $0x1,%rax
  cmp    $0x20,%cl
  je     L482
  cmp    $0xa,%cl
  je     L482
  movslq %edx,%rax
L254:
  cmpb   $0x20,0x0(%rbp,%rax,1)
  je     L484
  lea    -0x1(%rax),%edx
  add    $0x1,%edx
  jl     L58
  sub    $0x1,%rax
  cmp    $0xffffffff,%eax
  jne    L254
  mov    %rbp,%rsi
  lea    D664(%rip),%rdi
  jmp    L101
L7:
  xor    %eax,%eax
  jmp    L332
L553:
  lea    D68(%rip),%rdi
  call   <puts@plt>
  mov    $0xd,%eax
  jmp    L332
L249:
  mov    $0xc,%eax
  jmp    L332
L551:
  lea    D561(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0xe,%eax
  jmp    L332
L102:
  mov    %rbp,%rsi
  lea    D122(%rip),%rdi
L101:
  xor    %eax,%eax
  call   <printf@plt>
  lea    D421(%rip),%rdi
  call   <puts@plt>
  mov    $0x10,%eax
  jmp    L332
L484:
  lea    0x1(%rax),%ebx
L58:
  movslq %ebx,%r14
  xor    %r15d,%r15d
  jmp    L466
L235:
  movzbl 0x0(%rbp,%r14,1),%eax
  mov    0x10(%rsp),%rcx
  add    $0x1,%r14
  mov    %al,(%rcx,%r15,1)
  add    $0x1,%r15
L466:
  movsbl 0x0(%rbp,%r14,1),%edi
  movslq %r14d,%rbx
  movslq %r15d,%r12
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L235
  mov    0x10(%rsp),%rdi
  movb   $0x0,0x6a(%rsp,%r12,1)
  call   <atoi@plt>
  mov    %eax,0x30(%rsp)
L476:
  movsbl 0x0(%rbp,%rbx,1),%edi
  movslq %ebx,%r14
  add    $0x1,%rbx
  call   <isdigit@plt>
  test   %rax,%rax
  je     L476
  xor    %r15d,%r15d
L312:
  movsbl 0x0(%rbp,%r14,1),%edi
  movslq %r14d,%rbx
  movslq %r15d,%r12
  call   <isdigit@plt>
  test   %rax,%rax
  je     L388
  movzbl 0x0(%rbp,%r14,1),%eax
  mov    0x8(%rsp),%rcx
  add    $0x1,%r14
  mov    %al,(%rcx,%r15,1)
  add    $0x1,%r15
  jmp    L312
L388:
  mov    0x8(%rsp),%rdi
  movb   $0x0,0x61(%rsp,%r12,1)
  call   <atoi@plt>
  mov    %eax,0x34(%rsp)
L210:
  movsbl 0x0(%rbp,%rbx,1),%edi
  movslq %ebx,%r15
  add    $0x1,%rbx
  call   <isdigit@plt>
  test   %rax,%rax
  je     L210
  xor    %r12d,%r12d
L109:
  movsbl 0x0(%rbp,%r15,1),%edi
  movslq %r12d,%r14
  call   <isdigit@plt>
  test   %rax,%rax
  je     L69
  movzbl 0x0(%rbp,%r15,1),%eax
  mov    0x20(%rsp),%rcx
  add    $0x1,%r15
  mov    %al,(%rcx,%r12,1)
  add    $0x1,%r12
  jmp    L109
L69:
  mov    0x20(%rsp),%rdi
  movb   $0x0,0x64(%rsp,%r14,1)
  movslq %r15d,%r15
  call   <atoi@plt>
  mov    %eax,%r14d
L103:
  movsbl 0x0(%rbp,%r15,1),%edi
  movslq %r15d,%rbx
  add    $0x1,%r15
  call   <isdigit@plt>
  test   %rax,%rax
  je     L103
  xor    %r12d,%r12d
L158:
  movsbl 0x0(%rbp,%rbx,1),%edi
  mov    %ebx,0x1c(%rsp)
  movslq %r12d,%r15
  call   <isdigit@plt>
  test   %rax,%rax
  je     L505
  movzbl 0x0(%rbp,%rbx,1),%eax
  mov    0x28(%rsp),%rcx
  add    $0x1,%rbx
  mov    %al,(%rcx,%r12,1)
  add    $0x1,%r12
  jmp    L158
L505:
  mov    0x28(%rsp),%rdi
  movb   $0x0,0x67(%rsp,%r15,1)
  call   <atoi@plt>
  movslq 0x1c(%rsp),%rbx
  movslq %eax,%r15
L602:
  movsbl 0x0(%rbp,%rbx,1),%edi
  add    $0x1,%rbx
  call   <isdigit@plt>
  test   %rax,%rax
  je     L602
  imul   $0x3c,%r14d,%edx
  mov    0x50(%rsp),%rax
  mov    %rbp,%rdi
  xor    %r14d,%r14d
  sub    %r15,%rax
  lea    0x58(%rsp),%r15
  movslq %edx,%rdx
  sub    %rdx,%rax
  imul   $0xe10,0x34(%rsp),%edx
  movslq %edx,%rdx
  sub    %rdx,%rax
  imul   $0x15180,0x30(%rsp),%edx
  movslq %edx,%rdx
  sub    %rdx,%rax
  mov    %rax,0x58(%rsp)
  call   <strlen@plt>
  lea    -0x1(%rax),%edx
  movslq %edx,%rdx
  movb   $0x20,0x0(%rbp,%rdx,1)
  movslq %eax,%rdx
  movb   $0x73,0x0(%rbp,%rdx,1)
  lea    0x1(%rax),%edx
  movslq %edx,%rdx
  movb   $0x69,0x0(%rbp,%rdx,1)
  lea    0x2(%rax),%edx
  movslq %edx,%rdx
  movb   $0x6e,0x0(%rbp,%rdx,1)
  lea    0x3(%rax),%edx
  movslq %edx,%rdx
  movb   $0x63,0x0(%rbp,%rdx,1)
  lea    0x4(%rax),%edx
  movslq %edx,%rdx
  movb   $0x65,0x0(%rbp,%rdx,1)
  lea    0x5(%rax),%edx
  add    $0x6,%eax
  movslq %edx,%rdx
  movslq %eax,%r12
  movb   $0x20,0x0(%rbp,%rdx,1)
  jmp    L164
L653:
  mov    %r15,%rdi
  call   <gmtime@plt>
  mov    %eax,%edi
  call   <asctime@plt>
  movzbl (%rax,%r14,1),%eax
  add    $0x1,%r14
  mov    %al,0x0(%rbp,%r12,1)
  add    $0x1,%r12
L164:
  mov    %r15,%rdi
  mov    %r12d,%ebx
  call   <gmtime@plt>
  mov    %eax,%edi
  call   <asctime@plt>
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%r8d
  lea    0x0(%rbp,%r12,1),%rax
  cmp    %r14d,%r8d
  jg     L653
  movb   $0x0,(%rax)
  mov    %rbp,%rsi
  lea    D84(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L242
```

tool_calls: name: unpack_data
arguments: tag: D247
data_type: string
name: unpack_data
arguments: tag: D726
data_type: string
name: unpack_data
arguments: tag: D514
data_type: string
name: unpack_data
arguments: tag: D584
data_type: string
name: unpack_data
arguments: tag: D618
data_type: string
name: unpack_data
arguments: tag: D537
data_type: string
name: unpack_data
arguments: tag: D253
data_type: string
name: unpack_data
arguments: tag: D162
data_type: string
name: unpack_data
arguments: tag: D771
data_type: string
name: unpack_data
arguments: tag: D588
data_type: string
name: unpack_data
arguments: tag: D18
data_type: string
name: unpack_data
arguments: tag: D484
data_type: string
name: unpack_data
arguments: tag: D527
data_type: string
name: unpack_data
arguments: tag: D131
data_type: string
name: unpack_data
arguments: tag: D194
data_type: string
name: unpack_data
arguments: tag: D201
data_type: string
name: unpack_data
arguments: tag: D610
data_type: string
name: unpack_data
arguments: tag: D826
data_type: string
name: unpack_data
arguments: tag: D250
data_type: string
name: unpack_data
arguments: tag: D538
data_type: string
name: unpack_data
arguments: tag: D645
data_type: string
name: unpack_data
arguments: tag: D813
data_type: string
name: unpack_data
arguments: tag: D477
data_type: string
name: unpack_data
arguments: tag: D594
data_type: string
name: unpack_data
arguments: tag: D553
data_type: string
name: unpack_data
arguments: tag: D268
data_type: string
name: unpack_data
arguments: tag: D717
data_type: string
name: unpack_data
arguments: tag: D830
data_type: string
name: unpack_data
arguments: tag: D479
data_type: string
name: unpack_data
arguments: tag: D825
data_type: string
name: unpack_data
arguments: tag: D611
data_type: string
name: unpack_data
arguments: tag: D687
data_type: string
name: unpack_data
arguments: tag: D702
data_type: string
name: unpack_data
arguments: tag: D291
data_type: string
name: unpack_data
arguments: tag: D666
data_type: string
name: unpack_data
arguments: tag: D262
data_type: string
name: unpack_data
arguments: tag: D361
data_type: string
name: unpack_data
arguments: tag: D706
data_type: string
name: unpack_data
arguments: tag: D495
data_type: string
name: unpack_data
arguments: tag: D326
data_type: string
name: unpack_data
arguments: tag: D490
data_type: string
name: unpack_data
arguments: tag: D473
data_type: string
name: unpack_data
arguments: tag: D84
data_type: string
name: unpack_data
arguments: tag: D351
data_type: string
name: unpack_data
arguments: tag: D421
data_type: string
name: unpack_data
arguments: tag: D468
data_type: string
name: unpack_data
arguments: tag: D620
data_type: string
name: unpack_data
arguments: tag: D497
data_type: string
name: unpack_data
arguments: tag: D292
data_type: string
name: unpack_data
arguments: tag: D266
data_type: string
name: unpack_data
arguments: tag: D126
data_type: string
name: unpack_data
arguments: tag: D79
data_type: string
name: unpack_data
arguments: tag: D714
data_type: string
name: unpack_data
arguments: tag: D225
data_type: string
name: unpack_data
arguments: tag: D504
data_type: string
name: unpack_data
arguments: tag: D614
data_type: string
name: unpack_data
arguments: tag: D171
data_type: string
name: unpack_data
arguments: tag: D664
data_type: string
name: unpack_data
arguments: tag: D68
data_type: string
name: unpack_data
arguments: tag: D561
data_type: string
name: unpack_data
arguments: tag: D122
data_type: string

tool: D247: ---- ------- ---------------- ------- ----- --------------- ---------------

tool: D726: 0    standby OC3/OC12/DS3-ATM enabled spare 8-2-3p0-5-1.rel       ---      

tool: D514: 7    standby SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel       ---      

tool: D584: 8      ---         ---          ---    ---        ---             ---      

tool: D618:     Usage: %s <input text file 1>


tool: D537: 3      ---         ---          ---    ---        ---             ---      

tool: D253: 10     ---         ---          ---    ---        ---             ---      

tool: D162: This C program takes as INPUT(in a file) the output from an eSeries "show version" CLI command, for example:

tool: D771: Juniper Edge Routing Switch ERX-1400

tool: D588: Copyright (c) 1999-2008 Juniper Networks, Inc.  All rights reserved.

tool: D18: System Release: 8-2-3p0-5-1.rel

tool: D484:         Version: 8.2.3 patch-0.5.1 [BuildId 10739]   (March 24, 2009  10:50)

tool: D527: System running for: 553 days, 16 hours, 13 minutes, 20 seconds

tool: D131:         (since TUE SEP 01 2009 05:21:30 UTC)

tool: D194: slot  state        type        admin  spare running release   slot uptime  

tool: D201: 1    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:15s

tool: D610: 2    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:14s

tool: D826: 4    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:12s

tool: D250: 5    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:10s

tool: D538: 6    online  SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel 553d16h:10m:27s

tool: D645: 9    online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:33s

tool: D813: 11     ---         ---          ---    ---        ---             ---      

tool: D477: 12   online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:36s

tool: D594: 13     ---         ---          ---    ---        ---             ---      

tool: D553: --and provides as OUTPUT(to the monitor) the time that this eSeries "show version" CLI command was executed;

tool: D268: ALSO, it converts the slot uptimes to the actual times the slots came up, in this example it would be:

tool: D717: Time this "show version" CLI command was executed:                          Tue Mar  8 21:34:50 2011

tool: D830: 1    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:15s Tue Sep  1 05:33:35 2009

tool: D479: 2    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:14s Tue Sep  1 05:33:36 2009

tool: D825: 4    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:12s Tue Sep  1 05:33:38 2009

tool: D611: 5    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:10s Tue Sep  1 05:33:40 2009

tool: D687: 6    online  SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel 553d16h:10m:27s Tue Sep  1 05:24:23 2009

tool: D702: 9    online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:33s Tue Sep  1 05:32:17 2009

tool: D291: 12   online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:36s Tue Sep  1 05:32:14 2009

tool: D666: Caveats:

tool: D262: 0 - input format must be exact

tool: D361: 1 - output is in local time, ASSUMED to be UTC (at least, that is what I like)

tool: D706: 2 - the eSeries may add trailing spaces, which breaks this code.  An example workaround is:

tool: D495:         cat inputFile | sed 's/ *$//' > inputFileCleaned

tool: D326: Written by Jonathan Natale for Juniper Networks on 11-Mar-2011.

tool: D490: r

tool: D473: System running for: 

tool: D84: %s

tool: D351: Sorry, unable to open %s file.


tool: D421: Please try again.  Exiting ...

tool: D468: Sorry, unexpected NULL line read in %s file.


tool: D620: Sorry, wrong number of digits in the number of days, in first line (got %d, expected between 1 and 5).


tool: D497: Sorry, wrong number of non-numeric characters before a number, in first line (got %d, expected 20).


tool: D292: Sorry, wrong number of digits in the number of hours, in first line (got %d, expected between 1 and 2).


tool: D266: Sorry, wrong number of characters after the number of days and before the number of hours, in first line (got %d, expected 6 or 7).


tool: D126: Sorry, wrong number of digits in the number of minutes, in first line (got %d, expected between 1 and 2).


tool: D79: Sorry, wrong number of digits in the number of seconds, in first line (got %d, expected between 1 and 2).


tool: D714: Sorry, wrong number of characters after the number of hours and before the number of minutes, in first line (got %d, expected 7 or 8).


tool: D225:          (since %a %b %d %Y %T UTC)

tool: D504: Time this "show version" CLI command was executed:                                   %s

tool: D614: m:

tool: D171: Sorry, wrong number of characters after the number of minutes and before the number of seconds, in first line (got %d, expected 9 or 10).


tool: D664: Sorry, unexpectedly, a space was not found in the input line: <%s>.


tool: D68: strptime() failed!

tool: D561: mktime failed!

tool: D122: Sorry, unexpectedly, a nonspace was not found in the input line: <%s>.


assistant: ```c
int main(int argc, char **argv) {
  FILE *inputFile_ptr;
  int i, j, k;
  time_t t;
  struct tm time_str;
  char *line;
  char lineBuf[512];
  long int currentTimeInSecondsSinceEpoch = 1234567890;
  long int slotBootTimeInSecondsSinceEpoch = 313131313;
  int daysDiffInt = 0;
  int hoursDiffInt = 0;
  int minutesDiffInt = 0;
  int secondsDiffInt = 0;
  char daysDiffString[6];
  char hoursDiffString[3];
  char minutesDiffString[3];
  char secondsDiffString[3];
  if (argc != 2) {
    printf("\n");
    printf("\n");
    printf("    Usage: %s <input text file 1>\n", argv[0]);
    printf("\n");
    printf("This C program takes as INPUT(in a file) the output from an eSeries \"show version\" CLI command, for example:\n");
    printf("\n");
    printf("Juniper Edge Routing Switch ERX-1400\n");
    printf("Copyright (c) 1999-2008 Juniper Networks, Inc.  All rights reserved.\n");
    printf("System Release: 8-2-3p0-5-1.rel\n");
    printf("        Version: 8.2.3 patch-0.5.1 [BuildId 10739]   (March 24, 2009  10:50)\n");
    printf("System running for: 553 days, 16 hours, 13 minutes, 20 seconds\n");
    printf("        (since TUE SEP 01 2009 05:21:30 UTC)\n");
    printf("\n");
    printf("slot  state        type        admin  spare running release   slot uptime  \n");
    printf("---- ------- ---------------- ------- ----- --------------- ---------------\n");
    printf("0    standby OC3/OC12/DS3-ATM enabled spare 8-2-3p0-5-1.rel       ---      \n");
    printf("1    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:15s\n");
    printf("2    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:14s\n");
    printf("3      ---         ---          ---    ---        ---             ---      \n");
    printf("4    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:12s\n");
    printf("5    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:10s\n");
    printf("6    online  SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel 553d16h:10m:27s\n");
    printf("7    standby SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel       ---      \n");
    printf("8      ---         ---          ---    ---        ---             ---      \n");
    printf("9    online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:33s\n");
    printf("10     ---         ---          ---    ---        ---             ---      \n");
    printf("11     ---         ---          ---    ---        ---             ---      \n");
    printf("12   online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:36s\n");
    printf("13     ---         ---          ---    ---        ---             ---      \n");
    printf("\n");
    printf("\n");
    printf("--and provides as OUTPUT(to the monitor) the time that this eSeries \"show version\" CLI command was executed;\n");
    printf("ALSO, it converts the slot uptimes to the actual times the slots came up, in this example it would be:\n");
    printf("\n");
    printf("Juniper Edge Routing Switch ERX-1400\n");
    printf("Copyright (c) 1999-2008 Juniper Networks, Inc.  All rights reserved.\n");
    printf("System Release: 8-2-3p0-5-1.rel\n");
    printf("        Version: 8.2.3 patch-0.5.1 [BuildId 10739]   (March 24, 2009  10:50)\n");
    printf("System running for: 553 days, 16 hours, 13 minutes, 20 seconds\n");
    printf("        (since TUE SEP 01 2009 05:21:30 UTC)\n");
    printf("Time this \"show version\" CLI command was executed:                          Tue Mar  8 21:34:50 2011\n");
    printf("\n");
    printf("slot  state        type        admin  spare running release   slot uptime  \n");
    printf("---- ------- ---------------- ------- ----- --------------- ---------------\n");
    printf("0    standby OC3/OC12/DS3-ATM enabled spare 8-2-3p0-5-1.rel       ---      \n");
    printf("1    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:15s Tue Sep  1 05:33:35 2009\n");
    printf("2    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:14s Tue Sep  1 05:33:36 2009\n");
    printf("3      ---         ---          ---    ---        ---             ---      \n");
    printf("4    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:12s Tue Sep  1 05:33:38 2009\n");
    printf("5    online  OC3-4A           enabled  ---  8-2-3p0-5-1.rel 553d16h:01m:10s Tue Sep  1 05:33:40 2009\n");
    printf("6    online  SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel 553d16h:10m:27s Tue Sep  1 05:24:23 2009\n");
    printf("7    standby SRP-10Ge         enabled  ---  8-2-3p0-5-1.rel       ---      \n");
    printf("8      ---         ---          ---    ---        ---             ---      \n");
    printf("9    online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:33s Tue Sep  1 05:32:17 2009\n");
    printf("10     ---         ---          ---    ---        ---             ---      \n");
    printf("11     ---         ---          ---    ---        ---             ---      \n");
    printf("12   online  GE               enabled  ---  8-2-3p0-5-1.rel 553d16h:02m:36s Tue Sep  1 05:32:14 2009\n");
    printf("13     ---         ---          ---    ---        ---             ---      \n");
    printf("\n");
    printf("\n");
    printf("Caveats:\n");
    printf("0 - input format must be exact\n");
    printf("1 - output is in local time, ASSUMED to be UTC (at least, that is what I like)\n");
    printf("2 - the eSeries may add trailing spaces, which breaks this code.  An example workaround is:\n");
    printf("        cat inputFile | sed 's/ *$//' > inputFileCleaned\n");
    printf("\n");
    printf("Written by Jonathan Natale for Juniper Networks on 11-Mar-2011.\n");
    printf("\n");
    return (1);
  }
  if ((inputFile_ptr = fopen(argv[1], "r")) == NULL) {
    printf("Sorry, unable to open %s file.\n", argv[1]);
    printf("Please try again.  Exiting ...\n");
    return (2);
  }
  while (1) {
    if ((line = fgets(lineBuf, 512 - 2, inputFile_ptr)) == NULL) {
      printf("Sorry, unexpected NULL line read in %s file.\n", inputFile_ptr);
      printf("Please try again.  Exiting ...\n");
      return (3);
    }
    if (strstr(line, "System running for: ") == NULL) {
      printf("%s", line);
    } else {
      break;
    }
  }
  printf("%s", line);
  i = 0;
  j = 0;
  while (!isdigit(line[i])) {
    i++;
    j++;
  }
  if (j != 20) {
    printf("Sorry, wrong number of non-numeric characters before a number, in first line (got %d, expected 20).\n", j);
    printf("Please try again.  Exiting ...\n");
    return (4);
  }
  j = 0;
  while (isdigit(line[i])) {
    daysDiffString[j] = line[i];
    if (j >= 5) {
      printf("Sorry, wrong number of digits in the number of days, in first line (got %d, expected between 1 and 5).\n", j + 1);
      printf("Please try again.  Exiting ...\n");
      return (5);
    }
    i++;
    j++;
  }
  daysDiffString[j] = '\0';
  daysDiffInt = atoi(daysDiffString);
  j = 0;
  while (!isdigit(line[i])) {
    i++;
    j++;
  }
  if ((j != 6) && (j != 7)) {
    printf("Sorry, wrong number of characters after the number of days and before the number of hours, in first line (got %d, expected 6 or 7).\n", j);
    printf("Please try again.  Exiting ...\n");
    return (6);
  }
  j = 0;
  while (isdigit(line[i])) {
    hoursDiffString[j] = line[i];
    if (j >= 2) {
      printf("Sorry, wrong number of digits in the number of hours, in first line (got %d, expected between 1 and 2).\n", j + 1);
      printf("Please try again.  Exiting ...\n");
      return (7);
    }
    i++;
    j++;
  }
  hoursDiffString[j] = '\0';
  hoursDiffInt = atoi(hoursDiffString);
  j = 0;
  while (!isdigit(line[i])) {
    i++;
    j++;
  }
  if ((j != 7) && (j != 8)) {
    printf("Sorry, wrong number of characters after the number of hours and before the number of minutes, in first line (got %d, expected 7 or 8).\n", j);
    printf("Please try again.  Exiting ...\n");
    return (8);
  }
  j = 0;
  while (isdigit(line[i])) {
    minutesDiffString[j] = line[i];
    if (j >= 2) {
      printf("Sorry, wrong number of digits in the number of minutes, in first line (got %d, expected between 1 and 2).\n", j + 1);
      printf("Please try again.  Exiting ...\n");
      return (9);
    }
    i++;
    j++;
  }
  minutesDiffString[j] = '\0';
  minutesDiffInt = atoi(minutesDiffString);
  j = 0;
  while (!isdigit(line[i])) {
    i++;
    j++;
  }
  if ((j != 9) && (j != 10)) {
    printf("Sorry, wrong number of characters after the number of minutes and before the number of seconds, in first line (got %d, expected 9 or 10).\n", j);
    printf("Please try again.  Exiting ...\n");
    return (10);
  }
  j = 0;
  while (isdigit(line[i])) {
    secondsDiffString[j] = line[i];
    if (j >= 2) {
      printf("Sorry, wrong number of digits in the number of seconds, in first line (got %d, expected between 1 and 2).\n", j + 1);
      printf("Please try again.  Exiting ...\n");
      return (11);
    }
    i++;
    j++;
  }
  secondsDiffString[j] = '\0';
  secondsDiffInt = atoi(secondsDiffString);
  if ((line = fgets(lineBuf, 512 - 2, inputFile_ptr)) == NULL) {
    return (12);
  }
  printf("%s", line);
  if (strptime(line, "         (since %a %b %d %Y %T UTC)", &time_str) == (int)NULL) {
    printf("strptime() failed!\n");
    return (13);
  }
  time_str.tm_isdst = -1;
  t = mktime(&time_str);
  if (t == -1) {
    printf("mktime failed!");
    return (14);
  } else {
    currentTimeInSecondsSinceEpoch = (long)t + secondsDiffInt + minutesDiffInt * 60 + hoursDiffInt * 3600 + daysDiffInt * 86400;
  }
  printf("Time this \"show version\" CLI command was executed:                                   %s", asctime(gmtime(&currentTimeInSecondsSinceEpoch)));
  while (1) {
    while (1) {
      if ((line = fgets(lineBuf, 512 - 2, inputFile_ptr)) == NULL) {
        return (0);
      }
      if (strstr(line, "m:") == NULL) {
        printf("%s", line);
      } else {
        break;
      }
    }
    for (k = strlen(line) - 1; k >= -1; k--) {
      if (k == -1) {
        printf("Sorry, unexpectedly, a nonspace was not found in the input line: <%s>.\n", line);
        printf("Please try again.  Exiting ...\n");
        return (16);
      }
      if ((line[k] != ' ') && (line[k] != '\n')) {
        break;
      }
    }
    for (i = k; i >= -1; i--) {
      if (i == -1) {
        printf("Sorry, unexpectedly, a space was not found in the input line: <%s>.\n", line);
        printf("Please try again.  Exiting ...\n");
        return (16);
      }
      if (line[i] == ' ') {
        j = i + 1;
        break;
      }
    }
    i = 0;
    while (isdigit(line[j])) {
      daysDiffString[i++] = line[j++];
    }
    daysDiffString[i] = '\0';
    daysDiffInt = atoi(daysDiffString);
    while (!isdigit(line[j++]))
      ;
    j--;
    i = 0;
    while (isdigit(line[j])) {
      hoursDiffString[i++] = line[j++];
    }
    hoursDiffString[i] = '\0';
    hoursDiffInt = atoi(hoursDiffString);
    while (!isdigit(line[j++]))
      ;
    j--;
    i = 0;
    while (isdigit(line[j])) {
      minutesDiffString[i++] = line[j++];
    }
    minutesDiffString[i] = '\0';
    minutesDiffInt = atoi(minutesDiffString);
    while (!isdigit(line[j++]))
      ;
    j--;
    i = 0;
    while (isdigit(line[j])) {
      secondsDiffString[i++] = line[j++];
    }
    secondsDiffString[i] = '\0';
    secondsDiffInt = atoi(secondsDiffString);
    while (!isdigit(line[j++])) {
    }
    j--;
    slotBootTimeInSecondsSinceEpoch = currentTimeInSecondsSinceEpoch - secondsDiffInt - minutesDiffInt * 60 - hoursDiffInt * 3600 - daysDiffInt * 86400;
    j = strlen(line) - 1;
    line[j++] = ' ';
    line[j++] = 's';
    line[j++] = 'i';
    line[j++] = 'n';
    line[j++] = 'c';
    line[j++] = 'e';
    line[j++] = ' ';
    for (i = 0; i < strlen(asctime(gmtime(&slotBootTimeInSecondsSinceEpoch))); i++) {
      line[j++] = asctime(gmtime(&slotBootTimeInSecondsSinceEpoch))[i];
    }
    line[j] = '\0';
    printf("%s", line);
  }
  printf("Sorry, unexpected program exit point, something might be broken!\n");
  printf("Please try again and/or contact the program author, Jonathan Natale.  Exiting ...\n");
  return (0);
}
```