// File: karel-brinda[P]ococo/ext/htslib/cram/cram_encode.c
// Function: cram_add_substitution
static int cram_add_substitution(cram_fd *fd, cram_container *c,
				 cram_slice *s, cram_record *r,
				 int pos, char base, char qual, char ref) {
    cram_feature f;

    // seq=ACGTN vs ref=ACGT or seq=ACGT vs ref=ACGTN
    if (fd->L2[(uc)base]<4 || (fd->L2[(uc)base]<5 && fd->L2[(uc)ref]<4)) {
	f.X.pos = pos+1;
	f.X.code = 'X';
	f.X.base = fd->cram_sub_matrix[ref&0x1f][base&0x1f];
	cram_stats_add(c->stats[DS_BS], f.X.base);
    } else {
	f.B.pos = pos+1;
	f.B.code = 'B';
	f.B.base = base;
	f.B.qual = qual;
	cram_stats_add(c->stats[DS_BA], f.B.base);
	cram_stats_add(c->stats[DS_QS], f.B.qual);
	BLOCK_APPEND_CHAR(s->qual_blk, qual);
    }
    return cram_add_feature(c, s, r, &f);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %r9b, %al
movb 0x18(%rbp), %r9b
movb 0x10(%rbp), %r9b
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movb %al, -0x25(%rbp)
movq -0x8(%rbp), %rax
movzbl -0x25(%rbp), %ecx
movzbl 0x8334(%rax,%rcx), %eax
cmpl $0x4, %eax
jl 0x3f379
movq -0x8(%rbp), %rax
movzbl -0x25(%rbp), %ecx
movzbl 0x8334(%rax,%rcx), %eax
cmpl $0x5, %eax
jge 0x3f3cd
movq -0x8(%rbp), %rax
movzbl 0x18(%rbp), %ecx
movzbl 0x8334(%rax,%rcx), %eax
cmpl $0x4, %eax
jge 0x3f3cd
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x58, -0x34(%rbp)
movq -0x8(%rbp), %rax
addq $0x8434, %rax           # imm = 0x8434
movsbl 0x18(%rbp), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsbl -0x25(%rbp), %ecx
andl $0x1f, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x1b8(%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x54c30
jmp 0x3f52f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x42, -0x34(%rbp)
movsbl -0x25(%rbp), %eax
movl %eax, -0x30(%rbp)
movsbl 0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x1b0(%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x54c30
movq -0x10(%rbp), %rax
movq 0x120(%rax), %rdi
movl -0x2c(%rbp), %esi
callq 0x54c30
jmp 0x3f413
jmp 0x3f415
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x70(%rcx), %rcx
movq 0x30(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x3f502
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x3f48b
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x28(%rax), %xmm0
movaps 0x3b683(%rip), %xmm1    # 0x7aae0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x3b687(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x3c658(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x3f49a
movsd 0x3c63d(%rip), %xmm0    # 0x7bad0
movsd %xmm0, -0x40(%rbp)
jmp 0x3f49a
movsd -0x40(%rbp), %xmm0
movsd 0x3b619(%rip), %xmm2    # 0x7aac0
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x28(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq %rcx, 0x20(%rax)
jmp 0x3f415
jmp 0x3f504
movb 0x10(%rbp), %dl
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x70(%rcx), %rsi
movq 0x30(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x30(%rsi)
movb %dl, (%rax,%rcx)
jmp 0x3f52f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x41090
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)