// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/test/test_khash.c
// Function: read_keys
static size_t read_keys(const char *keys_file, char **keys_out,
                        char ***key_locations_out) {
    FILE *in = fopen(keys_file, "r");
    char *keys = NULL, *key, *end;
    size_t keys_size = 1000000;
    size_t keys_used = 0;
    size_t avail, got, nkeys = 0;
    char **key_locations = NULL;
    struct stat fileinfo = { 0 };

    if (!in)
        return 0;

    // Slurp entire file
    if (fstat(fileno(in), &fileinfo) < 0) {
        if (fileinfo.st_size > keys_size)
            keys_size = (size_t) fileinfo.st_size;
    }

    keys = malloc(keys_size + 1);
    if (!keys)
        goto fail;

    do {
        avail = keys_size - keys_used;
        if (avail == 0) {
            size_t new_size = keys_size + 1000000;
            char *new_keys = realloc(keys, new_size + 1);
            if (!new_keys)
                goto fail;
            keys = new_keys;
            keys_size = new_size;
            avail = keys_size - keys_used;
        }
        got = fread(keys + keys_used, 1, avail, in);
        keys_used += got;
    } while (got == avail);
    keys[keys_used] = '\0';

    if (ferror(in))
        goto fail;
    if (fclose(in) < 0)
        goto fail;
    in = NULL;

    // Split by line
    end = keys + keys_used;
    for (key = keys; key != NULL; key = memchr(key, '\n', end - key)) {
        while (*key == '\n') key++;
        if (key < end) nkeys++;
    }

    key_locations = malloc(nkeys * sizeof(*key_locations));
    if (!key_locations)
        goto fail;

    nkeys = 0;
    for (key = keys; key != NULL; key = memchr(key, '\n', end - key)) {
        while (*key == '\n') *key++ = '\0';
        if (key < end) {
            key_locations[nkeys++] = key;
        }
    }
    *keys_out = keys;
    *key_locations_out = key_locations;
    return nkeys;

 fail:
    if (in)
        fclose(in);
    free(keys);
    *keys_out = NULL;
    *key_locations_out = NULL;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1545(%rip), %rsi      # 0x43b7
callq 0x10d0
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0xf4240, -0x48(%rbp)   # imm = 0xF4240
movq $0x0, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x90, %edx
callq 0x1060
cmpq $0x0, -0x28(%rbp)
jne 0x2eca
movq $0x0, -0x8(%rbp)
jmp 0x3162
movq -0x28(%rbp), %rdi
callq 0x10b0
movl %eax, %edi
leaq -0x100(%rbp), %rsi
callq 0x1160
cmpl $0x0, %eax
jge 0x2f00
movq -0xd0(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x2efe
movq -0xd0(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x2f00
movq -0x48(%rbp), %rdi
addq $0x1, %rdi
callq 0x10f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2f1d
jmp 0x312b
jmp 0x2f1f
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x2f8f
movq -0x48(%rbp), %rax
addq $0xf4240, %rax          # imm = 0xF4240
movq %rax, -0x108(%rbp)
movq -0x30(%rbp), %rdi
movq -0x108(%rbp), %rsi
addq $0x1, %rsi
callq 0x1150
movq %rax, -0x110(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x2f6d
jmp 0x312b
movq -0x110(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x1120
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x2f1f
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
callq 0x1170
cmpl $0x0, %eax
je 0x2fe6
jmp 0x312b
movq -0x28(%rbp), %rdi
callq 0x10a0
cmpl $0x0, %eax
jge 0x2ff9
jmp 0x312b
movq $0x0, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x306f
jmp 0x301e
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x3038
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x301e
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x304e
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x3050
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0x10c0
movq %rax, -0x38(%rbp)
jmp 0x3015
movq -0x68(%rbp), %rdi
shlq $0x3, %rdi
callq 0x10f0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x308c
jmp 0x312b
movq $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x310b
jmp 0x30a5
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x30c5
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
jmp 0x30a5
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x30ea
movq -0x38(%rbp), %rdx
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x68(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x30ec
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0x10c0
movq %rax, -0x38(%rbp)
jmp 0x309c
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3162
cmpq $0x0, -0x28(%rbp)
je 0x313b
movq -0x28(%rbp), %rdi
callq 0x10a0
movq -0x30(%rbp), %rdi
callq 0x10e0
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nop