; elso.

section .text

global elso:function
global masodik:function
global harmadik:function
global negyedik:function
global otodik:function
global hatodik:function

elso:
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
    
    mov rcx, lookup_elso
    
    movzx  eax,al

    sub    eax,0x54 ; -'T'
    movzx  eax,al ; levágja
    movzx  edi,BYTE [rcx+rax*1] ; index a listába
    imul   rax,rdi,0x8020 ; rax-be a szorzatot
    and    eax,0x88440 
    imul   rdi,rdi,0x802 ; 10-ed akkora
    and    edi,0x22110
    or     rax,rdi ; 
    imul   rax,rax,0x10101
    shr    rax,0x10
    lea    edi,[rax+rax*1]
    and    edi,0xffffffaa
    shr    al,1
    and    eax,0x55
    or     edi,eax
    add    eax,eax
    shr    dil,1
    and    edi,0x55
    or     eax,edi
    rol    al,1
    movzx  eax,al
    movzx  eax,BYTE [rcx+rax*1]
    sub    eax,0x65
    xor    eax,0x3d
    movzx  eax,al
    imul   rdi,rax,0x802
    and    edi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rdi,rax
    imul   rdi,rdi,0x10101
    shr    rdi,0x10
    mov    eax,edi
    shr    al,1
    and    eax,0x55
    add    edi,edi
    and    edi,0xffffffaa
    or     eax,edi
    add    eax,0x10
    ror    al,0x2
    sub    eax,0x24
    mov    edi,eax
    shr    dil,1
    and    edi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     eax,edi


    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret


masodik:
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
    
    mov rcx, lookup_masodik
    movzx  eax,al
    movzx  edi,BYTE [rcx+rax*1]
    mov    eax,edi
    shr    al,1
    and    eax,0x55
    add    edi,edi
    and    edi,0xffffffaa
    or     eax,edi
    rol    al,1
    not    eax
    movzx  eax,al
    movzx  edi,BYTE [rcx+rax*1]
    sub    edi,0x1e
    movzx  edi,dil
    imul   rax,rdi,0x802
    and    eax,0x22110
    imul   rdi,rdi,0x8020
    and    edi,0x88440
    or     rax,rdi
    imul   rax,rax,0x10101
    shr    rax,0x10
    sub    eax,0x48
    movzx  eax,al
    movzx  edi,BYTE [rcx+rax*1]
    ror    dil,0x2
    sub    edi,0x12
    mov    eax,edi
    shr    al,1
    and    eax,0x55
    add    edi,edi
    and    edi,0xffffffaa
    or     eax,edi
    xor    eax,0x4f
    movzx  eax,al
    imul   rdi,rax,0x802
    and    edi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rax,rdi
    imul   rax,rax,0x10101
    shr    rax,0x10


    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret

harmadik:
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
    
    movzx  rax,al
    lea    esi,[rax+0x35]
    mov    eax,esi
    shr    al,1
    and    eax,0x55
    add    esi,esi
    and    esi,0xffffffaa
    or     eax,esi
    not    eax
    rol    al,0x2
    mov    esi,eax
    shr    sil,1
    and    esi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     eax,esi
    movzx  eax,al
    imul   rsi,rax,0x802
    and    esi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rsi,rax
    imul   rsi,rsi,0x10101
    shr    rsi,0x10
    rol    sil,1
    movzx  esi,sil
    imul   rax,rsi,0x802
    and    eax,0x22110
    imul   rsi,rsi,0x8020
    and    esi,0x88440
    or     rax,rsi
    imul   rax,rax,0x10101
    shr    rax,0x10
    mov    esi,eax
    shr    sil,1
    and    esi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     esi,eax
    shr    al,1
    add    esi,esi
    and    esi,0xffffffaa
    or     eax,esi
    movzx  eax,al
    imul   rsi,rax,0x802
    and    esi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rax,rsi
    imul   rax,rax,0x10101
    shr    rax,0x10
    xor    eax,0x22
    mov    esi,eax
    shr    sil,1
    and    esi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     eax,esi
    rol    al,1
   
    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret

