// File: /workspace/github_c_makefile_star2_O1/pavel-demin[P]ft8d-c/ft8d.c
// Function: unpack
int unpack(char *call, char *grid)
{
  int i, n;
  uint64_t icall;
  uint16_t igrid;
  uint8_t i3, iflip;

  call[0] = 0;
  grid[0] = 0;

  i3 = 0;
  for(i = 0; i < 3; ++i) i3 |= message[76 - i] << i;

  if(i3 == 1 || i3 == 2)
  {
    icall = 0;
    for(i = 0; i < 28; ++i) icall |= message[56 - i] << i;

    igrid = 0;
    for(i = 0; i < 15; ++i) igrid |= message[73 - i] << i;

    if(igrid <= MAXGRID && igrid != 32373)
    {
      grid[4] = 0;
      n = igrid;
      grid[3] = '0' + (n % 10);
      n /= 10;
      grid[2] = '0' + (n % 10);
      n /= 10;
      grid[1] = 'A' + (n % 18);
      n /= 18;
      grid[0] = 'A' + (n % 18);
    }

    n = icall - NTOKENS - MAX22;

    if(n < 0) return 0;

    call[6] = 0;
    for(i = 0; i < 3; ++i)
    {
      call[5 - i] = c4[n % 27];
      n /= 27;
    }
    call[2] = c3[n % 10];
    n /= 10;
    call[1] = c2[n % 36];
    n /= 36;
    call[0] = c1[n % 37];
    trim(call);

    return 1;
  }

  if(i3 == 4)
  {
    iflip = message[70];

    if(iflip) return 0;

    icall = 0;
    for(i = 0; i < 58; ++i) icall |= (uint64_t)message[69 - i] << i;
    call[11] = 0;
    for(i = 0; i < 11; ++i)
    {
      call[10 - i] = c0[icall % 38];
      icall /= 38;
    }
    trim(call);

    return 1;
  }

  return 0;
}

