// File: /workspace/github_c_makefile_star2_O0/excess-c64[P]lib1541img/src/lib/1541img/lynx.c
// Function: findHeader
static int findHeader(size_t *sigpos, uint8_t *dirblocks, size_t *dirpos,
	const uint8_t *content, size_t size)
{
    size_t pos = 0;
    if (size < 255) return -1;
    size_t base = content[0] | (content[1] << 8);
    size_t next = content[2] | (content[3] << 8);
    if (next <= base) goto lynxhdr;
    pos = next - base + 2;
    if (pos > size - 5)
    {
	pos = 0;
	goto lynxhdr;
    }
    if (content[pos-1])
    {
	pos = 0;
	goto lynxhdr;
    }
    while (content[pos] || content[pos+1])
    {
	size_t nextline = content[pos] | (content[pos+1] << 8);
	if (nextline <= next) return -1;
	next = nextline;
	pos = next - base + 2;
	if (pos > size - 5) return -1;
	if (content[pos-1]) return -1;
    }
    pos += 2;
    if (content[pos++] != 0x0d) return -1;
lynxhdr:
    if (findLynxHeader(&pos, dirblocks, dirpos, content, size) < 0) return -1;
    *sigpos = pos;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0xff, -0x30(%rbp)
jae 0xfa5a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
ja 0xfa9e
jmp 0xfbe7
movq -0x48(%rbp), %rax
subq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x5, %rcx
cmpq %rcx, %rax
jbe 0xfacc
movq $0x0, -0x38(%rbp)
jmp 0xfbe7
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
cmpb $0x0, (%rax,%rcx)
je 0xfaeb
movq $0x0, -0x38(%rbp)
jmp 0xfbe7
jmp 0xfaed
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x51(%rbp)
jne 0xfb19
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0xfb25
jmp 0xfbb4
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
ja 0xfb5f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
subq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x5, %rcx
cmpq %rcx, %rax
jbe 0xfb94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
cmpb $0x0, (%rax,%rcx)
je 0xfbaf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
jmp 0xfaed
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movzbl (%rax,%rcx), %eax
cmpl $0xd, %eax
je 0xfbe5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
jmp 0xfbe7
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0x38(%rbp), %rdi
callq 0x11270
cmpl $0x0, %eax
jge 0xfc0e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfc20
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)