negyedik:

    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
    
    mov    rcx,lookup_negyedik ;        # 0x4063a0

    movzx  eax,al
    movzx  edi,BYTE [rcx+rax*1]
    not    edi
    rol    dil,0x4
    movzx  edi,dil
    imul   rax,rdi,0x802
    and    eax,0x22110
    imul   rdi,rdi,0x8020
    and    edi,0x88440
    or     rax,rdi
    imul   rax,rax,0x10101
    shr    rax,0x10
    add    eax,0x77
    not    eax
    ror    al,0x3
    movzx  eax,al
    imul   rdi,rax,0x802
    and    edi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rax,rdi
    imul   rax,rax,0x10101
    shr    rax,0x10
    movzx  eax,al
    movzx  eax,BYTE [rcx+rax*1]
    add    eax,0x2b
    mov    edi,eax
    shr    dil,1
    and    edi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     edi,eax
    shr    al,1
    add    edi,edi
    and    edi,0xffffffaa
    or     eax,edi
    movzx  eax,al
    movzx  eax,BYTE [rcx+rax*1]
   
    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret

otodik:
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
    
    mov rdi, lookup_otodik
    
    movzx  eax,al

   

    sub    eax,0x17
    mov    edx,eax
    shr    dl,1
    and    edx,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     edx,eax
    shr    al,1
    add    edx,edx
    and    edx,0xffffffaa
    or     eax,edx
    add    eax,0x35
    movzx  eax,al
    movzx  eax,BYTE [rdi+rax*1]
    xor    eax,0x7a
    rol    al,0x3
    sub    eax,0x44
    mov    edx,eax
    shr    dl,1
    and    edx,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     edx,eax
    not    edx
    add    edx,0x26
    xor    edx,0x79
    movzx  edx,dl
    imul   rax,rdx,0x802
    and    eax,0x22110
    imul   rdx,rdx,0x8020
    and    edx,0x88440
    or     rax,rdx
    imul   rax,rax,0x10101
    shr    rax,0x10
    add    eax,0x58
    xor    eax,0x34
    movzx  eax,al
    imul   rdx,rax,0x802
    and    edx,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rax,rdx
    imul   rax,rax,0x10101
    shr    rax,0x10

    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret

hatodik:
    push rbx
    push rcx
    push rdx
    push rsi
    push rdi

    mov rax, rdi
        
    movzx  eax,al

    mov esi, eax
    shr    sil,1
    and    esi,0x55
    add    eax,eax
    and    eax,0xffffffaa
    or     esi,eax
    movzx  esi,sil
    imul   rax,rsi,0x802
    and    eax,0x22110
    imul   rsi,rsi,0x8020
    and    esi,0x88440
    or     rax,rsi
    imul   rax,rax,0x10101
    shr    rax,0x10
    add    eax,0x5f
    ror    al,0x2
    movzx  eax,al
    imul   rsi,rax,0x802
    and    esi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rsi,rax
    imul   rsi,rsi,0x10101
    shr    rsi,0x10
    movzx  esi,sil
    imul   rax,rsi,0x802
    and    eax,0x22110
    imul   rsi,rsi,0x8020
    and    esi,0x88440
    or     rax,rsi
    imul   rax,rax,0x10101
    shr    rax,0x10
    ror    al,0x3
    movzx  eax,al
    imul   rsi,rax,0x802
    and    esi,0x22110
    imul   rax,rax,0x8020
    and    eax,0x88440
    or     rsi,rax
    imul   rsi,rsi,0x10101
    shr    rsi,0x10
    ror    sil,1
    movzx  esi,sil
    imul   rax,rsi,0x802
    and    eax,0x22110
    imul   rsi,rsi,0x8020
    and    esi,0x88440
    or     rax,rsi
    imul   rax,rax,0x10101
    shr    rax,0x10
    ror    al,0x2
    sub    eax,0xc
    not    eax
    sub    eax,0x5e
    not    eax
    ror    al,0x3


    movzx  rax,al


    pop rdi
    pop rsi
    pop rdx
    pop rcx
    pop rbx

    ret

