// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: ltf8_decode
int ltf8_decode(cram_fd *fd, int64_t *val_p) {
    int c = hgetc(fd->fp);
    int64_t val = (unsigned char)c;
    if (c == -1)
	return -1;

    if (val < 0x80) {
	*val_p =   val;
	return 1;

    } else if (val < 0xc0) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & (((1LL<<(6+8)))-1);
	return 2;

    } else if (val < 0xe0) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(5+2*8))-1);
	return 3;

    } else if (val < 0xf0) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(4+3*8))-1);
	return 4;

    } else if (val < 0xf8) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(3+4*8))-1);
	return 5;

    } else if (val < 0xfc) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(2+5*8))-1);
	return 6;

    } else if (val < 0xfe) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(1+6*8))-1);
	return 7;

    } else if (val < 0xff) {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val & ((1LL<<(7*8))-1);
	return 8;

    } else {
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val;
    }

    return 9;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31147
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3114c
callq 0x4805a
cmpl $-0x1, %eax
je 0x3118e
movzbl %al, %r15d
movl $0x1, %eax
cmpl $0x80, %r15d
jb 0x313de
cmpl $0xbf, %r15d
ja 0x31198
shll $0x8, %r15d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x311bb
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x311c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x313e1
cmpl $0xdf, %r15d
ja 0x311d7
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x311fe
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31203
callq 0x4805a
movzbl %al, %eax
andl $0x3f00, %r15d          # imm = 0x3F00
orq %rax, %r15
movl $0x2, %eax
jmp 0x313de
cmpl $0xef, %r15d
ja 0x31228
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31271
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31276
callq 0x4805a
shll $0x10, %r15d
shll $0x8, %eax
movzwl %ax, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31252
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31257
cmpl $0xf7, %r15d
ja 0x3129e
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31311
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31316
callq 0x4805a
movzbl %al, %eax
andl $0x1f0000, %r15d        # imm = 0x1F0000
orq %r12, %r15
orq %rax, %r15
movl $0x3, %eax
jmp 0x313de
callq 0x4805a
shll $0x10, %r15d
shll $0x8, %eax
movzwl %ax, %r12d
orl %r15d, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x312cc
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x312d1
cmpl $0xfb, %r15d
ja 0x3133e
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x313ea
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x313ef
callq 0x4805a
movzbl %al, %eax
orl %eax, %r12d
shll $0x8, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x312f5
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x312fa
callq 0x4805a
movzbl %al, %eax
andl $0xfffff00, %r12d       # imm = 0xFFFFF00
orq %rax, %r12
movl $0x4, %eax
jmp 0x313db
callq 0x4805a
shll $0x10, %r15d
shll $0x8, %eax
movzwl %ax, %r12d
orl %r15d, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3136c
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31371
cmpl $0xfd, %r15d
ja 0x31417
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x314e5
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x314ea
callq 0x4805a
movzbl %al, %eax
orq %rax, %r12
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31391
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31396
callq 0x4805a
shlq $0x10, %r12
shll $0x8, %eax
movzwl %ax, %r15d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x313bb
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x313c0
callq 0x4805a
movzbl %al, %eax
movabsq $0x7ffff0000, %rcx      # imm = 0x7FFFF0000
andq %rcx, %r12
orq %r15, %r12
orq %rax, %r12
movl $0x5, %eax
movq %r12, %r15
movq %r15, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x4805a
shll $0x10, %r15d
shll $0x8, %eax
movzwl %ax, %r12d
orl %r15d, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31448
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3144d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
cmpl $0xff, %r15d
jne 0x31512
cmpq %rax, %rcx
jbe 0x315f1
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %ebp
jmp 0x315f8
callq 0x4805a
movzbl %al, %eax
orq %rax, %r12
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3146d
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31472
callq 0x4805a
shlq $0x10, %r12
shll $0x8, %eax
movzwl %ax, %r15d
orq %r12, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3149a
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3149f
callq 0x4805a
movzbl %al, %eax
orq %rax, %r15
shlq $0x8, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x314c3
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x314c8
callq 0x4805a
movzbl %al, %eax
movabsq $0x3ffffffff00, %rcx    # imm = 0x3FFFFFFFF00
andq %rcx, %r15
orq %rax, %r15
movl $0x6, %eax
jmp 0x313de
callq 0x4805a
shll $0x10, %r15d
shll $0x8, %eax
movzwl %ax, %r12d
orl %r15d, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3152b
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31530
cmpq %rax, %rcx
jbe 0x31612
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31617
callq 0x4805a
movzbl %al, %eax
orq %rax, %r12
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31550
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31555
callq 0x4805a
shlq $0x10, %r12
shll $0x8, %eax
movzwl %ax, %r15d
orq %r12, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3157d
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31582
callq 0x4805a
movzbl %al, %eax
orq %rax, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x315a2
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x315a7
callq 0x4805a
shlq $0x10, %r15
shll $0x8, %eax
movzwl %ax, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x315cc
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x315d1
callq 0x4805a
movzbl %al, %eax
movabsq $0x1ffffffff0000, %rcx  # imm = 0x1FFFFFFFF0000
andq %rcx, %r15
orq %r12, %r15
orq %rax, %r15
movl $0x7, %eax
jmp 0x313de
callq 0x4805a
movl %eax, %ebp
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31638
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3163d
callq 0x4805a
shll $0x8, %eax
movzwl %ax, %r15d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31664
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31669
callq 0x4805a
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r12d
orl %ebp, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3168c
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31691
callq 0x4805a
movzbl %al, %ebp
orl %r15d, %ebp
shll $0x8, %ebp
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x316b2
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x316b7
callq 0x4805a
movzbl %al, %r15d
orl %r12d, %r15d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x316d8
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x316dd
callq 0x4805a
movzbl %al, %r12d
orl %ebp, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31705
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3170a
callq 0x4805a
shlq $0x10, %r15
shll $0x8, %eax
movzwl %ax, %r12d
orq %r15, %r12
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31732
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31737
callq 0x4805a
shlq $0x10, %r12
shll $0x8, %eax
movzwl %ax, %r15d
orq %r12, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x31757
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x3175c
callq 0x4805a
movzbl %al, %eax
orq %rax, %r12
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3177c
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31781
callq 0x4805a
movzbl %al, %eax
orq %rax, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x317a9
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x317ae
callq 0x4805a
shlq $0x10, %r12
shll $0x8, %eax
movzwl %ax, %r15d
orq %r12, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x317d3
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x317d8
callq 0x4805a
shlq $0x10, %r15
shll $0x8, %eax
movzwl %ax, %r12d
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x317fc
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31801
callq 0x4805a
movzbl %al, %eax
orq %rax, %r15
shlq $0x8, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x3181b
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x31820
callq 0x4805a
movzbl %al, %eax
andq $-0x10000, %r15         # imm = 0xFFFF0000
orq %r12, %r15
orq %rax, %r15
movl $0x8, %eax
jmp 0x313de
callq 0x4805a
movzbl %al, %eax
orq %rax, %r15
movl $0x9, %eax
jmp 0x313de