// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: cram_init_tables
static void cram_init_tables(cram_fd *fd) {
    int i;

    memset(fd->L1, 4, 256);
    fd->L1['A'] = 0; fd->L1['a'] = 0;
    fd->L1['C'] = 1; fd->L1['c'] = 1;
    fd->L1['G'] = 2; fd->L1['g'] = 2;
    fd->L1['T'] = 3; fd->L1['t'] = 3;

    memset(fd->L2, 5, 256);
    fd->L2['A'] = 0; fd->L2['a'] = 0;
    fd->L2['C'] = 1; fd->L2['c'] = 1;
    fd->L2['G'] = 2; fd->L2['g'] = 2;
    fd->L2['T'] = 3; fd->L2['t'] = 3;
    fd->L2['N'] = 4; fd->L2['n'] = 4;

    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	for (i = 0; i < 0x200; i++) {
	    int f = 0;

	    if (i & CRAM_FPAIRED)      f |= BAM_FPAIRED;
	    if (i & CRAM_FPROPER_PAIR) f |= BAM_FPROPER_PAIR;
	    if (i & CRAM_FUNMAP)       f |= BAM_FUNMAP;
	    if (i & CRAM_FREVERSE)     f |= BAM_FREVERSE;
	    if (i & CRAM_FREAD1)       f |= BAM_FREAD1;
	    if (i & CRAM_FREAD2)       f |= BAM_FREAD2;
	    if (i & CRAM_FSECONDARY)   f |= BAM_FSECONDARY;
	    if (i & CRAM_FQCFAIL)      f |= BAM_FQCFAIL;
	    if (i & CRAM_FDUP)         f |= BAM_FDUP;

	    fd->bam_flag_swap[i]  = f;
	}
    
	for (i = 0; i < 0x1000; i++) {
	    int g = 0;

	    if (i & BAM_FPAIRED)	   g |= CRAM_FPAIRED;
	    if (i & BAM_FPROPER_PAIR)  g |= CRAM_FPROPER_PAIR;
	    if (i & BAM_FUNMAP)        g |= CRAM_FUNMAP;
	    if (i & BAM_FREVERSE)      g |= CRAM_FREVERSE;
	    if (i & BAM_FREAD1)        g |= CRAM_FREAD1;
	    if (i & BAM_FREAD2)        g |= CRAM_FREAD2;
	    if (i & BAM_FSECONDARY)    g |= CRAM_FSECONDARY;
	    if (i & BAM_FQCFAIL)       g |= CRAM_FQCFAIL;
	    if (i & BAM_FDUP)          g |= CRAM_FDUP;

	    fd->cram_flag_swap[i] = g;
	}
    } else {
	/* NOP */
	for (i = 0; i < 0x1000; i++)
	    fd->bam_flag_swap[i] = i;
	for (i = 0; i < 0x1000; i++)
	    fd->cram_flag_swap[i] = i;
    }

    memset(fd->cram_sub_matrix, 4, 32*32);
    for (i = 0; i < 32; i++) {
	fd->cram_sub_matrix[i]['A'&0x1f]=0;
	fd->cram_sub_matrix[i]['C'&0x1f]=1;
	fd->cram_sub_matrix[i]['G'&0x1f]=2;
	fd->cram_sub_matrix[i]['T'&0x1f]=3;
	fd->cram_sub_matrix[i]['N'&0x1f]=4;
    }
    for (i = 0; i < 20; i+=4) {
	int j;
	for (j = 0; j < 20; j++) {
	    fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][j]=3;
	    fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][j]=3;
	    fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][j]=3;
	    fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][j]=3;
	}
	fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][CRAM_SUBST_MATRIX[i+0]&0x1f]=0;
	fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][CRAM_SUBST_MATRIX[i+1]&0x1f]=1;
	fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][CRAM_SUBST_MATRIX[i+2]&0x1f]=2;
	fd->cram_sub_matrix["ACGTN"[i>>2]&0x1f][CRAM_SUBST_MATRIX[i+3]&0x1f]=3;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x8234, %rdi           # imm = 0x8234