// Assembly:
pushq %rax
xorl %ecx, %ecx
movb %cl, (%rdi)
movb %cl, (%rsi)
leaq 0x66f1(%rip), %rax      # 0xd4fc
xorl %edx, %edx
movzbl (%rax), %r8d
shll %cl, %r8d
orb %r8b, %dl
incq %rcx
decq %rax
cmpq $0x3, %rcx
jne 0x6e0d
leal -0x1(%rdx), %eax
cmpb $0x1, %al
ja 0x6fe5
leaq 0x66b3(%rip), %rdx      # 0xd4e8
xorl %ecx, %ecx
xorl %eax, %eax
movzbl (%rdx), %r8d
shll %cl, %r8d
orq %r8, %rax
incq %rcx
decq %rdx
cmpq $0x1c, %rcx
jne 0x6e39
leaq 0x66a3(%rip), %rdx      # 0xd4f9
xorl %ecx, %ecx
xorl %r8d, %r8d
movzbl (%rdx), %r9d
shll %cl, %r9d
orl %r9d, %r8d
incq %rcx
decq %rdx
cmpq $0xf, %rcx
jne 0x6e5b
movzwl %r8w, %ecx
cmpl $0x7e91, %ecx           # imm = 0x7E91
setae %dl
cmpl $0x7e75, %ecx           # imm = 0x7E75
sete %r8b
orb %dl, %r8b
jne 0x6f19
movb $0x0, 0x4(%rsi)
imull $0xcccd, %ecx, %edx     # imm = 0xCCCD
shrl $0x13, %edx
leal (%rdx,%rdx), %r8d
leal (%r8,%r8,4), %r8d
movl %ecx, %r9d
subl %r8d, %r9d
orb $0x30, %r9b
movb %r9b, 0x3(%rsi)
imull $0x199a, %edx, %r8d     # imm = 0x199A
shrl $0xf, %r8d
andl $-0x2, %r8d
leal (%r8,%r8,4), %r8d
subl %r8d, %edx
orb $0x30, %dl
movb %dl, 0x2(%rsi)
movl %ecx, %edx
shrl $0x2, %edx
imull $0x147b, %edx, %edx     # imm = 0x147B
shrl $0x11, %edx
imull $0xe39, %edx, %r8d      # imm = 0xE39
shrl $0xf, %r8d
andl $-0x2, %r8d
leal (%r8,%r8,8), %r8d
subl %r8d, %edx
addb $0x41, %dl
movb %dl, 0x1(%rsi)
imull $0x91a3, %ecx, %ecx     # imm = 0x91A3
shrl $0x1a, %ecx
imull $0xe39, %ecx, %edx      # imm = 0xE39
shrl $0xf, %edx
andl $-0x2, %edx
leal (%rdx,%rdx,8), %edx
subl %edx, %ecx
addb $0x41, %cl
movb %cl, (%rsi)
addl $0xffa08318, %eax       # imm = 0xFFA08318
js 0x705c
movb $0x0, 0x6(%rdi)
movl $0x5, %edx
leaq 0x495c(%rip), %rsi      # 0xb890
movl %eax, %r8d
movl %eax, %ecx
imulq $0x2f684bdb, %rcx, %r9  # imm = 0x2F684BDB
shrq $0x20, %r9
subl %r9d, %eax
shrl %eax
addl %r9d, %eax
shrl $0x4, %eax
leal (%rax,%rax,8), %r9d
leal (%r9,%r9,2), %r9d
subl %r9d, %r8d
movb (%r8,%rsi), %r8b
movb %r8b, (%rdi,%rdx)
decq %rdx
cmpq $0x2, %rdx
jne 0x6f34
movl %eax, %edx
imulq $0x1999999a, %rdx, %rdx # imm = 0x1999999A
shrq $0x20, %rdx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %eax
leaq 0x48fe(%rip), %rdx      # 0xb884
movb (%rax,%rdx), %al
movb %al, 0x2(%rdi)
movl $0xf2b9d649, %eax       # imm = 0xF2B9D649
imulq %rcx, %rax
shrq $0x28, %rax
imulq $0x71c71c8, %rax, %rdx  # imm = 0x71C71C8
shrq $0x20, %rdx
shll $0x2, %edx
leal (%rdx,%rdx,8), %edx
subl %edx, %eax
leaq 0x48ad(%rip), %rdx      # 0xb860
movb (%rax,%rdx), %al
movb %al, 0x1(%rdi)
imulq $0x1af83441, %rcx, %rax # imm = 0x1AF83441
shrq $0x2a, %rax
imulq $0x6eb3e46, %rax, %rcx  # imm = 0x6EB3E46
shrq $0x20, %rcx
leal (%rcx,%rcx,8), %edx
leal (%rcx,%rdx,4), %ecx
subl %ecx, %eax
leaq 0x4852(%rip), %rcx      # 0xb830
movb (%rax,%rcx), %al
movb %al, (%rdi)
jmp 0x7050
xorl %eax, %eax
cmpb $0x4, %dl
jne 0x705e
cmpb $0x0, 0x6503(%rip)      # 0xd4f6
jne 0x705e
leaq 0x64f9(%rip), %rax      # 0xd4f5
xorl %ecx, %ecx
xorl %esi, %esi
movzbl (%rax), %edx
shlq %cl, %rdx
orq %rdx, %rsi
incq %rcx
decq %rax
cmpq $0x3a, %rcx
jne 0x7000
movb $0x0, 0xb(%rdi)
movl $0xb, %ecx
leaq 0x47db(%rip), %r8       # 0xb800
movabsq $-0x286bca1af286bca1, %r9 # imm = 0xD79435E50D79435F
movq %rsi, %rax
mulq %r9
shrq $0x5, %rdx
imulq $0x26, %rdx, %rax
subq %rax, %rsi
movb (%r8,%rsi), %al
movb %al, -0x1(%rdi,%rcx)
movq %rdx, %rsi
decq %rcx
jne 0x702f
callq 0x6d83
movl $0x1, %eax
jmp 0x705e
xorl %eax, %eax
popq %rcx
retq