// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]yahs/sdict.c
// Function: file_sdict_match
int file_sdict_match(char *f, sdict_t *dict)
{
    uint32_t i, m, n, s, *lens;
    uint64_t l;
    int64_t magic_number;
    char *names, *p;
    FILE *fp;

    fp = fopen(f, "r");
    if (fp == NULL)
        return 1;

    m = fread(&magic_number, sizeof(int64_t), 1, fp);
    if (m != 1) bin_fread_error();
    if (!is_valid_bin_header(magic_number))
        return 2;

    m = fread(&n, sizeof(uint32_t), 1, fp);
    if (m != 1) bin_fread_error();
    if (n != dict->n)
        return 3;
    
    lens = (uint32_t *) calloc(n, sizeof(uint32_t));
    m = fread(lens, sizeof(uint32_t), n, fp);
    if (m != n) bin_fread_error();
    for (i = 0; i < n; ++i) {
        if (dict->s[i].len != lens[i]) {
            free(lens);
            return 4;
        }
    }
    free(lens);
    
    m = fread(&l, sizeof(uint64_t), 1, fp);
    if (m != 1) bin_fread_error();
    names = (char *) calloc(l, 1);
    m = fread(names, 1, l, fp);
    if (m != l) bin_fread_error();
    for (p = names, i = 0; i < n; ++i) {
        s = strlen(dict->s[i].name);
        if (p - names >= l || strncmp(p, dict->s[i].name, s)) {
            free(names);
            return 5;
        }
        p += s + 1;
    }
    free(names);

    fclose(fp);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
leaq 0x2364(%rip), %rsi      # 0xab6c
callq 0x22c0
testq %rax, %rax
je 0x89b8
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20c0
cmpl $0x1, %eax
je 0x883c
xorl %eax, %eax
callq 0x2d21
movq 0x28(%rsp), %rdi
callq 0x2d0e
testl %eax, %eax
je 0x89bf
leaq 0x14(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x20c0
cmpl $0x1, %eax
je 0x8871
xorl %eax, %eax
callq 0x2d21
movl 0x14(%rsp), %r15d
movl $0x3, %eax
cmpl (%r14), %r15d
jne 0x89e4
movl $0x4, %esi
movq %r15, %rdi
callq 0x21d0
movq %rax, %r12
movl $0x4, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x20c0
cmpl %eax, %r15d
je 0x88b3
xorl %eax, %eax
callq 0x2d21
testq %r15, %r15
je 0x88da
movq 0x8(%r14), %rax
addq $0x10, %rax
xorl %ecx, %ecx
movl (%rax), %edx
cmpl (%r12,%rcx,4), %edx
jne 0x89c6
incq %rcx
addq $0x18, %rax
cmpq %rcx, %r15
jne 0x88c2
movq %r12, %rdi
callq 0x2050
leaq 0x30(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x20c0
cmpl $0x1, %eax
je 0x8905
xorl %eax, %eax
callq 0x2d21
movq 0x30(%rsp), %r12
movl $0x1, %esi
movq %r12, %rdi
callq 0x21d0
movl $0x1, %esi
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20c0
movl %eax, %eax
movq %r12, 0x20(%rsp)
cmpq %r12, %rax
je 0x8942
xorl %eax, %eax
callq 0x2d21
testl %r15d, %r15d
je 0x89a2
movq 0x8(%r14), %r13
shlq $0x3, %r15
leaq (%r15,%r15,2), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
movq (%r13,%r12), %rbp
movq %rbp, %rdi
callq 0x2110
movq %rax, %r15
movq %r14, %rax
subq 0x8(%rsp), %rax
cmpq 0x20(%rsp), %rax
jae 0x89d5
movl %r15d, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2090
testl %eax, %eax
jne 0x89d5
incl %r15d
addq %r15, %r14
addq $0x18, %r12
cmpq %r12, 0x18(%rsp)
jne 0x8960
movq 0x8(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2100
xorl %eax, %eax
jmp 0x89e4
movl $0x1, %eax
jmp 0x89e4
movl $0x2, %eax
jmp 0x89e4
movq %r12, %rdi
callq 0x2050
movl $0x4, %eax
jmp 0x89e4
movq 0x8(%rsp), %rdi
callq 0x2050
movl $0x5, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq