// File: /workspace/github_c_makefile_star2_O2/cinemast[P]sudoku/sudoku.c
// Function: read_board
static
int
read_board (FILE * f, int is_tmplt)
{
    char * p, * q;
    int i, row, col, type = COMPACT;

    reset();
    len_tmplt = 0;

    /* Skip lines until a '%' is found */
    line[0] = ' ';
    while ('%' != line[0]) {
        if (0 == tgets(line, sizeof(line), f)) {
            return -1;
        }
    }
    /* Read optional title, and removing trailing whitespace */
    for (p = line + 1; *p && isspace(*p); ++p) {
       ;
    }
    if (*p) {
        for (q = title; '\0' != (*q++ = *p++);) {
           ;
        }
        --q;
        while (isspace(*--q)) {
           ;
        }
        *++q = '\0';
    } else {
        strcpy(title, "(untitled)");
    }
    /* Consume comment lines - no leading spaces allowed */
    line[0] = '#';
    while ('#' == line[0]) {
        if (0 == tgets(line, sizeof(line), f)) {
            return -1;
        }
    }
    /* Analyse first line to determine the 'type' - default is COMPACT */
    if (0 == is_tmplt) {
        for (p = line; *p && COMPACT == type; ++p) {
            if ('|' == *p) {
                type = VERBOSE;
            }
        }
    }
    /* Consume grid - allow leading spaces and comments at end */
    for (row = 0; row < 9; ++row) {
        /* Assume line already loaded into buffer; skip leading spaces */
        for (p = line; *p && isspace(*p); ++p) {
           ;
        }
        for (col = 0; *p && col < 9; ++col, ++p) {
            if (is_tmplt) {
                if ('*' == *p) {
                    tmplt[len_tmplt++] = INDEX(row, col);
                }
            } else {
                if (VERBOSE == type) {
                    while (*p && (isspace(*p) || '|' == *p)) {
                        ++p;
                    }
                }
                if (isdigit(*p)) {
                    if (0 != fill(INDEX(row, col), *p - '0')) {
                        return -1;
                    }
                    board[INDEX(row, col)] |= FIXED;
                }
                /* else assume blank square */
            }
        }
        /* Don't complain about any trailing characters - ignored silently */

        /* Load next line (if needed) */
        if (row < 8) {
            if (0 == tgets(line, sizeof(line), f)) {
                return -1;
            }
            if (VERBOSE == type
                && 2 == row % 3
                && 0 == tgets(line, sizeof(line), f)) {
                return -1; /* Skip separators */
            }
        }
    }

    /* Construct move history for a template */
    if (is_tmplt) {
        idx_history = 0;
        for (i = 0; i < 81; ++i) {
            if (0 != DIGIT(i)) {
                history[idx_history++] = i | (DIGIT(i) << 8);
            }
        }
    }
    /* Finally, markup all of these moves as 'fixed' */
    for (i = 0; i < idx_history; ++i) {
        history[i] |= FIXED;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %r12
leaq 0x9fd4(%rip), %rdi      # 0xf4a0
movl $0x144, %edx            # imm = 0x144
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
callq 0x2190
leaq 0xa13c(%rip), %rdi      # 0xf620
movl $0x3cc, %edx            # imm = 0x3CC
xorl %esi, %esi
callq 0x2190
andl $0x0, 0xa11d(%rip)      # 0xf614
andl $0x0, 0xa696(%rip)      # 0xfb94
andl $0x0, 0xa4f3(%rip)      # 0xf9f8
movb $0x20, 0xa4f4(%rip)     # 0xfa00
movb $0x20, %al
pushq $-0x1
popq %r15
cmpb $0x25, %al
je 0x552f
movq %r12, %rdi
callq 0x57ca
testq %rax, %rax
je 0x5740
movb 0xa4d3(%rip), %al       # 0xfa00
jmp 0x5512
leaq 0xa4cb(%rip), %rbx      # 0xfa01
movsbq (%rbx), %r14
testq %r14, %r14
je 0x5554
callq 0x2390
movq (%rax), %rcx
testb $0x20, 0x1(%rcx,%r14,2)
je 0x5571
incq %rbx
jmp 0x5536
movabsq $0x656c7469746e7528, %rax # imm = 0x656C7469746E7528
movq %rax, 0x9eab(%rip)      # 0xf410
movl $0x296465, 0x9ea8(%rip) # imm = 0x296465
jmp 0x55a2
xorl %edx, %edx
leaq 0x9e96(%rip), %rcx      # 0xf410
movb (%rbx,%rdx), %sil
movb %sil, (%rdx,%rcx)
incq %rdx
testb %sil, %sil
jne 0x557a
movq (%rax), %rax
addq %rdx, %rcx
movsbq -0x2(%rcx), %rdx
decq %rcx
testb $0x20, 0x1(%rax,%rdx,2)
jne 0x5590
movb $0x0, (%rcx)
movb $0x23, 0xa457(%rip)     # 0xfa00
movb $0x23, %al
cmpb $0x23, %al
jne 0x55c8
movq %r12, %rdi
callq 0x57ca
testq %rax, %rax
je 0x5740
movb 0xa43a(%rip), %al       # 0xfa00
jmp 0x55ab
xorl %r15d, %r15d
testl %ebp, %ebp
jne 0x55f6
leaq 0xa42b(%rip), %rcx      # 0xfa01
testl %r15d, %r15d
jne 0x55ef
testb %al, %al
je 0x55ef
xorl %r15d, %r15d
cmpb $0x7c, %al
sete %r15b
movb (%rcx), %al
incq %rcx
jmp 0x55d6
testl %r15d, %r15d
setne %r15b
xorl %r13d, %r13d
movl %r15d, %eax
xorb $0x1, %al
movb %al, 0xf(%rsp)
movq %r12, 0x18(%rsp)
cmpq $0x9, %r13
je 0x5752
leaq 0xa3e8(%rip), %r14      # 0xfa00
movsbq (%r14), %rbx
testq %rbx, %rbx
je 0x5635
callq 0x2390
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbx,2)
je 0x5635
incq %r14
jmp 0x5618
movq %r13, 0x20(%rsp)
leaq (%r13,%r13,8), %r13
xorl %r12d, %r12d
testb %bl, %bl
je 0x56f4
cmpq $0x8, %r12
ja 0x56f4
testl %ebp, %ebp
je 0x5681
cmpb $0x2a, %bl
jne 0x56e5
leal (%r12,%r13), %eax
movslq 0xa38c(%rip), %rcx      # 0xf9f8
leal 0x1(%rcx), %edx
movl %edx, 0xa383(%rip)      # 0xf9f8
leaq 0xa3d4(%rip), %rdx      # 0xfa50
movl %eax, (%rdx,%rcx,4)
jmp 0x56e5
testb %r15b, %r15b
je 0x56b1
testb %bl, %bl
je 0x56af
callq 0x2390
cmpb $0x7c, %bl
je 0x56a6
movq (%rax), %rax
movsbq %bl, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
je 0x56b1
movb 0x1(%r14), %bl
incq %r14
jmp 0x5686
xorl %ebx, %ebx
callq 0x2390
movq (%rax), %rax
movsbq %bl, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x56e5
movsbl %bl, %esi
leaq (%r12,%r13), %rbx
addl $-0x30, %esi
movl %ebx, %edi
callq 0x5894
testl %eax, %eax
jne 0x573c
leaq 0x9dc0(%rip), %rax      # 0xf4a0
orb $0x10, 0x2(%rax,%rbx,4)
incq %r12
movb 0x1(%r14), %bl
incq %r14
jmp 0x5642
movq 0x20(%rsp), %r13
cmpq $0x8, %r13
movq 0x18(%rsp), %r12
je 0x5734
movq %r12, %rdi
callq 0x57ca
testq %rax, %rax
je 0x573c
movl %r13d, %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
cmpl $0x2, %edx
setne %al
orb 0xf(%rsp), %al
jne 0x5734
movq %r12, %rdi
callq 0x57ca
testq %rax, %rax
je 0x573c
incq %r13
jmp 0x5607
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
je 0x579e
andl $0x0, 0x9eb7(%rip)      # 0xf614
xorl %ecx, %ecx
xorl %eax, %eax
leaq 0x9eb8(%rip), %rdi      # 0xf620
cmpq $0x51, %rcx
je 0x57ab
movq 0x10(%rsp), %rdx
movl (%rdx), %edx
shrl $0x10, %edx
testb $0xf, %dl
je 0x5793
andl $0xf, %edx
shll $0x8, %edx
addl %ecx, %edx
movslq %eax, %rsi
incl %eax
movl %eax, 0x9e84(%rip)      # 0xf614
movl %edx, (%rdi,%rsi,4)
incq %rcx
addq $0x4, 0x10(%rsp)
jmp 0x5768
movl 0x9e70(%rip), %eax      # 0xf614
leaq 0x9e75(%rip), %rdi      # 0xf620
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %eax
shlq $0x2, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x5740
orb $0x10, 0x2(%rcx,%rdi)
addq $0x4, %rcx
jmp 0x57ba