section .data
lookup_elso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88, 0xcb, 0x56, 0x78, 0xbf
db 0x22, 0x23, 0x36, 0x6c, 0x48, 0x71, 0x54, 0x70
db 0x74, 0xba, 0x69, 0xe8, 0xe1, 0xe4, 0xe7, 0x15
db 0xbb, 0x66, 0x40, 0x10, 0x5b, 0xa5, 0xc8, 0x31
db 0xf7, 0x28, 0xf2, 0xf3, 0x33, 0xb9, 0xfd, 0x00
db 0xf6, 0xde, 0x57, 0x9e, 0x03, 0x79, 0xb3, 0x3a
db 0xc2, 0x6b, 0xdb, 0xd0, 0x8b, 0x63, 0x17, 0x6d
db 0x9f, 0xd2, 0xab, 0x49, 0xd5, 0xc0, 0xea, 0xda
db 0x3c, 0x95, 0xb7, 0x44, 0x7b, 0xdf, 0x90, 0x76
db 0x4b, 0xc3, 0x65, 0x80, 0x41, 0x6a, 0xc1, 0xd8

lookup_masodik
db 0x3e, 0xd3, 0x05, 0xa7, 0x09, 0x14, 0xbd, 0x1e
db 0xe0, 0x5d, 0xb0, 0x6e, 0x9b, 0xd6, 0x32, 0xee
db 0x51, 0x72, 0x68, 0x5a, 0x97, 0xa9, 0xa0, 0x67
db 0xc5, 0x42, 0x59, 0x55, 0x7f, 0x37, 0xc9, 0xac
db 0x8d, 0x0a, 0x5c, 0x46, 0x2c, 0xa3, 0xd9, 0xd4
db 0xd1, 0x07, 0x7d, 0x39, 0x24, 0xed, 0xfe, 0x8e
db 0x61, 0x99, 0xe3, 0x3d, 0x1b, 0x08, 0x92, 0x73
db 0xf4, 0xad, 0xf0, 0xfc, 0xca, 0xa2, 0xec, 0x38
db 0x18, 0x2a, 0xcd, 0x87, 0xaf, 0xd7, 0x4a, 0x1d
db 0xc6, 0x7a, 0x2e, 0x30, 0xbc, 0x4f, 0x58, 0xbe
db 0x4d, 0x13, 0xfb, 0x8a, 0xce, 0x3f, 0x01, 0x85
db 0xe9, 0x8c, 0x20, 0x1c, 0xaa, 0x35, 0x26, 0x2d
db 0xb4, 0x2b, 0x3b, 0x19, 0xb8, 0xb5, 0x45, 0xa8
db 0xff, 0x47, 0x12, 0xe5, 0xcc, 0x50, 0x27, 0x16
db 0x98, 0x0b, 0x83, 0xf5, 0x91, 0x29, 0xb2, 0xf9
db 0x1f, 0x0c, 0x86, 0x84, 0x75, 0x64, 0x1a, 0x0f
db 0xe6, 0x7c, 0x02, 0x04, 0x9a, 0x94, 0x34, 0x4e
db 0x53, 0xef, 0xdc, 0xb1, 0xf8, 0x81, 0x52, 0x06
db 0xfa, 0xc7, 0x0e, 0xb6, 0xcf, 0x77, 0x21, 0x11
db 0x6f, 0x25, 0x82, 0xa6, 0x4c, 0x60, 0x0d, 0x7e
db 0x93, 0xae, 0xc4, 0xeb, 0x5f, 0x9d, 0x62, 0x96
db 0x8f, 0x89, 0x2f, 0xdd, 0x43, 0x5e, 0xa1, 0xe2
db 0xf1, 0xa4, 0x9c, 0x88, 0xcb, 0x56, 0x78, 0xbf
db 0x22, 0x23, 0x36, 0x6c, 0x48, 0x71, 0x54, 0x70
db 0x74, 0xba, 0x69, 0xe8, 0xe1, 0xe4, 0xe7, 0x15
db 0xbb, 0x66, 0x40, 0x10, 0x5b, 0xa5, 0xc8, 0x31
db 0xf7, 0x28, 0xf2, 0xf3, 0x33, 0xb9, 0xfd, 0x00
db 0xf6, 0xde, 0x57, 0x9e, 0x03, 0x79, 0xb3, 0x3a
db 0xc2, 0x6b, 0xdb, 0xd0, 0x8b, 0x63, 0x17, 0x6d
db 0x9f, 0xd2, 0xab, 0x49, 0xd5, 0xc0, 0xea, 0xda
db 0x3c, 0x95, 0xb7, 0x44, 0x7b, 0xdf, 0x90, 0x76
db 0x4b, 0xc3, 0x65, 0x80, 0x41, 0x6a, 0xc1, 0xd8