movl $0x4, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x42d0
movq -0x8(%rbp), %rax
movb $0x0, 0x8275(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x8295(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x8277(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x8297(%rax)
movq -0x8(%rbp), %rax
movb $0x2, 0x827b(%rax)
movq -0x8(%rbp), %rax
movb $0x2, 0x829b(%rax)
movq -0x8(%rbp), %rax
movb $0x3, 0x8288(%rax)
movq -0x8(%rbp), %rax
movb $0x3, 0x82a8(%rax)
movq -0x8(%rbp), %rdi
addq $0x8334, %rdi           # imm = 0x8334
movl $0x5, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x42d0
movq -0x8(%rbp), %rax
movb $0x0, 0x8375(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x8395(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x8377(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x8397(%rax)
movq -0x8(%rbp), %rax
movb $0x2, 0x837b(%rax)
movq -0x8(%rbp), %rax
movb $0x2, 0x839b(%rax)
movq -0x8(%rbp), %rax
movb $0x3, 0x8388(%rax)
movq -0x8(%rbp), %rax
movb $0x3, 0x83a8(%rax)
movq -0x8(%rbp), %rax
movb $0x4, 0x8382(%rax)
movq -0x8(%rbp), %rax
movb $0x4, 0x83a2(%rax)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x52191
movl $0x0, -0xc(%rbp)
cmpl $0x200, -0xc(%rbp)      # imm = 0x200
jge 0x52094
movl $0x0, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x51fca
movl -0x10(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x51fe0
movl -0x10(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x51ff4
movl -0x10(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x52008
movl -0x10(%rbp), %eax
orl $0x10, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x5201c
movl -0x10(%rbp), %eax
orl $0x40, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x52032
movl -0x10(%rbp), %eax
orl $0x80, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x52048
movl -0x10(%rbp), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x5205e
movl -0x10(%rbp), %eax
orl $0x200, %eax            # imm = 0x200
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x52074
movl -0x10(%rbp), %eax
orl $0x400, %eax            # imm = 0x400
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x234(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x51fa0
movl $0x0, -0xc(%rbp)
cmpl $0x1000, -0xc(%rbp)     # imm = 0x1000
jge 0x5218f
movl $0x0, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x520c5
movl -0x14(%rbp), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x520db
movl -0x14(%rbp), %eax
orl $0x80, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x520ef
movl -0x14(%rbp), %eax
orl $0x40, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x52103
movl -0x14(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x52117
movl -0x14(%rbp), %eax
orl $0x10, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x5212d
movl -0x14(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x52143
movl -0x14(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x52159
movl -0x14(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x5216f
movl -0x14(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x4234(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5209b
jmp 0x521ed
movl $0x0, -0xc(%rbp)
cmpl $0x1000, -0xc(%rbp)     # imm = 0x1000
jge 0x521be
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x234(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x52198
movl $0x0, -0xc(%rbp)
cmpl $0x1000, -0xc(%rbp)     # imm = 0x1000
jge 0x521eb
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x4234(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x521c5
jmp 0x521ed
movq -0x8(%rbp), %rdi
addq $0x8434, %rdi           # imm = 0x8434
movl $0x4, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x42d0
movl $0x0, -0xc(%rbp)
cmpl $0x20, -0xc(%rbp)
jge 0x522a3
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x0, 0x1(%rax)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x1, 0x3(%rax)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x2, 0x7(%rax)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x3, 0x14(%rax)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb $0x4, 0xe(%rax)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5220e
movl $0x0, -0xc(%rbp)
cmpl $0x14, -0xc(%rbp)
jge 0x524d1
movl $0x0, -0x18(%rbp)
cmpl $0x14, -0x18(%rbp)
jge 0x5239f
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b1d2(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movb $0x3, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b19f(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movb $0x3, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b16c(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movb $0x3, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b139(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movb $0x3, (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x522bb
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b0f8(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rdx
leaq 0x297d7(%rip), %rcx     # 0x7bbb1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b0af(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x2978e(%rip), %rcx     # 0x7bbb1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b066(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x29745(%rip), %rcx     # 0x7bbb1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
movb $0x2, (%rax,%rcx)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movl -0xc(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x2b01d(%rip), %rcx     # 0x7d4b1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rdx
leaq 0x296fc(%rip), %rcx     # 0x7bbb1
movsbl (%rcx,%rdx), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
movb $0x3, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x4, %eax
movl %eax, -0xc(%rbp)
jmp 0x522aa
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)