// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_maqcns.c
// Function: glf2cns
uint32_t glf2cns(const glf1_t *g, int q_r)
{
	int i, j, k, tmp[16], min = 10000, min2 = 10000, min3 = 10000, min_g = -1, min_g2 = -1;
	uint32_t x = 0;
	for (i = k = 0; i < 4; ++i)
		for (j = i; j < 4; ++j) {
			tmp[j<<2|i] = -1;
			tmp[i<<2|j] = g->lk[k++] + (i == j? 0 : q_r);
		}
	for (i = 0; i < 16; ++i) {
		if (tmp[i] < 0) continue;
		if (tmp[i] < min) {
			min3 = min2; min2 = min; min = tmp[i]; min_g2 = min_g; min_g = i;
		} else if (tmp[i] < min2) {
			min3 = min2; min2 = tmp[i]; min_g2 = i;
		} else if (tmp[i] < min3) min3 = tmp[i];
	}
	x = min_g >= 0? (1U<<(min_g>>2&3) | 1U<<(min_g&3)) << 28 : 0xf << 28;
	x |= min_g2 >= 0? (1U<<(min_g2>>2&3) | 1U<<(min_g2&3)) << 24 : 0xf << 24;
	x |= (uint32_t)g->max_mapQ << 16;
	x |= min2 < 10000? (min2 - min < 256? min2 - min : 255) << 8 : 0xff << 8;
	x |= min2 < 10000 && min3 < 10000? (min3 - min2 < 256? min3 - min2 : 255) : 0xff;
	return x;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
leaq 0x2(%rdi), %rax
leaq -0x40(%rsp), %rcx
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
movslq %r9d, %r9
leaq (%rax,%r9), %r11
movq %rcx, %rbx
xorl %r10d, %r10d
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movzbl (%r11,%r10), %ebp
testq %r10, %r10
movl %esi, %r14d
cmovel %edx, %r14d
addl %ebp, %r14d
movl %r14d, (%rcx,%r10,4)
addq $0x10, %rbx
leaq (%r8,%r10), %r14
incq %r14
incq %r10
cmpq $0x4, %r14
jne 0x7d32
incq %r8
addq $0x14, %rcx
addq %r10, %r9
cmpq $0x4, %r8
jne 0x7d25
movl $0x2710, %edx           # imm = 0x2710
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl $0x2710, %esi           # imm = 0x2710
movl $0x2710, %r8d           # imm = 0x2710
movl %r8d, %ebx
movl %esi, %r11d
movl %r10d, %r9d
movl -0x40(%rsp,%rcx,4), %esi
testl %esi, %esi
js 0x7dcb
cmpl %ebx, %esi
jge 0x7db4
movl %esi, %r8d
movl %ebx, %esi
movl %r11d, %edx
movl %ecx, %r10d
movl %r9d, %eax
jmp 0x7dd4
cmpl %r11d, %esi
jge 0x7dc6
movl %ebx, %r8d
movl %r11d, %edx
movl %r9d, %r10d
movl %ecx, %eax
jmp 0x7dd4
cmpl %edx, %esi
cmovll %esi, %edx
movl %ebx, %r8d
movl %r11d, %esi
movl %r9d, %r10d
incq %rcx
cmpq $0x10, %rcx
jne 0x7d8f
testl %r10d, %r10d
js 0x7e02
movl %r10d, %ecx
shrb $0x2, %cl
andb $0x3, %cl
movl $0x1, %r9d
shll %cl, %r9d
andb $0x3, %r10b
btsl %r10d, %r9d
shll $0x1c, %r9d
jmp 0x7e08
movl $0xf0000000, %r9d       # imm = 0xF0000000
testl %eax, %eax
js 0x7e29
movl %eax, %ecx
shrb $0x2, %cl
andb $0x3, %cl
movl $0x1, %r10d
shll %cl, %r10d
andb $0x3, %al
btsl %eax, %r10d
shll $0x18, %r10d
jmp 0x7e2f
movl $0xf000000, %r10d       # imm = 0xF000000
movzbl 0x1(%rdi), %eax
movl $0xff00, %ecx           # imm = 0xFF00
cmpl $0x270f, %esi           # imm = 0x270F
jg 0x7e52
movl %esi, %ecx
subl %r8d, %ecx
movl $0xff, %edi
cmpl %edi, %ecx
cmovgel %edi, %ecx
shll $0x8, %ecx
movl %edx, %edi
subl %esi, %edi
movl $0xff, %r8d
cmpl %r8d, %edi
cmovgel %r8d, %edi
movl $0x2710, %r11d          # imm = 0x2710
cmpl %r11d, %edx
cmovgel %r8d, %edi
cmpl %r11d, %esi
cmovgel %r8d, %edi
orl %r10d, %r9d
shll $0x10, %eax
orl %r9d, %eax
orl %ecx, %eax
orl %edi, %eax
popq %rbx
popq %r14
popq %rbp
retq