lookup_negyedik
db 0x3e, 0xd3, 0x05, 0xa7, 0x09, 0x14, 0xbd, 0x1e
db 0xe0, 0x5d, 0xb0, 0x6e, 0x9b, 0xd6, 0x32, 0xee
db 0x51, 0x72, 0x68, 0x5a, 0x97, 0xa9, 0xa0, 0x67
db 0xc5, 0x42, 0x59, 0x55, 0x7f, 0x37, 0xc9, 0xac
db 0x8d, 0x0a, 0x5c, 0x46, 0x2c, 0xa3, 0xd9, 0xd4
db 0xd1, 0x07, 0x7d, 0x39, 0x24, 0xed, 0xfe, 0x8e
db 0x61, 0x99, 0xe3, 0x3d, 0x1b, 0x08, 0x92, 0x73
db 0xf4, 0xad, 0xf0, 0xfc, 0xca, 0xa2, 0xec, 0x38
db 0x18, 0x2a, 0xcd, 0x87, 0xaf, 0xd7, 0x4a, 0x1d
db 0xc6, 0x7a, 0x2e, 0x30, 0xbc, 0x4f, 0x58, 0xbe
db 0x4d, 0x13, 0xfb, 0x8a, 0xce, 0x3f, 0x01, 0x85
db 0xe9, 0x8c, 0x20, 0x1c, 0xaa, 0x35, 0x26, 0x2d
db 0xb4, 0x2b, 0x3b, 0x19, 0xb8, 0xb5, 0x45, 0xa8
db 0xff, 0x47, 0x12, 0xe5, 0xcc, 0x50, 0x27, 0x16
db 0x98, 0x0b, 0x83, 0xf5, 0x91, 0x29, 0xb2, 0xf9
db 0x1f, 0x0c, 0x86, 0x84, 0x75, 0x64, 0x1a, 0x0f
db 0xe6, 0x7c, 0x02, 0x04, 0x9a, 0x94, 0x34, 0x4e
db 0x53, 0xef, 0xdc, 0xb1, 0xf8, 0x81, 0x52, 0x06
db 0xfa, 0xc7, 0x0e, 0xb6, 0xcf, 0x77, 0x21, 0x11
db 0x6f, 0x25, 0x82, 0xa6, 0x4c, 0x60, 0x0d, 0x7e
db 0x93, 0xae, 0xc4, 0xeb, 0x5f, 0x9d, 0x62, 0x96
db 0x8f, 0x89, 0x2f, 0xdd, 0x43, 0x5e, 0xa1, 0xe2
db 0xf1, 0xa4, 0x9c, 0x88, 0xcb, 0x56, 0x78, 0xbf
db 0x22, 0x23, 0x36, 0x6c, 0x48, 0x71, 0x54, 0x70
db 0x74, 0xba, 0x69, 0xe8, 0xe1, 0xe4, 0xe7, 0x15
db 0xbb, 0x66, 0x40, 0x10, 0x5b, 0xa5, 0xc8, 0x31
db 0xf7, 0x28, 0xf2, 0xf3, 0x33, 0xb9, 0xfd, 0x00
db 0xf6, 0xde, 0x57, 0x9e, 0x03, 0x79, 0xb3, 0x3a
db 0xc2, 0x6b, 0xdb, 0xd0, 0x8b, 0x63, 0x17, 0x6d
db 0x9f, 0xd2, 0xab, 0x49, 0xd5, 0xc0, 0xea, 0xda
db 0x3c, 0x95, 0xb7, 0x44, 0x7b, 0xdf, 0x90, 0x76
db 0x4b, 0xc3, 0x65, 0x80, 0x41, 0x6a, 0xc1, 0xd8

