// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, %r12
leaq 0x92da(%rip), %rdi      # 0xf4a0
xorl %ebx, %ebx
movl $0x144, %edx            # imm = 0x144
xorl %esi, %esi
callq 0x2190
leaq 0x9445(%rip), %rdi      # 0xf620
movl $0x3cc, %edx            # imm = 0x3CC
xorl %esi, %esi
callq 0x2190
movl %ebx, 0x9427(%rip)      # 0xf614
movl %ebx, 0x99a1(%rip)      # 0xfb94
movl %ebx, 0x97ff(%rip)      # 0xf9f8
movb $0x20, 0x9800(%rip)     # 0xfa00
movq %r12, %rdi
callq 0x64f6
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x64e4
cmpb $0x25, 0x97e2(%rip)     # 0xfa00
jne 0x6200
movb 0x97db(%rip), %bl       # 0xfa01
testb %bl, %bl
je 0x624d
callq 0x2390
movq (%rax), %rdx
leaq 0x97c9(%rip), %rcx      # 0xfa02
movsbq %bl, %rsi
testb $0x20, 0x1(%rdx,%rsi,2)
je 0x626a
movb (%rcx), %bl
incq %rcx
testb %bl, %bl
jne 0x6239
movabsq $0x656c7469746e7528, %rax # imm = 0x656C7469746E7528
movq %rax, 0x91b2(%rip)      # 0xf410
movl $0x296465, 0x91af(%rip) # imm = 0x296465
jmp 0x629c
xorl %esi, %esi
leaq 0x919d(%rip), %rdx      # 0xf410
movb -0x1(%rcx,%rsi), %dil
movb %dil, (%rsi,%rdx)
incq %rsi
testb %dil, %dil
jne 0x6273
movq (%rax), %rax
addq %rsi, %rdx
movsbq -0x2(%rdx), %rcx
decq %rdx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x628a
movb $0x0, (%rdx)
movb $0x23, 0x975d(%rip)     # 0xfa00
movq %r12, %rdi
callq 0x64f6
testq %rax, %rax
je 0x64e4
movb 0x9746(%rip), %al       # 0xfa00
cmpb $0x23, %al
je 0x62a3
cmpl $0x0, 0xc(%rsp)
setne %cl
testb %al, %al
sete %dl
movl $0x0, 0x8(%rsp)
orb %cl, %dl
jne 0x62fa
leaq 0x9723(%rip), %rcx      # 0xfa01
movl %eax, %edx
movb (%rcx), %al
testb %al, %al
je 0x62ee
incq %rcx
cmpb $0x7c, %dl
jne 0x62de
xorl %eax, %eax
cmpb $0x7c, %dl
sete %al
movl %eax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb 0x96f6(%rip), %r13b     # 0xfa00
testb %r13b, %r13b
je 0x6406
callq 0x2390
movq (%rax), %rax
leaq 0x96de(%rip), %rbx      # 0xfa00
movsbq %r13b, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x633e
movb 0x1(%rbx), %r13b
incq %rbx
testb %r13b, %r13b
jne 0x6322
jmp 0x6406
movq 0x10(%rsp), %rax
leaq (%rax,%rax,8), %r14
xorl %ebp, %ebp
cmpl $0x0, 0xc(%rsp)
je 0x637a
cmpb $0x2a, %r13b
jne 0x63e9
leal (%r14,%rbp), %eax
movslq 0x9693(%rip), %rcx      # 0xf9f8
leal 0x1(%rcx), %edx
movl %edx, 0x968a(%rip)      # 0xf9f8
leaq 0x96db(%rip), %rdx      # 0xfa50
movl %eax, (%rdx,%rcx,4)
jmp 0x63e9
cmpl $0x0, 0x8(%rsp)
je 0x63ae
callq 0x2390
movq (%rax), %rax
cmpb $0x7c, %r13b
je 0x639f
movsbq %r13b, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
je 0x63ae
movb 0x1(%rbx), %r13b
incq %rbx
testb %r13b, %r13b
jne 0x6389
xorl %r13d, %r13d
callq 0x2390
movq (%rax), %rax
movsbq %r13b, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x63e9
movsbl %r13b, %esi
leaq (%r14,%rbp), %r13
addl $-0x30, %esi
movl %r13d, %edi
callq 0x65c2
testl %eax, %eax
jne 0x64e4
leaq 0x90bd(%rip), %rax      # 0xf4a0
orb $0x10, 0x2(%rax,%r13,4)
movb 0x1(%rbx), %r13b
testb %r13b, %r13b
je 0x6406
leaq 0x1(%rbp), %rax
incq %rbx
cmpq $0x8, %rbp
movq %rax, %rbp
jb 0x6349
movq 0x10(%rsp), %rbx
cmpq $0x8, %rbx
je 0x6462
movq %r12, %rdi
callq 0x64f6
testq %rax, %rax
je 0x64e4
cmpl $0x0, 0x8(%rsp)
je 0x6455
movl %ebx, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rcx, %rax
shrq $0x21, %rax
leal (%rax,%rax,2), %eax
movl %ebx, %ecx
subl %eax, %ecx
cmpl $0x2, %ecx
jne 0x6455
movq %r12, %rdi
callq 0x64f6
testq %rax, %rax
je 0x64e4
incq %rbx
movq %rbx, 0x10(%rsp)
jmp 0x6303
cmpl $0x0, 0xc(%rsp)
je 0x64b5
movl $0x0, 0x91a1(%rip)      # 0xf614
xorl %ecx, %ecx
xorl %eax, %eax
leaq 0x91a2(%rip), %rdi      # 0xf620
leaq 0x901b(%rip), %r8       # 0xf4a0
movl (%r8), %edx
shrl $0x10, %edx
testb $0xf, %dl
je 0x64a6
andl $0xf, %edx
shll $0x8, %edx
addl %ecx, %edx
movslq %eax, %rsi
incl %eax
movl %eax, 0x9171(%rip)      # 0xf614
movl %edx, (%rdi,%rsi,4)
incq %rcx
addq $0x4, %r8
cmpq $0x51, %rcx
jne 0x6485
jmp 0x64c2
movl 0x9159(%rip), %eax      # 0xf614
leaq 0x915e(%rip), %rdi      # 0xf620
testl %eax, %eax
jle 0x64e1
movl %eax, %eax
shlq $0x2, %rax
xorl %r15d, %r15d
xorl %ecx, %ecx
orb $0x10, 0x2(%rcx,%rdi)
addq $0x4, %rcx
cmpq %rcx, %rax
jne 0x64d1
jmp 0x64e4
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq