// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movq %rdi, %r15
leaq 0x9303(%rip), %rdi      # 0xf4a0
xorl %ebx, %ebx
movl $0x144, %edx            # imm = 0x144
xorl %esi, %esi
callq 0x2190
leaq 0x946e(%rip), %rdi      # 0xf620
movl $0x3cc, %edx            # imm = 0x3CC
xorl %esi, %esi
callq 0x2190
movl %ebx, 0x9450(%rip)      # 0xf614
movl %ebx, 0x99ca(%rip)      # 0xfb94
movl %ebx, 0x9828(%rip)      # 0xf9f8
movb $0x20, 0x9829(%rip)     # 0xfa00
cmpb $0x25, 0x9822(%rip)     # 0xfa00
je 0x61f2
movq %r15, %rdi
callq 0x64eb
testq %rax, %rax
jne 0x61d7
jmp 0x62a6
movsbq 0x9807(%rip), %r14      # 0xfa01
testq %r14, %r14
sete %bl
je 0x623d
callq 0x2390
movq (%rax), %rcx
testb $0x20, 0x1(%rcx,%r14,2)
jne 0x621b
leaq 0x97e8(%rip), %rax      # 0xfa01
jmp 0x6239
leaq 0x97df(%rip), %rax      # 0xfa01
movsbq 0x1(%rax), %rdx
testq %rdx, %rdx
sete %bl
je 0x623d
incq %rax
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0x6222
testb %bl, %bl
je 0x625a
movabsq $0x656c7469746e7528, %rax # imm = 0x656C7469746E7528
movq %rax, 0x91c2(%rip)      # 0xf410
movl $0x296465, 0x91bf(%rip) # imm = 0x296465
jmp 0x6289
leaq 0x91af(%rip), %rbx      # 0xf410
movb (%rax), %cl
incq %rax
movb %cl, (%rbx)
incq %rbx
testb %cl, %cl
jne 0x6261
callq 0x2390
movq (%rax), %rax
movsbq -0x2(%rbx), %rcx
decq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x6277
movb $0x0, (%rbx)
movb $0x23, 0x9770(%rip)     # 0xfa00
cmpb $0x23, 0x9769(%rip)     # 0xfa00
jne 0x62be
movq %r15, %rdi
callq 0x64eb
testq %rax, %rax
jne 0x6290
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
sete %cl
movb 0x9737(%rip), %al       # 0xfa00
testb %al, %al
setne %dl
andb %cl, %dl
movl $0x0, 0xc(%rsp)
cmpb $0x1, %dl
jne 0x6300
leaq 0x971d(%rip), %rcx      # 0xfa01
movl %eax, %edx
movb (%rcx), %al
testb %al, %al
je 0x62f4
incq %rcx
cmpb $0x7c, %dl
jne 0x62e4
xorl %eax, %eax
cmpb $0x7c, %dl
sete %al
movl %eax, 0xc(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x10(%rsp)
movb 0x96f3(%rip), %bl       # 0xfa00
leaq 0x96ec(%rip), %r14      # 0xfa00
testb %bl, %bl
je 0x633d
callq 0x2390
movq (%rax), %rax
leaq 0x96d9(%rip), %r14      # 0xfa00
movsbq %bl, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x633d
movb 0x1(%r14), %bl
incq %r14
testb %bl, %bl
jne 0x6327
movb (%r14), %al
testb %al, %al
je 0x640b
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,8), %r13
xorl %ebx, %ebx
testl %ebp, %ebp
je 0x637f
cmpb $0x2a, %al
jne 0x63ef
leal (%rbx,%r13), %eax
movslq 0x968e(%rip), %rcx      # 0xf9f8
leal 0x1(%rcx), %edx
movl %edx, 0x9685(%rip)      # 0xf9f8
leaq 0x96d6(%rip), %rdx      # 0xfa50
movl %eax, (%rdx,%rcx,4)
jmp 0x63ef
cmpl $0x0, 0xc(%rsp)
je 0x63b8
movb (%r14), %r12b
testb %r12b, %r12b
je 0x63b8
callq 0x2390
movq (%rax), %rax
cmpb $0x7c, %r12b
je 0x63ac
movsbq %r12b, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
je 0x63b8
movb 0x1(%r14), %r12b
incq %r14
testb %r12b, %r12b
jne 0x6396
callq 0x2390
movq (%rax), %rax
movsbq (%r14), %rsi
testb $0x8, 0x1(%rax,%rsi,2)
je 0x63ef
leaq (%rbx,%r13), %r12
addl $-0x30, %esi
movl %r12d, %edi
callq 0x65cb
testl %eax, %eax
jne 0x62a6
leaq 0x90b7(%rip), %rax      # 0xf4a0
orb $0x10, 0x2(%rax,%r12,4)
movb 0x1(%r14), %al
testb %al, %al
je 0x640b
leaq 0x1(%rbx), %rcx
incq %r14
cmpq $0x8, %rbx
movq %rcx, %rbx
jb 0x6353
movq 0x10(%rsp), %rbx
cmpq $0x8, %rbx
je 0x6460
movq %r15, %rdi
callq 0x64eb
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x62ac
cmpl $0x0, 0xc(%rsp)
je 0x6460
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 0x6460
movq %r15, %rdi
callq 0x64eb
testq %rax, %rax
je 0x62ac
incq %rbx
cmpq $0x9, %rbx
jne 0x6302
testl %ebp, %ebp
leaq 0x91aa(%rip), %rdi      # 0xf620
leaq 0x9023(%rip), %r8       # 0xf4a0
je 0x64bb
movl $0x0, 0x918b(%rip)      # 0xf614
xorl %eax, %eax
xorl %ecx, %ecx
movl (%r8), %edx
shrl $0x10, %edx
testb $0xf, %dl
je 0x64ae
andl $0xf, %edx
shll $0x8, %edx
addl %eax, %edx
movslq %ecx, %rsi
incl %ecx
movl %ecx, 0x9169(%rip)      # 0xf614
movl %edx, (%rdi,%rsi,4)
incq %rax
addq $0x4, %r8
cmpq $0x51, %rax
jne 0x648d
movslq 0x9152(%rip), %rax      # 0xf614
testq %rax, %rax
jle 0x64e3
shlq $0x2, %rax
xorl %r12d, %r12d
xorl %ecx, %ecx
orb $0x10, 0x2(%rcx,%rdi)
addq $0x4, %rcx
cmpq %rcx, %rax
jne 0x64d0
jmp 0x62ac
xorl %r12d, %r12d
jmp 0x62ac