lookup_otodik
db 0x3e, 0xd3, 0x05, 0xa7, 0x09, 0x14, 0xbd, 0x1e
db 0xe0, 0x5d, 0xb0, 0x6e, 0x9b, 0xd6, 0x32, 0xee
db 0x51, 0x72, 0x68, 0x5a, 0x97, 0xa9, 0xa0, 0x67
db 0xc5, 0x42, 0x59, 0x55, 0x7f, 0x37, 0xc9, 0xac
db 0x8d, 0x0a, 0x5c, 0x46, 0x2c, 0xa3, 0xd9, 0xd4
db 0xd1, 0x07, 0x7d, 0x39, 0x24, 0xed, 0xfe, 0x8e
db 0x61, 0x99, 0xe3, 0x3d, 0x1b, 0x08, 0x92, 0x73
db 0xf4, 0xad, 0xf0, 0xfc, 0xca, 0xa2, 0xec, 0x38
db 0x18, 0x2a, 0xcd, 0x87, 0xaf, 0xd7, 0x4a, 0x1d
db 0xc6, 0x7a, 0x2e, 0x30, 0xbc, 0x4f, 0x58, 0xbe
db 0x4d, 0x13, 0xfb, 0x8a, 0xce, 0x3f, 0x01, 0x85
db 0xe9, 0x8c, 0x20, 0x1c, 0xaa, 0x35, 0x26, 0x2d
db 0xb4, 0x2b, 0x3b, 0x19, 0xb8, 0xb5, 0x45, 0xa8
db 0xff, 0x47, 0x12, 0xe5, 0xcc, 0x50, 0x27, 0x16
db 0x98, 0x0b, 0x83, 0xf5, 0x91, 0x29, 0xb2, 0xf9
db 0x1f, 0x0c, 0x86, 0x84, 0x75, 0x64, 0x1a, 0x0f
db 0xe6, 0x7c, 0x02, 0x04, 0x9a, 0x94, 0x34, 0x4e
db 0x53, 0xef, 0xdc, 0xb1, 0xf8, 0x81, 0x52, 0x06
db 0xfa, 0xc7, 0x0e, 0xb6, 0xcf, 0x77, 0x21, 0x11
db 0x6f, 0x25, 0x82, 0xa6, 0x4c, 0x60, 0x0d, 0x7e
db 0x93, 0xae, 0xc4, 0xeb, 0x5f, 0x9d, 0x62, 0x96
db 0x8f, 0x89, 0x2f, 0xdd, 0x43, 0x5e, 0xa1, 0xe2
db 0xf1, 0xa4, 0x9c, 0x88, 0xcb, 0x56, 0x78, 0xbf
db 0x22, 0x23, 0x36, 0x6c, 0x48, 0x71, 0x54, 0x70
db 0x74, 0xba, 0x69, 0xe8, 0xe1, 0xe4, 0xe7, 0x15
db 0xbb, 0x66, 0x40, 0x10, 0x5b, 0xa5, 0xc8, 0x31
db 0xf7, 0x28, 0xf2, 0xf3, 0x33, 0xb9, 0xfd, 0x00
db 0xf6, 0xde, 0x57, 0x9e, 0x03, 0x79, 0xb3, 0x3a
db 0xc2, 0x6b, 0xdb, 0xd0, 0x8b, 0x63, 0x17, 0x6d
db 0x9f, 0xd2, 0xab, 0x49, 0xd5, 0xc0, 0xea, 0xda
db 0x3c, 0x95, 0xb7, 0x44, 0x7b, 0xdf, 0x90, 0x76
db 0x4b, 0xc3, 0x65, 0x80, 0x41, 0x6a, 0xc1, 0xd8